#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 */
struct stat {
  int st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *filename = argv[1];
  int size, i;
  FILE *f;
  struct stat st;
  stat(filename, &st);
  size = st.st_size;
  if ((f = fopen(filename, "rb")) == NULL) {
    fprintf(stderr, "%s: error opening %s\n", argv[0], filename);
    return EXIT_FAILURE;
  }
  printf("unsigned char code[%d] = {\n", size);
  for (i = 0; i < size; i++) {
    printf("%d, ", fgetc(f));
  }
  printf("};\n\n");
  fclose(f);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <stat@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11e4 <main+0x84>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe35(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1252 <main+0xf2>
mov    -0x1c(%rbp),%esi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    122f <main+0xcf>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,%esi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11fc <main+0x9c>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    0x8(%rsi),%r14
mov    %rsp,%rsi
mov    %r14,%rdi
call   1080 <stat@plt>
mov    (%rsp),%ebp
lea    0xe6d(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     11f6 <main+0x86>
mov    %rax,%rbx
lea    0xe6f(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebp,%ebp
jle    11d9 <main+0x69>
lea    0xe77(%rip),%r14
xchg   %ax,%ax
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffff,%ebp
jne    11c0 <main+0x50>
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2ddc(%rip),%rax
jmp    1218 <main+0xa8>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xdfa(%rip),%rsi
mov    %r14,%rcx
call   1070 <fprintf@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"%s: error opening %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [28 x i8] c"unsigned char code[%d] = {\0A\00"
@.str.3 = [5 x i8] c"%d, \00"
@.str.4 = [5 x i8] c"};\0A\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = call i32 @stat(i8* %14, %struct.stat* %10)
%16 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%17 = load i32, i32* %16
store i32 %17, i32* %7
%18 = load i8*, i8** %6
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %9
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %29
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = load i8*, i8** %6
%27 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %3
br label %48
29: ; preds = %2
%30 = load i32, i32* %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %30)
store i32 0, i32* %8
br label %32
32: ; preds = %40, %29
%33 = load i32, i32* %8
%34 = load i32, i32* %7
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %43
36: ; preds = %32
%37 = load i32*, i32** %9
%38 = call i32 @fgetc(i32* %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %36
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %32
43: ; preds = %32
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%45 = load i32*, i32** %9
%46 = call i32 @fclose(i32* %45)
%47 = load i32, i32* @EXIT_SUCCESS
store i32 %47, i32* %3
br label %48
48: ; preds = %43, %21
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"%s: error opening %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [28 x i8] c"unsigned char code[%d] = {\0A\00"
@.str.3 = [5 x i8] c"%d, \00"
@EXIT_SUCCESS = global i32 0
@str = [4 x i8] c"};\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = bitcast %struct.stat* %3 to i8*
%7 = call i32 @stat(i8* %5, %struct.stat* %3)
%8 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %5)
br label %28
16: ; preds = %2
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%18 = icmp sgt i32 %9, 0
br i1 %18, label %19, label %25
19: ; preds = %16, %19
%20 = phi i32 [ %23, %19 ], [ 0, %16 ]
%21 = tail call i32 @fgetc(i32* %10)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = add nuw nsw i32 %20, 1
%24 = icmp eq i32 %23, %9
br i1 %24, label %25, label %19
25: ; preds = %19, %16
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%27 = tail call i32 @fclose(i32* %10)
br label %28
28: ; preds = %25, %12
%29 = phi i32* [ @EXIT_FAILURE, %12 ], [ @EXIT_SUCCESS, %25 ]
%30 = load i32, i32* %29
ret i32 %30
}