#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*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
int main(int argc, char **argv) {
  FILE *inFile;
  FILE *outFile = stdout;
  unsigned int word;
  int ch, i;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s bin-file [> result]\n", argv[0]);
    return 1;
  }
  if ((inFile = fopen(argv[1], "rb")) == NULL) {
    fprintf(stderr, "Cannot open %s\n", argv[1]);
    return 1;
  }
  i = 0;
  word = 0;
  while ((ch = fgetc(inFile)) != EOF) {
    word |= ch << (8 * (i & 3));
    if (i == 0)
      fputs("  ", outFile);
    else if (i % 32 == 0)
      fputs("\n  ", outFile);
    i++;
    if (i % 4 == 0) {
      fprintf(outFile, "0x%08X,", word);
      if (i % 32 != 0)
        fputs(" ", outFile);
      word = 0;
    }
  }
  if (i % 4)
    fprintf(outFile, "0x%08X,", word);
  fputc('\n', outFile);
  fclose(inFile);
  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)
mov    0x2e53(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b9 <main+0x59>
mov    0x2e43(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1335 <main+0x1d5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe57(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1207 <main+0xa7>
mov    0x2df6(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1335 <main+0x1d5>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x28(%rbp)
mov    0x2dc0(%rip),%rcx
cmp    (%rcx),%eax
je     12ee <main+0x18e>
mov    -0x28(%rbp),%eax
mov    -0x2c(%rbp),%ecx
and    $0x3,%ecx
shl    $0x3,%ecx
shl    %cl,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1263 <main+0x103>
mov    -0x20(%rbp),%rsi
lea    0xdda(%rip),%rdi
call   1040 <fputs@plt>
jmp    128c <main+0x12c>
mov    -0x2c(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1287 <main+0x127>
mov    -0x20(%rbp),%rsi
lea    0xdb0(%rip),%rdi
call   1040 <fputs@plt>
jmp    128c <main+0x12c>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12e9 <main+0x189>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xd7f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x2c(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12e2 <main+0x182>
mov    -0x20(%rbp),%rsi
lea    0xd57(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x0,-0x24(%rbp)
jmp    1215 <main+0xb5>
mov    -0x2c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1317 <main+0x1b7>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xd26(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rsi
mov    $0xa,%edi
call   1060 <fputc@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
mov    %rsi,%rbp
cmp    $0x2,%edi
jne    1265 <main+0x105>
mov    0x2e52(%rip),%rax
mov    (%rax),%r14
mov    0x8(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     127c <main+0x11c>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    0x2e3c(%rip),%r12
cmp    (%r12),%eax
je     12b8 <main+0x158>
xor    %r13d,%r13d
lea    0xe73(%rip),%r15
xor    %ebp,%ebp
jmp    11fd <main+0x9d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %r14,%rcx
call   1080 <fwrite@plt>
mov    $0x1,%r13d
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    (%r12),%eax
je     129f <main+0x13f>
lea    0x0(,%r13,8),%ecx
shl    %cl,%eax
mov    %ebp,%ecx
mov    %eax,%ebp
or     %ecx,%ebp
test   %r13d,%r13d
je     11d0 <main+0x70>
test   $0x1f,%r13b
jne    1231 <main+0xd1>
mov    $0x3,%esi
mov    $0x1,%edx
lea    0xe09(%rip),%rdi
mov    %r14,%rcx
call   1080 <fwrite@plt>
add    $0x1,%r13d
test   $0x3,%r13b
jne    11eb <main+0x8b>
mov    %r14,%rdi
lea    0xdf1(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
test   $0x1f,%r13b
je     1261 <main+0x101>
mov    $0x20,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
xor    %ebp,%ebp
jmp    11eb <main+0x8b>
mov    0x2d6c(%rip),%rax
movslq (%rax),%rdi
mov    0x0(%rbp),%rdx
lea    0xd86(%rip),%rsi
jmp    1291 <main+0x131>
mov    0x2d55(%rip),%rax
movslq (%rax),%rdi
mov    0x8(%rbp),%rdx
lea    0xd91(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    12cf <main+0x16f>
test   $0x3,%r13b
je     12b8 <main+0x158>
lea    0xd8a(%rip),%rsi
mov    %r14,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xa,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32* null
@stderr = global i32 0
@.str = [31 x i8] c"Usage: %s bin-file [> result]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [16 x i8] c"Cannot open %s\0A\00"
@EOF = global i32 0
@.str.3 = [3 x i8] c" \00"
@.str.4 = [4 x i8] c"\0A \00"
@.str.5 = [8 x i8] c"0x%08X,\00"
@.str.6 = [2 x i8] c" \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32*, i32** @stdout
store i32* %11, i32** %7
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i32*
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 1, i32* %3
br label %94
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %6
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %36
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = sext i32 %29 to i64
%31 = inttoptr i64 %30 to i32*
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %34)
store i32 1, i32* %3
br label %94
36: ; preds = %22
store i32 0, i32* %10
store i32 0, i32* %8
br label %37
37: ; preds = %80, %36
%38 = load i32*, i32** %6
%39 = call i32 @fgetc(i32* %38)
store i32 %39, i32* %9
%40 = load i32, i32* @EOF
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %81
42: ; preds = %37
%43 = load i32, i32* %9
%44 = load i32, i32* %10
%45 = and i32 %44, 3
%46 = mul nsw i32 8, %45
%47 = shl i32 %43, %46
%48 = load i32, i32* %8
%49 = or i32 %48, %47
store i32 %49, i32* %8
%50 = load i32, i32* %10
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %42
%53 = load i32*, i32** %7
%54 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %53)
br label %63
55: ; preds = %42
%56 = load i32, i32* %10
%57 = srem i32 %56, 32
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = load i32*, i32** %7
%61 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %60)
br label %62
62: ; preds = %59, %55
br label %63
63: ; preds = %62, %52
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
store i32 %65, i32* %10
%66 = load i32, i32* %10
%67 = srem i32 %66, 4
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %80
69: ; preds = %63
%70 = load i32*, i32** %7
%71 = load i32, i32* %8
%72 = call i32 (i32*, i8*, ...) @fprintf(i32* %70, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %71)
%73 = load i32, i32* %10
%74 = srem i32 %73, 32
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %69
%77 = load i32*, i32** %7
%78 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32* %77)
br label %79
79: ; preds = %76, %69
store i32 0, i32* %8
br label %80
80: ; preds = %79, %63
br label %37
81: ; preds = %37
%82 = load i32, i32* %10
%83 = srem i32 %82, 4
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %89
85: ; preds = %81
%86 = load i32*, i32** %7
%87 = load i32, i32* %8
%88 = call i32 (i32*, i8*, ...) @fprintf(i32* %86, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %87)
br label %89
89: ; preds = %85, %81
%90 = load i32*, i32** %7
%91 = call i32 @fputc(i8 signext 10, i32* %90)
%92 = load i32*, i32** %6
%93 = call i32 @fclose(i32* %92)
store i32 0, i32* %3
br label %94
94: ; preds = %89, %28, %14
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
@stdout = global i32* null
@stderr = global i32 0
@.str = [31 x i8] c"Usage: %s bin-file [> result]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [16 x i8] c"Cannot open %s\0A\00"
@EOF = global i32 0
@.str.3 = [3 x i8] c" \00"
@.str.4 = [4 x i8] c"\0A \00"
@.str.5 = [8 x i8] c"0x%08X,\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32*, i32** @stdout
%4 = icmp eq i32 %0, 2
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i32*
%9 = load i8*, i8** %1
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %66
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = tail call i32 @fgetc(i32* %14)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %63, label %26
20: ; preds = %11
%21 = load i32, i32* @stderr
%22 = sext i32 %21 to i64
%23 = inttoptr i64 %22 to i32*
%24 = load i8*, i8** %12
%25 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %66
26: ; preds = %16, %52
%27 = phi i32 [ %55, %52 ], [ %17, %16 ]
%28 = phi i32 [ %53, %52 ], [ 0, %16 ]
%29 = phi i32 [ %54, %52 ], [ 0, %16 ]
%30 = shl i32 %28, 3
%31 = and i32 %30, 24
%32 = shl i32 %27, %31
%33 = or i32 %32, %29
%34 = icmp eq i32 %28, 0
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %3)
br label %52
37: ; preds = %26
%38 = and i32 %28, 31
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 3, i64 1, i32* %3)
br label %42
42: ; preds = %37, %40
%43 = add nuw nsw i32 %28, 1
%44 = and i32 %43, 3
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %33)
%48 = and i32 %43, 31
%49 = icmp eq i32 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %46
%51 = tail call i32 bitcast (i32 (i8, i32*)* @fputc to i32 (i32, i32*)*)(i32 32, i32* %3)
br label %52
52: ; preds = %35, %46, %50, %42
%53 = phi i32 [ %43, %42 ], [ %43, %50 ], [ %43, %46 ], [ 1, %35 ]
%54 = phi i32 [ %33, %42 ], [ 0, %50 ], [ 0, %46 ], [ %33, %35 ]
%55 = tail call i32 @fgetc(i32* %14)
%56 = load i32, i32* @EOF
%57 = icmp eq i32 %55, %56
br i1 %57, label %58, label %26
58: ; preds = %52
%59 = and i32 %53, 3
%60 = icmp eq i32 %59, 0
br i1 %60, label %63, label %61
61: ; preds = %58
%62 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %54)
br label %63
63: ; preds = %16, %61, %58
%64 = tail call i32 @fputc(i8 signext 10, i32* %3)
%65 = tail call i32 @fclose(i32* %14)
br label %66
66: ; preds = %63, %20, %5
%67 = phi i32 [ 1, %5 ], [ 1, %20 ], [ 0, %63 ]
ret i32 %67
}