#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*/ time_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ Abort(char *, char *);
int EOF;
char *ctime(int /*<<< orphan*/ *);
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*/ *stdout;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *inFile;
  FILE *outFile = stdout;
  time_t now = time(NULL);
  int ch, i;
  if (argc != 2)
    Abort("Usage: %s bin-file [> result]", argv[0]);
  if ((inFile = fopen(argv[1], "rb")) == NULL)
    Abort("Cannot open %s\n", argv[1]);
  fprintf(outFile,
          "/* data statements for file %s at %.24s */\n"
          "/* Generated by BIN2C, G. Vanem 1995 */\n",
          argv[1], ctime(&now));
  i = 0;
  while ((ch = fgetc(inFile)) != EOF) {
    if (i++ % 12 == 0)
      fputs("\n  ", outFile);
    fprintf(outFile, "0x%02X,", ch);
  }
  fputc('\n', outFile);
  fclose(inFile);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11dd <main+0x4d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe28(%rip),%rdi
call   10a0 <Abort@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe32(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1213 <main+0x83>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe13(%rip),%rdi
call   10a0 <Abort@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
lea    -0x24(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x28(%rbp)
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%eax
je     12b1 <main+0x121>
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x2c(%rbp)
mov    $0xc,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1297 <main+0x107>
mov    -0x20(%rbp),%rsi
lea    0xdf3(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1250 <main+0xc0>
mov    -0x20(%rbp),%rsi
mov    $0xa,%edi
call   1070 <fputc@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x40,%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,%r15
mov    %edi,%ebp
mov    0x2e31(%rip),%rax
mov    (%rax),%rbx
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0x4(%rsp)
cmp    $0x2,%ebp
je     11c9 <main+0x39>
mov    (%r15),%rsi
lea    0xe3c(%rip),%rdi
call   1090 <Abort@plt>
mov    0x8(%r15),%rdi
lea    0xe4a(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11f1 <main+0x61>
mov    0x8(%r15),%rsi
lea    0xe35(%rip),%rdi
call   1090 <Abort@plt>
mov    0x8(%r15),%rbp
lea    0x4(%rsp),%rdi
call   1040 <ctime@plt>
lea    0xe2b(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    0x2dc1(%rip),%rax
cmp    (%rax),%ebp
jne    1251 <main+0xc1>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe31(%rip),%r12
xor    %r15d,%r15d
xor    %r13d,%r13d
jmp    128c <main+0xfc>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
add    $0xffffffff,%r15d
add    $0x1,%r13d
mov    0x2d60(%rip),%rax
cmp    (%rax),%ebp
je     122b <main+0x9b>
mov    %r13d,%eax
mov    $0xaaaaaaab,%ecx
imul   %rcx,%rax
shr    $0x23,%rax
lea    (%rax,%rax,2),%eax
shl    $0x2,%eax
add    %r15d,%eax
jne    1260 <main+0xd0>
mov    $0x3,%esi
mov    $0x1,%edx
lea    0xdcd(%rip),%rdi
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
jmp    1260 <main+0xd0>

LLVM IR (-O0):
@stdout = global i32* null
@.str = [30 x i8] c"Usage: %s bin-file [> result]\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [16 x i8] c"Cannot open %s\0A\00"
@.str.3 = [84 x i8] c"/* data statements for file %s at %.24s */\0A/* Generated by BIN2C, G. Vanem 1995 */\0A\00"
@EOF = global i32 0
@.str.4 = [4 x i8] c"\0A \00"
@.str.5 = [8 x i8] c"0x%02X,\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 = call i32 @time(i32* null)
store i32 %12, i32* %8
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @Abort(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %15, %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %31
26: ; preds = %20
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @Abort(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %26, %20
%32 = load i32*, i32** %7
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i8* @ctime(i32* %8)
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.3, i64 0, i64 0), i8* %35, i8* %36)
store i32 0, i32* %10
br label %38
38: ; preds = %51, %31
%39 = load i32*, i32** %6
%40 = call i32 @fgetc(i32* %39)
store i32 %40, i32* %9
%41 = load i32, i32* @EOF
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %55
43: ; preds = %38
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
%46 = srem i32 %44, 12
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = load i32*, i32** %7
%50 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %49)
br label %51
51: ; preds = %48, %43
%52 = load i32*, i32** %7
%53 = load i32, i32* %9
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %53)
br label %38
55: ; preds = %38
%56 = load i32*, i32** %7
%57 = call i32 @fputc(i8 signext 10, i32* %56)
%58 = load i32*, i32** %6
%59 = call i32 @fclose(i32* %58)
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32* null
@.str = [30 x i8] c"Usage: %s bin-file [> result]\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [16 x i8] c"Cannot open %s\0A\00"
@.str.3 = [84 x i8] c"/* data statements for file %s at %.24s */\0A/* Generated by BIN2C, G. Vanem 1995 */\0A\00"
@EOF = global i32 0
@.str.4 = [4 x i8] c"\0A \00"
@.str.5 = [8 x i8] c"0x%02X,\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = load i32*, i32** @stdout
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %3
%7 = icmp eq i32 %0, 2
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 @Abort(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %8, %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 %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %12
%18 = tail call i32 @Abort(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %11
%20 = load i8*, i8** %12
%21 = call i8* @ctime(i32* %3)
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.3, i64 0, i64 0), i8* %20, i8* %21)
%23 = call i32 @fgetc(i32* %14)
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %39, label %26
26: ; preds = %19, %34
%27 = phi i32 [ %36, %34 ], [ %23, %19 ]
%28 = phi i32 [ %29, %34 ], [ 0, %19 ]
%29 = add nuw nsw i32 %28, 1
%30 = urem i32 %28, 12
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 3, i64 1, i32* %4)
br label %34
34: ; preds = %32, %26
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %27)
%36 = call i32 @fgetc(i32* %14)
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %26
39: ; preds = %34, %19
%40 = call i32 @fputc(i8 signext 10, i32* %4)
%41 = call i32 @fclose(i32* %14)
ret i32 0
}