#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ create_prelude_h(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ stderr;
void run(const char *filepath) {
  int c;
  int n = 0;
  FILE *fin = fopen(filepath, "r");
  FILE *fout = fopen("src/prelude.bin", "w");
  if (fin == NULL) {
    fprintf(stderr, "Error opening file\n");
    exit(1);
  }
  while ((c = fgetc(fin)) != EOF) {
    fprintf(fout, "'\\x%X',", (unsigned)c);
    n++;
  }
  fclose(fin);
  fclose(fout);
  create_prelude_h(n);
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe74(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cb <run+0x6b>
mov    0x2e28(%rip),%rax
movslq (%rax),%rdi
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11d0 <run+0x70>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e05(%rip),%rcx
cmp    (%rcx),%eax
je     120e <run+0xae>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11d0 <run+0x70>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%edi
call   1030 <create_prelude_h@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe74(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
test   %rbx,%rbx
je     120f <run+0x9f>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2e37(%rip),%r12
xor    %ebp,%ebp
cmp    (%r12),%eax
je     11f0 <run+0x80>
lea    0xe68(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r12),%eax
jne    11d0 <run+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %ebp,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <create_prelude_h@plt>
mov    0x2dc2(%rip),%rax
movslq (%rax),%rcx
lea    0xdf4(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [16 x i8] c"src/prelude.bin\00"
@.str.2 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.3 = [20 x i8] c"Error opening file\0A\00"
@EOF = global i32 0
@.str.4 = [8 x i8] c"'\\x%X',\00"
define void @run(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
store i8* %0, i8** %2
store i32 0, i32* %4
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %18
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i32*
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %1
br label %19
19: ; preds = %24, %18
%20 = load i32*, i32** %5
%21 = call i32 @fgetc(i32* %20)
store i32 %21, i32* %3
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = load i32*, i32** %6
%26 = load i32, i32* %3
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %19
30: ; preds = %19
%31 = load i32*, i32** %5
%32 = call i32 @fclose(i32* %31)
%33 = load i32*, i32** %6
%34 = call i32 @fclose(i32* %33)
%35 = load i32, i32* %4
%36 = call i32 @create_prelude_h(i32 %35)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [16 x i8] c"src/prelude.bin\00"
@.str.2 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.3 = [20 x i8] c"Error opening file\0A\00"
@EOF = global i32 0
@.str.4 = [8 x i8] c"'\\x%X',\00"
define void @run(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i32* %2, null
br i1 %4, label %9, label %5
5: ; preds = %1
%6 = tail call i32 @fgetc(i32* %2)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %23, label %15
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i32*
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i64 19, i64 1, i32* %12)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %5, %15
%16 = phi i32 [ %20, %15 ], [ %6, %5 ]
%17 = phi i32 [ %19, %15 ], [ 0, %5 ]
%18 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%19 = add nuw nsw i32 %17, 1
%20 = tail call i32 @fgetc(i32* %2)
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %15
23: ; preds = %15, %5
%24 = phi i32 [ 0, %5 ], [ %19, %15 ]
%25 = tail call i32 @fclose(i32* %2)
%26 = tail call i32 @fclose(i32* %3)
%27 = tail call i32 @create_prelude_h(i32 %24)
ret void
}