Created
February 23, 2021 21:32
-
-
Save hikari-no-yume/f2953c446e145edc7439c8cf3cafcfe8 to your computer and use it in GitHub Desktop.
What would C look like if it had already been compiled to LLVM IR and back again, but then you compiled it to LLVM IR and back again… again? (sequel to https://gist.github.com/hikari-no-yume/3cde016149d0309a80770c5eccd013ad, using https://github.com/JuliaComputing/llvm-cbe)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Provide Declarations */ | |
#include <stdarg.h> | |
#include <setjmp.h> | |
#include <limits.h> | |
#include <stdint.h> | |
#include <math.h> | |
#ifndef __cplusplus | |
typedef unsigned char bool; | |
#endif | |
#if defined(__GNUC__) | |
#define __ATTRIBUTELIST__(x) __attribute__(x) | |
#else | |
#define __ATTRIBUTELIST__(x) | |
#endif | |
#ifdef _MSC_VER /* Can only support "linkonce" vars with GCC */ | |
#define __attribute__(X) | |
#endif | |
/* Global Declarations */ | |
/* Types Declarations */ | |
/* Function definitions */ | |
/* Types Definitions */ | |
struct l_array_14_uint8_t { | |
uint8_t array[14]; | |
}; | |
/* External Global Variable Declarations */ | |
/* Function Declarations */ | |
uint32_t main(void) __ATTRIBUTELIST__((noinline, nothrow)); | |
uint32_t printf(uint8_t*, ...); | |
/* Global Variable Definitions and Initialization */ | |
static struct l_array_14_uint8_t _OC_str = { "hello, world\n" }; | |
/* LLVM Intrinsic Builtin Function Bodies */ | |
/* Function Bodies */ | |
uint32_t main(void) { | |
uint32_t llvm_cbe_tmp__1; | |
llvm_cbe_tmp__1 = printf(((&_OC_str.array[((int64_t)UINT64_C(0))]))); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ModuleID = 'hello-world.cbe.c' | |
source_filename = "hello-world.cbe.c" | |
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | |
target triple = "x86_64-pc-linux-gnu" | |
%struct.l_array_14_uint8_t = type { [14 x i8] } | |
@_OC_str = internal global %struct.l_array_14_uint8_t { [14 x i8] c"hello, world\0A\00" }, align 1 | |
; Function Attrs: noinline nounwind optnone uwtable | |
define dso_local i32 @main() #0 { | |
%1 = alloca i32, align 4 | |
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds (%struct.l_array_14_uint8_t, %struct.l_array_14_uint8_t* @_OC_str, i32 0, i32 0, i64 0)) | |
store i32 %2, i32* %1, align 4 | |
ret i32 0 | |
} | |
declare dso_local i32 @printf(i8*, ...) #1 | |
attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } | |
attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } | |
!llvm.module.flags = !{!0} | |
!llvm.ident = !{!1} | |
!0 = !{i32 1, !"wchar_size", i32 4} | |
!1 = !{!"clang version 10.0.0-4ubuntu1 "} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Provide Declarations */ | |
#include <stdarg.h> | |
#include <setjmp.h> | |
#include <limits.h> | |
#include <stdint.h> | |
#include <math.h> | |
#ifndef __cplusplus | |
typedef unsigned char bool; | |
#endif | |
#if defined(__GNUC__) | |
#define __ATTRIBUTELIST__(x) __attribute__(x) | |
#else | |
#define __ATTRIBUTELIST__(x) | |
#endif | |
#ifdef _MSC_VER /* Can only support "linkonce" vars with GCC */ | |
#define __attribute__(X) | |
#endif | |
/* Global Declarations */ | |
/* Types Declarations */ | |
struct l_struct_struct_OC_l_array_14_uint8_t; | |
/* Function definitions */ | |
/* Types Definitions */ | |
struct l_array_14_uint8_t { | |
uint8_t array[14]; | |
}; | |
struct l_struct_struct_OC_l_array_14_uint8_t { | |
struct l_array_14_uint8_t field0; | |
}; | |
/* External Global Variable Declarations */ | |
/* Function Declarations */ | |
uint32_t main(void) __ATTRIBUTELIST__((noinline, nothrow)); | |
uint32_t printf(uint8_t*, ...); | |
/* Global Variable Definitions and Initialization */ | |
static struct l_struct_struct_OC_l_array_14_uint8_t _OC_str = { { "hello, world\n" } }; | |
/* LLVM Intrinsic Builtin Function Bodies */ | |
/* Function Bodies */ | |
uint32_t main(void) { | |
uint32_t llvm_cbe_tmp__1; /* Address-exposed local */ | |
uint32_t llvm_cbe_tmp__2; | |
llvm_cbe_tmp__2 = printf(((&_OC_str.field0.array[((int64_t)UINT64_C(0))]))); | |
llvm_cbe_tmp__1 = llvm_cbe_tmp__2; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment