#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 */
scalar_t__ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char const *);
scalar_t__ printf(char *, int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stderr;
int main(int argc, const char **argv) {
  if (argc != 2) {
    fprintf(stderr, "usage: bin2h infile >outfile\n");
    return 1;
  }
  FILE *inf = fopen(argv[1], "rb");
  if (inf == 0) {
    perror(argv[1]);
    return 2;
  }
  int width = 0;
  while (1) {
    int c = fgetc(inf);
    if (c < 0)
      break;
    width += printf("%d,", c);
    if (width > 75 || feof(inf)) {
      putchar('\n');
      width = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b1 <main+0x41>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1265 <main+0xf5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ed <main+0x7d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1265 <main+0xf5>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    120f <main+0x9f>
jmp    125e <main+0xee>
mov    -0x20(%rbp),%esi
lea    0xe08(%rip),%rdi
call   1040 <printf@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x4b,-0x1c(%rbp)
jg     1248 <main+0xd8>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1259 <main+0xe9>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x1c(%rbp)
jmp    11f4 <main+0x84>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11fd <main+0x8d>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe90(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1226 <main+0xb6>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <fgetc@plt>
test   %eax,%eax
js     1219 <main+0xa9>
xor    %ebp,%ebp
lea    0xe6d(%rip),%r14
jmp    11da <main+0x6a>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %ebx,%ebp
test   %eax,%eax
js     1219 <main+0xa9>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rax,%rbx
add    %ebp,%ebx
cmp    $0x4b,%ebx
jg     11c0 <main+0x50>
mov    %r15,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    11c0 <main+0x50>
jmp    11cc <main+0x5c>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    121b <main+0xab>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%rdi
call   1090 <perror@plt>
mov    $0x2,%eax
jmp    121b <main+0xab>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"usage: bin2h infile >outfile\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [4 x i8] c"%d,\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %50
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %26
21: ; preds = %14
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @perror(i8* %24)
store i32 2, i32* %3
br label %50
26: ; preds = %14
store i32 0, i32* %7
br label %27
27: ; preds = %26, %48
%28 = load i32*, i32** %6
%29 = call i32 @fgetc(i32* %28)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
br label %49
33: ; preds = %27
%34 = load i32, i32* %8
%35 = call i64 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = add nsw i64 %37, %35
%39 = trunc i64 %38 to i32
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = icmp sgt i32 %40, 75
br i1 %41, label %46, label %42
42: ; preds = %33
%43 = load i32*, i32** %6
%44 = call i64 @feof(i32* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42, %33
%47 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %7
br label %48
48: ; preds = %46, %42
br label %27
49: ; preds = %32
store i32 0, i32* %3
br label %50
50: ; preds = %49, %21, %11
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"usage: bin2h infile >outfile\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [4 x i8] c"%d,\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %34
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 %15, label %12
12: ; preds = %7
%13 = tail call i32 @fgetc(i32* %10)
%14 = icmp slt i32 %13, 0
br i1 %14, label %34, label %18
15: ; preds = %7
%16 = load i8*, i8** %8
%17 = tail call i32 @perror(i8* %16)
br label %34
18: ; preds = %12, %30
%19 = phi i32 [ %32, %30 ], [ %13, %12 ]
%20 = phi i32 [ %31, %30 ], [ 0, %12 ]
%21 = tail call i64 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%22 = trunc i64 %21 to i32
%23 = add i32 %20, %22
%24 = icmp sgt i32 %23, 75
br i1 %24, label %28, label %25
25: ; preds = %18
%26 = tail call i64 @feof(i32* %10)
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25, %18
%29 = tail call i32 @putchar(i8 signext 10)
br label %30
30: ; preds = %25, %28
%31 = phi i32 [ 0, %28 ], [ %23, %25 ]
%32 = tail call i32 @fgetc(i32* %10)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %18
34: ; preds = %30, %12, %15, %4
%35 = phi i32 [ 1, %4 ], [ 2, %15 ], [ 0, %12 ], [ 0, %30 ]
ret i32 %35
}