#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 /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *f;
  size_t f_sz;
  int i, c;
  if (argc < 2) {
    fprintf(stderr, "usage: file2gobyte file\n");
    return 1;
  }
  f = fopen(argv[1], "rb");
  if (f == NULL) {
    fprintf(stderr, "cannot open file %s\n", argv[1]);
    return 1;
  }
  fseek(f, 0, SEEK_END);
  f_sz = ftell(f);
  rewind(f);
  printf("FileName := \"%s\"\n", argv[1]);
  printf("FileSize := %ld\n", f_sz);
  printf("FileData := []byte{\n\t\t");
  for (i = 0; i < f_sz; i++) {
    c = fgetc(f);
    printf("'\\x%02x',", c);
    if ((i + 1) % 8 == 0)
      printf("\n\t\t");
    else
      printf(" ");
  }
  printf("\n}\n");
  fclose(f);
  return 0;
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    11c3 <main+0x43>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    130c <main+0x18c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe47(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1211 <main+0x91>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    130c <main+0x18c>
mov    -0x18(%rbp),%rdi
mov    0x2dcc(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    12ee <main+0x16e>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12cd <main+0x14d>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12db <main+0x15b>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12e0 <main+0x160>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1278 <main+0xf8>
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     11cc <main+0x2c>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    12e2 <main+0x142>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xe3f(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12c7 <main+0x127>
mov    %rax,%r13
mov    0x2df6(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %r13,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r13,%rdi
call   10a0 <ftell@plt>
mov    %rax,%rbp
mov    %r13,%rdi
call   1070 <rewind@plt>
mov    0x8(%r15),%rsi
lea    0xe12(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe16(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe16(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %rbp,%rbp
je     12b1 <main+0x111>
neg    %rbp
mov    $0x1,%ebx
lea    0xe12(%rip),%r15
lea    0xe07(%rip),%r12
jmp    128c <main+0xec>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x20,%edi
call   1030 <putchar@plt>
lea    (%rbx,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
je     12b1 <main+0x111>
mov    %r13,%rdi
call   1080 <fgetc@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
test   $0x7,%bl
jne    1270 <main+0xd0>
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    127a <main+0xda>
lea    0xdbd(%rip),%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
jmp    12e8 <main+0x148>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xd41(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"usage: file2gobyte file\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [21 x i8] c"cannot open file %s\0A\00"
@SEEK_END = global i32 0
@.str.3 = [18 x i8] c"FileName := \22%s\22\0A\00"
@.str.4 = [17 x i8] c"FileSize := %ld\0A\00"
@.str.5 = [23 x i8] c"FileData := []byte{\0A\09\09\00"
@.str.6 = [10 x i8] c"'\\x%02x',\00"
@.str.7 = [4 x i8] c"\0A\09\09\00"
@.str.8 = [2 x i8] c" \00"
@.str.9 = [4 x i8] c"\0A}\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %69
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %26)
store i32 1, i32* %3
br label %69
28: ; preds = %15
%29 = load i32*, i32** %6
%30 = load i32, i32* @SEEK_END
%31 = call i32 @fseek(i32* %29, i32 0, i32 %30)
%32 = load i32*, i32** %6
%33 = call i64 @ftell(i32* %32)
store i64 %33, i64* %7
%34 = load i32*, i32** %6
%35 = call i32 @rewind(i32* %34)
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%40 = load i64, i64* %7
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i64 %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %8
br label %43
43: ; preds = %62, %28
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = load i64, i64* %7
%47 = icmp ult i64 %45, %46
br i1 %47, label %48, label %65
48: ; preds = %43
%49 = load i32*, i32** %6
%50 = call i32 @fgetc(i32* %49)
store i32 %50, i32* %9
%51 = load i32, i32* %9
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %51)
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
%55 = srem i32 %54, 8
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %48
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
br label %61
59: ; preds = %48
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %61
61: ; preds = %59, %57
br label %62
62: ; preds = %61
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 1
store i32 %64, i32* %8
br label %43
65: ; preds = %43
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%67 = load i32*, i32** %6
%68 = call i32 @fclose(i32* %67)
store i32 0, i32* %3
br label %69
69: ; preds = %65, %22, %12
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"usage: file2gobyte file\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [21 x i8] c"cannot open file %s\0A\00"
@SEEK_END = global i32 0
@.str.3 = [18 x i8] c"FileName := \22%s\22\0A\00"
@.str.4 = [17 x i8] c"FileSize := %ld\0A\00"
@.str.5 = [23 x i8] c"FileData := []byte{\0A\09\09\00"
@.str.6 = [10 x i8] c"'\\x%02x',\00"
@.str.7 = [4 x i8] c"\0A\09\09\00"
@str = [3 x i8] c"\0A}\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %42
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %8
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %42
16: ; preds = %7
%17 = load i32, i32* @SEEK_END
%18 = tail call i32 @fseek(i32* %10, i32 0, i32 %17)
%19 = tail call i64 @ftell(i32* %10)
%20 = tail call i32 @rewind(i32* %10)
%21 = load i8*, i8** %8
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i64 %19)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp eq i64 %19, 0
br i1 %25, label %39, label %26
26: ; preds = %16, %37
%27 = phi i64 [ %30, %37 ], [ 0, %16 ]
%28 = tail call i32 @fgetc(i32* %10)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %28)
%30 = add nuw i64 %27, 1
%31 = and i64 %30, 7
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
br label %37
35: ; preds = %26
%36 = tail call i32 @putchar(i32 32)
br label %37
37: ; preds = %33, %35
%38 = icmp eq i64 %30, %19
br i1 %38, label %39, label %26
39: ; preds = %37, %16
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%41 = tail call i32 @fclose(i32* %10)
br label %42
42: ; preds = %39, %12, %4
%43 = phi i32 [ 1, %4 ], [ 1, %12 ], [ 0, %39 ]
ret i32 %43
}