#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*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printFooter(int /*<<< orphan*/ *);
int /*<<< orphan*/ printHeader(int /*<<< orphan*/ *, char const *);
int /*<<< orphan*/ printUsage(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char outNameBuff[256];
  unsigned char readBuffer[12];
  const char *outName = NULL, *inName;
  size_t fileRead = 0, i;
  FILE *inFile, *outFile;
  if (argc == 1) {
    printUsage(argv[0]);
    return 2;
  }
  inName = argv[1];
  if (argc >= 3)
    outName = argv[2];
  else {
    sprintf(outNameBuff, "%s.h", argv[1]);
    outName = outNameBuff;
  }
  inFile = fopen(inName, "rb");
  if (!inFile) {
    fprintf(stderr, "ERROR: Can't open input file %s\n", inName);
    return 1;
  }
  outFile = fopen(outName, "w");
  if (!outFile) {
    fprintf(stderr, "ERROR: Can't output input file %s\n", outName);
    return 1;
  }
  printHeader(outFile, inName);
  do {
    fileRead = fread(readBuffer, 1, 12, inFile);
    if (fileRead > 0) {
      for (i = 0; i < fileRead; i++)
        fprintf(outFile, "%c0x%02x,", (i == 0 ? '\t' : ' '), readBuffer[i]);
      fprintf(outFile, "\n");
    }
  } while (fileRead == 12);
  printFooter(outFile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x128(%rbp)
movq   $0x0,-0x138(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11c1 <main+0x51>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <printUsage@plt>
movl   $0x2,-0x4(%rbp)
jmp    13af <main+0x23f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x130(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     11ee <main+0x7e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x128(%rbp)
jmp    1217 <main+0xa7>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdfc(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x130(%rbp),%rdi
lea    0xde0(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x148(%rbp)
cmpq   $0x0,-0x148(%rbp)
jne    126a <main+0xfa>
mov    0x2d9a(%rip),%rax
movslq (%rax),%rdi
mov    -0x130(%rbp),%rdx
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13af <main+0x23f>
mov    -0x128(%rbp),%rdi
lea    0xdb1(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x150(%rbp)
cmpq   $0x0,-0x150(%rbp)
jne    12bd <main+0x14d>
mov    0x2d47(%rip),%rax
movslq (%rax),%rdi
mov    -0x128(%rbp),%rdx
lea    0xd81(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13af <main+0x23f>
mov    -0x150(%rbp),%rdi
mov    -0x130(%rbp),%rsi
call   1070 <printHeader@plt>
lea    -0x11c(%rbp),%rdi
mov    -0x148(%rbp),%rcx
mov    $0x1,%esi
mov    $0xc,%edx
call   1040 <fread@plt>
mov    %rax,-0x138(%rbp)
cmpq   $0x0,-0x138(%rbp)
jbe    1389 <main+0x219>
movq   $0x0,-0x140(%rbp)
mov    -0x140(%rbp),%rax
cmp    -0x138(%rbp),%rax
jae    1374 <main+0x204>
mov    -0x150(%rbp),%rdi
mov    -0x140(%rbp),%rcx
mov    $0x20,%edx
mov    $0x9,%eax
cmp    $0x0,%rcx
cmove  %eax,%edx
mov    -0x140(%rbp),%rax
movzbl -0x11c(%rbp,%rax,1),%ecx
ff
lea    0xcf8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x140(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x140(%rbp)
jmp    130d <main+0x19d>
mov    -0x150(%rbp),%rdi
lea    0xca5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    138e <main+0x21e>
cmpq   $0xc,-0x138(%rbp)
0c
je     12d0 <main+0x160>
mov    -0x150(%rbp),%rdi
call   1030 <printFooter@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
cmp    $0x1,%edi
jne    11a8 <main+0x28>
mov    (%rsi),%rdi
call   1070 <printUsage@plt>
mov    $0x2,%eax
jmp    12cc <main+0x14c>
mov    0x8(%rsi),%r15
cmp    $0x3,%edi
jl     11b7 <main+0x37>
mov    0x10(%rsi),%r12
jmp    11ce <main+0x4e>
lea    0x10(%rsp),%r12
lea    0xe3d(%rip),%rsi
mov    %r12,%rdi
mov    %r15,%rdx
call   10a0 <sprintf@plt>
lea    0xe30(%rip),%rsi
mov    %r15,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1296 <main+0x116>
mov    %rax,%r14
lea    0xe39(%rip),%rsi
mov    %r12,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     12ac <main+0x12c>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r15,%rsi
call   1080 <printHeader@plt>
mov    $0x9,%ebp
lea    0xe33(%rip),%r12
nopl   0x0(%rax,%rax,1)
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0xc,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     128a <main+0x10a>
mov    %rax,%rbx
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %r15,%r15
mov    $0x20,%edx
cmove  %ebp,%edx
movzbl 0x4(%rsp,%r15,1),%ecx
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%r15
cmp    %r15,%rbx
jne    1250 <main+0xd0>
mov    $0xa,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
cmp    $0xc,%rbx
je     1220 <main+0xa0>
mov    %r13,%rdi
call   1030 <printFooter@plt>
xor    %eax,%eax
jmp    12cc <main+0x14c>
mov    0x2d43(%rip),%rax
movslq (%rax),%rdi
lea    0xd61(%rip),%rsi
mov    %r15,%rdx
jmp    12c0 <main+0x140>
mov    0x2d2d(%rip),%rax
movslq (%rax),%rdi
lea    0xd6e(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s.h\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [33 x i8] c"ERROR: Can't open input file %s\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [35 x i8] c"ERROR: Can't output input file %s\0A\00"
@.str.5 = [10 x i8] c"%c0x%02x,\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca [12 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
store i64 0, i64* %10
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @printUsage(i8* %19)
store i32 2, i32* %3
br label %99
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %9
%25 = load i32, i32* %4
%26 = icmp sge i32 %25, 3
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
store i8* %30, i8** %8
br label %38
31: ; preds = %21
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
store i8* %37, i8** %8
br label %38
38: ; preds = %31, %27
%39 = load i8*, i8** %9
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %40, i32** %12
%41 = load i32*, i32** %12
%42 = icmp ne i32* %41, null
br i1 %42, label %49, label %43
43: ; preds = %38
%44 = load i32, i32* @stderr
%45 = sext i32 %44 to i64
%46 = inttoptr i64 %45 to i32*
%47 = load i8*, i8** %9
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %47)
store i32 1, i32* %3
br label %99
49: ; preds = %38
%50 = load i8*, i8** %8
%51 = call i32* @fopen(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %51, i32** %13
%52 = load i32*, i32** %13
%53 = icmp ne i32* %52, null
br i1 %53, label %60, label %54
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = sext i32 %55 to i64
%57 = inttoptr i64 %56 to i32*
%58 = load i8*, i8** %8
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %57, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %58)
store i32 1, i32* %3
br label %99
60: ; preds = %49
%61 = load i32*, i32** %13
%62 = load i8*, i8** %9
%63 = call i32 @printHeader(i32* %61, i8* %62)
br label %64
64: ; preds = %93, %60
%65 = getelementptr inbounds [12 x i8], [12 x i8]* %7, i64 0, i64 0
%66 = load i32*, i32** %12
%67 = call i64 @fread(i8* %65, i32 1, i32 12, i32* %66)
store i64 %67, i64* %10
%68 = load i64, i64* %10
%69 = icmp ugt i64 %68, 0
br i1 %69, label %70, label %92
70: ; preds = %64
store i64 0, i64* %11
br label %71
71: ; preds = %86, %70
%72 = load i64, i64* %11
%73 = load i64, i64* %10
%74 = icmp ult i64 %72, %73
br i1 %74, label %75, label %89
75: ; preds = %71
%76 = load i32*, i32** %13
%77 = load i64, i64* %11
%78 = icmp eq i64 %77, 0
%79 = zext i1 %78 to i64
%80 = select i1 %78, i32 9, i32 32
%81 = load i64, i64* %11
%82 = getelementptr inbounds [12 x i8], [12 x i8]* %7, i64 0, i64 %81
%83 = load i8, i8* %82
%84 = zext i8 %83 to i32
%85 = call i32 (i32*, i8*, ...) @fprintf(i32* %76, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %80, i32 %84)
br label %86
86: ; preds = %75
%87 = load i64, i64* %11
%88 = add i64 %87, 1
store i64 %88, i64* %11
br label %71
89: ; preds = %71
%90 = load i32*, i32** %13
%91 = call i32 (i32*, i8*, ...) @fprintf(i32* %90, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %92
92: ; preds = %89, %64
br label %93
93: ; preds = %92
%94 = load i64, i64* %10
%95 = icmp eq i64 %94, 12
br i1 %95, label %64, label %96
96: ; preds = %93
%97 = load i32*, i32** %13
%98 = call i32 @printFooter(i32* %97)
store i32 0, i32* %3
br label %99
99: ; preds = %96, %54, %43, %16
%100 = load i32, i32* %3
ret i32 %100
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s.h\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [33 x i8] c"ERROR: Can't open input file %s\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [35 x i8] c"ERROR: Can't output input file %s\0A\00"
@.str.5 = [10 x i8] c"%c0x%02x,\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [12 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 @printUsage(i8* %9)
br label %57
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = icmp sgt i32 %0, 2
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
br label %20
18: ; preds = %11
%19 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %20
20: ; preds = %18, %15
%21 = phi i8* [ %17, %15 ], [ %5, %18 ]
%22 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i32*
%28 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %57
29: ; preds = %20
%30 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = sext i32 %33 to i64
%35 = inttoptr i64 %34 to i32*
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %21)
br label %57
37: ; preds = %29
%38 = tail call i32 @printHeader(i32* %30, i8* %13)
br label %39
39: ; preds = %52, %37
%40 = call i64 @fread(i8* %6, i32 1, i32 12, i32* %22)
%41 = icmp eq i64 %40, 0
br i1 %41, label %55, label %42
42: ; preds = %39, %42
%43 = phi i64 [ %50, %42 ], [ 0, %39 ]
%44 = icmp eq i64 %43, 0
%45 = select i1 %44, i32 9, i32 32
%46 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 %43
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %45, i32 %48)
%50 = add nuw i64 %43, 1
%51 = icmp eq i64 %50, %40
br i1 %51, label %52, label %42
52: ; preds = %42
%53 = tail call i32 @fputc(i32 10, i32* %30)
%54 = icmp eq i64 %40, 12
br i1 %54, label %39, label %55
55: ; preds = %39, %52
%56 = tail call i32 @printFooter(i32* %30)
br label %57
57: ; preds = %55, %32, %24, %8
%58 = phi i32 [ 2, %8 ], [ 0, %55 ], [ 1, %32 ], [ 1, %24 ]
ret i32 %58
}