#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 */

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ free(char *);
char *make_ident(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  unsigned char buf[BUFSIZ];
  char *ident;
  int fd, i, total, rd, need_comma;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s binary_file > output_file\n", argv[0]);
    return -1;
  }
  fd = open(argv[1], O_RDONLY);
  if (fd == -1) {
    fprintf(stderr, "%s: can't open %s for reading\n", argv[0], argv[1]);
    return -1;
  }
  ident = make_ident(argv[1]);
  printf("static const unsigned char %s[] = {", ident);
  for (total = 0, need_comma = 0; (rd = read(fd, buf, BUFSIZ)) != 0;) {
    if (rd == -1) {
      fprintf(stderr, "%s: file read error\n", argv[0]);
      return -1;
    }
    for (i = 0; i < rd; i++) {
      if (need_comma)
        printf(", ");
      else
        need_comma = 1;
      if ((total % 11) == 0)
        printf("\n\t");
      printf("0x%.2x", buf[i]);
      total++;
    }
  }
  printf("\n};\n");
  close(fd);
  free(ident);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ed <main+0x7d>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    1392 <main+0x222>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1249 <main+0xd9>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    1392 <main+0x222>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <make_ident@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x48(%rbp),%rsi
mov    -0x2c(%rbp),%edi
mov    0x2d48(%rip),%rax
mov    (%rax),%edx
call   1060 <read@plt>
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
je     1365 <main+0x1f5>
cmpl   $0xffffffff,-0x38(%rbp)
jne    12d6 <main+0x166>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    1392 <main+0x222>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1360 <main+0x1f0>
cmpl   $0x0,-0x3c(%rbp)
je     1306 <main+0x196>
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    130d <main+0x19d>
movl   $0x1,-0x3c(%rbp)
mov    -0x34(%rbp),%eax
mov    $0xb,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    132f <main+0x1bf>
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%rax
movslq -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xd41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12dd <main+0x16d>
jmp    127a <main+0x10a>
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r13
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x1,%edi
jg     11cc <main+0x4c>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xe39(%rip),%rsi
jmp    134b <main+0x1cb>
mov    0x8(%r13),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1316 <main+0x196>
mov    %eax,%r15d
mov    0x8(%r13),%rdi
call   10a0 <make_ident@plt>
lea    0xe4a(%rip),%rdi
mov    %rax,-0x40(%rbp)
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r14b
movl   $0x0,-0x2c(%rbp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2da9(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     1337 <main+0x1b7>
mov    %eax,%r12d
test   %eax,%eax
je     1366 <main+0x1e6>
jle    1220 <main+0xa0>
test   $0x1,%r14b
jne    125e <main+0xde>
lea    0xe26(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,-0x38(%rbp)
imul   $0xba2e8ba3,-0x2c(%rbp),%eax
add    $0xba2e8ba,%eax
cmp    $0x1745d174,%eax
ja     1283 <main+0x103>
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl (%rbx),%esi
lea    0xdf6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x1,%r12d
jne    12aa <main+0x12a>
add    %r12d,-0x2c(%rbp)
xor    %r14d,%r14d
mov    -0x38(%rbp),%r13
jmp    1220 <main+0xa0>
mov    %r12d,%eax
mov    %rax,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rax,-0x48(%rbp)
mov    $0x1,%r14d
jmp    12dd <main+0x15d>
movzbl (%rbx,%r14,1),%esi
lea    0xdb7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r14
cmp    %r14,-0x50(%rbp)
je     129a <main+0x11a>
mov    -0x48(%rbp),%rax
lea    (%rax,%r14,1),%r13d
lea    0xd91(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
imul   $0xba2e8ba3,%r13d,%eax
add    $0xba2e8ba,%eax
cmp    $0x1745d174,%eax
ja     12c0 <main+0x140>
lea    0xd73(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12c0 <main+0x140>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
mov    0x8(%r13),%rcx
lea    0xcf7(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1352 <main+0x1d2>
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xd1d(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd1d(%rip),%rdi
call   1040 <puts@plt>
mov    %r15d,%edi
call   1060 <close@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1357 <main+0x1d7>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [37 x i8] c"Usage: %s binary_file > output_file\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [31 x i8] c"%s: can't open %s for reading\0A\00"
@.str.2 = [36 x i8] c"static const unsigned char %s[] = {\00"
@.str.3 = [21 x i8] c"%s: file read error\0A\00"
@.str.4 = [3 x i8] c", \00"
@.str.5 = [3 x i8] c"\0A\09\00"
@.str.6 = [7 x i8] c"0x%.2x\00"
@.str.7 = [5 x i8] c"\0A};\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* @BUFSIZ
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %6
%18 = alloca i8, i64 %16
store i64 %16, i64* %7
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 2
br i1 %20, label %21, label %27
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %25)
store i32 -1, i32* %3
store i32 1, i32* %14
br label %101
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = load i32, i32* @O_RDONLY
%32 = call i32 @open(i8* %30, i32 %31)
store i32 %32, i32* %9
%33 = load i32, i32* %9
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %44
35: ; preds = %27
%36 = load i32, i32* @stderr
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %39, i8* %42)
store i32 -1, i32* %3
store i32 1, i32* %14
br label %101
44: ; preds = %27
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i8* @make_ident(i8* %47)
store i8* %48, i8** %8
%49 = load i8*, i8** %8
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %49)
store i32 0, i32* %11
store i32 0, i32* %13
br label %51
51: ; preds = %94, %44
%52 = load i32, i32* %9
%53 = load i32, i32* @BUFSIZ
%54 = call i32 @read(i32 %52, i8* %18, i32 %53)
store i32 %54, i32* %12
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %95
56: ; preds = %51
%57 = load i32, i32* %12
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %65
59: ; preds = %56
%60 = load i32, i32* @stderr
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 0
%63 = load i8*, i8** %62
%64 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %63)
store i32 -1, i32* %3
store i32 1, i32* %14
br label %101
65: ; preds = %56
store i32 0, i32* %10
br label %66
66: ; preds = %91, %65
%67 = load i32, i32* %10
%68 = load i32, i32* %12
%69 = icmp slt i32 %67, %68
br i1 %69, label %70, label %94
70: ; preds = %66
%71 = load i32, i32* %13
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %76
75: ; preds = %70
store i32 1, i32* %13
br label %76
76: ; preds = %75, %73
%77 = load i32, i32* %11
%78 = srem i32 %77, 11
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %76
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %82
82: ; preds = %80, %76
%83 = load i32, i32* %10
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %18, i64 %84
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %87)
%89 = load i32, i32* %11
%90 = add nsw i32 %89, 1
store i32 %90, i32* %11
br label %91
91: ; preds = %82
%92 = load i32, i32* %10
%93 = add nsw i32 %92, 1
store i32 %93, i32* %10
br label %66
94: ; preds = %66
br label %51
95: ; preds = %51
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%97 = load i32, i32* %9
%98 = call i32 @close(i32 %97)
%99 = load i8*, i8** %8
%100 = call i32 @free(i8* %99)
store i32 0, i32* %3
store i32 1, i32* %14
br label %101
101: ; preds = %95, %59, %35, %21
%102 = load i8*, i8** %6
%103 = load i32, i32* %3
ret i32 %103
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [37 x i8] c"Usage: %s binary_file > output_file\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [31 x i8] c"%s: can't open %s for reading\0A\00"
@.str.2 = [36 x i8] c"static const unsigned char %s[] = {\00"
@.str.3 = [21 x i8] c"%s: file read error\0A\00"
@.str.4 = [3 x i8] c", \00"
@.str.5 = [3 x i8] c"\0A\09\00"
@.str.6 = [7 x i8] c"0x%.2x\00"
@str = [4 x i8] c"\0A};\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %74
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %1
%20 = load i8*, i8** %12
%21 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20)
br label %74
22: ; preds = %11
%23 = load i8*, i8** %12
%24 = tail call i8* @make_ident(i8* %23)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %28
26: ; preds = %63, %45
%27 = add i32 %33, %29
br label %28
28: ; preds = %26, %22
%29 = phi i32 [ %27, %26 ], [ 0, %22 ]
%30 = phi i1 [ false, %26 ], [ true, %22 ]
br label %31
31: ; preds = %28, %34
%32 = load i32, i32* @BUFSIZ
%33 = call i32 @read(i32 %15, i8* %5, i32 %32)
switch i32 %33, label %34 [
i32 0, label %70
i32 -1, label %50
]
34: ; preds = %31
%35 = icmp sgt i32 %33, 0
br i1 %35, label %36, label %31
36: ; preds = %34
%37 = zext i32 %33 to i64
br i1 %30, label %40, label %38
38: ; preds = %36
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %38, %36
%41 = srem i32 %29, 11
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
%46 = load i8, i8* %5
%47 = zext i8 %46 to i32
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %47)
%49 = icmp eq i32 %33, 1
br i1 %49, label %26, label %54
50: ; preds = %31
%51 = load i32, i32* @stderr
%52 = load i8*, i8** %1
%53 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %52)
br label %74
54: ; preds = %45, %63
%55 = phi i64 [ %68, %63 ], [ 1, %45 ]
%56 = phi i32 [ %57, %63 ], [ %29, %45 ]
%57 = add nsw i32 %56, 1
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%59 = srem i32 %57, 11
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %54
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %63
63: ; preds = %61, %54
%64 = getelementptr inbounds i8, i8* %5, i64 %55
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %66)
%68 = add nuw nsw i64 %55, 1
%69 = icmp eq i64 %68, %37
br i1 %69, label %26, label %54
70: ; preds = %31
%71 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%72 = tail call i32 @close(i32 %15)
%73 = tail call i32 @free(i8* %24)
br label %74
74: ; preds = %70, %50, %17, %7
%75 = phi i32 [ -1, %7 ], [ -1, %17 ], [ -1, %50 ], [ 0, %70 ]
ret i32 %75
}