#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char *);
int main(int argc, const char *argv[]) {
  const char *varname;
  int i = 0;
  int c;
  int id = 0;
  if (argv[1] && strcmp(argv[1], "-i") == 0) {
    argv++;
    argc--;
    id = 1;
  }
  if (argc == 1) {
    fprintf(stderr, "bin2hex: [-i] firmware\n");
    exit(1);
  }
  varname = argv[1];
  printf("/* automatically generated by bin2hex */\n");
  printf("static unsigned char %s [] %s =\n{\n", varname,
         id ? "__initdata" : "");
  while ((c = getchar()) != EOF) {
    if (i != 0 && i % 10 == 0) {
      printf("\n");
    }
    printf("0x%02lx,", c & 0xFFl);
    i++;
  }
  printf("};\nstatic int %sLen =  %d;\n", varname, i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11bd <main+0x6d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11bd <main+0x6d>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11e6 <main+0x96>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%ecx
lea    0xe36(%rip),%rdx
lea    0xe53(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x20(%rbp)
mov    0x2dad(%rip),%rcx
cmp    (%rcx),%eax
je     1296 <main+0x146>
cmpl   $0x0,-0x1c(%rbp)
je     126f <main+0x11f>
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    126f <main+0x11f>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x20(%rbp),%rsi
and    $0xff,%rsi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    122a <main+0xda>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%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,%rbp
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
lea    0xee2(%rip),%r15
test   %rdi,%rdi
je     11af <main+0x3f>
lea    0xe69(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11af <main+0x3f>
add    $0x8,%rbp
add    $0xffffffff,%ebx
lea    0xe8f(%rip),%r15
cmp    $0x1,%ebx
je     1283 <main+0x113>
mov    0x8(%rbp),%r14
lea    0xeab(%rip),%rdi
call   1040 <puts@plt>
lea    0xe4c(%rip),%rdi
xor    %ebp,%ebp
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2dfc(%rip),%r12
cmp    (%r12),%eax
je     125f <main+0xef>
mov    %eax,%ebx
mov    %r14,(%rsp)
mov    $0xcccccccd,%r13d
lea    0xe44(%rip),%r15
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    1233 <main+0xc3>
nopl   0x0(%rax)
movzbl %bl,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r14d
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%ebx
add    $0xffffffff,%ebp
cmp    (%r12),%eax
je     1259 <main+0xe9>
test   %ebp,%ebp
je     1210 <main+0xa0>
mov    %r14d,%eax
imul   %r13,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
neg    %eax
cmp    %ebp,%eax
jne    1210 <main+0xa0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1210 <main+0xa0>
neg    %ebp
mov    (%rsp),%r14
lea    0xdec(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
lea    0xd70(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"-i\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"bin2hex: [-i] firmware\0A\00"
@.str.2 = [42 x i8] c"/* automatically generated by bin2hex */\0A\00"
@.str.3 = [35 x i8] c"static unsigned char %s [] %s =\0A{\0A\00"
@.str.4 = [11 x i8] c"__initdata\00"
@.str.5 = [1 x i8] zeroinitializer
@EOF = global i32 0
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [9 x i8] c"0x%02lx,\00"
@.str.8 = [28 x i8] c"};\0Astatic int %sLen = %d;\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %9
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %25
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i32 1
store i8** %22, i8*** %5
%23 = load i32, i32* %4
%24 = add nsw i32 %23, -1
store i32 %24, i32* %4
store i32 1, i32* %9
br label %25
25: ; preds = %20, %14, %2
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %25
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
store i8* %35, i8** %6
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%37 = load i8*, i8** %6
%38 = load i32, i32* %9
%39 = icmp ne i32 %38, 0
%40 = zext i1 %39 to i64
%41 = select i1 %39, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %37, i8* %41)
br label %43
43: ; preds = %56, %32
%44 = call i32 (...) @getchar()
store i32 %44, i32* %8
%45 = load i32, i32* @EOF
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %63
47: ; preds = %43
%48 = load i32, i32* %7
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %47
%51 = load i32, i32* %7
%52 = srem i32 %51, 10
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %56
56: ; preds = %54, %50, %47
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = and i64 %58, 255
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i64 %59)
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %43
63: ; preds = %43
%64 = load i8*, i8** %6
%65 = load i32, i32* %7
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %64, i32 %65)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"-i\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"bin2hex: [-i] firmware\0A\00"
@.str.3 = [35 x i8] c"static unsigned char %s [] %s =\0A{\0A\00"
@.str.4 = [11 x i8] c"__initdata\00"
@.str.5 = [1 x i8] zeroinitializer
@EOF = global i32 0
@.str.7 = [9 x i8] c"0x%02lx,\00"
@.str.8 = [28 x i8] c"};\0Astatic int %sLen = %d;\0A\00"
@str = [41 x i8] c"/* automatically generated by bin2hex */\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = add nsw i32 %0, -1
br label %11
11: ; preds = %9, %6, %2
%12 = phi i8** [ %3, %9 ], [ %1, %6 ], [ %1, %2 ]
%13 = phi i32 [ %10, %9 ], [ %0, %6 ], [ %0, %2 ]
%14 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), %9 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), %6 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), %2 ]
%15 = icmp eq i32 %13, 1
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %11
%21 = getelementptr inbounds i8*, i8** %12, i64 1
%22 = load i8*, i8** %21
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %22, i8* %14)
%25 = tail call i32 (...) @getchar()
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %45, label %28
28: ; preds = %20, %37
%29 = phi i32 [ %42, %37 ], [ %25, %20 ]
%30 = phi i32 [ %41, %37 ], [ 0, %20 ]
%31 = icmp ne i32 %30, 0
%32 = urem i32 %30, 10
%33 = icmp eq i32 %32, 0
%34 = and i1 %31, %33
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = tail call i32 @putchar(i32 10)
br label %37
37: ; preds = %35, %28
%38 = and i32 %29, 255
%39 = zext i32 %38 to i64
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i64 %39)
%41 = add nuw nsw i32 %30, 1
%42 = tail call i32 (...) @getchar()
%43 = load i32, i32* @EOF
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %28
45: ; preds = %37, %20
%46 = phi i32 [ 0, %20 ], [ %41, %37 ]
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %22, i32 %46)
ret i32 0
}