#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 (!feof(inf)) {
    width += printf("%d,", fgetc(inf));
    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    1271 <main+0x101>
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    1271 <main+0x101>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1213 <main+0xa3>
jmp    126a <main+0xfa>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,%esi
lea    0xdfc(%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     1254 <main+0xe4>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1265 <main+0xf5>
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   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    1205 <main+0x95>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe92(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1229 <main+0xb9>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <feof@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1223 <main+0xb3>
xor    %ebx,%ebx
lea    0xe69(%rip),%r14
jmp    11d9 <main+0x69>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    1221 <main+0xb1>
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
movslq %ebx,%rbx
add    %rax,%rbx
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    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    1223 <main+0xb3>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x8(%r14),%rdi
call   1090 <perror@plt>
mov    $0x2,%eax
jmp    1223 <main+0xb3>

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

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 %36
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 i64 @feof(i32* %10)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %36
15: ; preds = %7
%16 = load i8*, i8** %8
%17 = tail call i32 @perror(i8* %16)
br label %36
18: ; preds = %12, %32
%19 = phi i64 [ %33, %32 ], [ 0, %12 ]
%20 = tail call i32 @fgetc(i32* %10)
%21 = tail call i64 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = shl i64 %19, 32
%23 = ashr exact i64 %22, 32
%24 = add nsw i64 %21, %23
%25 = trunc i64 %24 to i32
%26 = icmp sgt i32 %25, 75
br i1 %26, label %30, label %27
27: ; preds = %18
%28 = tail call i64 @feof(i32* %10)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27, %18
%31 = tail call i32 @putchar(i8 signext 10)
br label %32
32: ; preds = %30, %27
%33 = phi i64 [ 0, %30 ], [ %24, %27 ]
%34 = tail call i64 @feof(i32* %10)
%35 = icmp eq i64 %34, 0
br i1 %35, label %18, label %36
36: ; preds = %32, %12, %15, %4
%37 = phi i32 [ 1, %4 ], [ 2, %15 ], [ 0, %12 ], [ 0, %32 ]
ret i32 %37
}