#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
unsigned char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int bin2h(char *infname, char *outfname, char *fw_name, const char *mode) {
  int ret = 0;
  FILE *infile, *outfile;
  unsigned char c;
  int i = 0;
  infile = fopen(infname, "r");
  if (infile == (FILE *)NULL) {
    printf("Can't read file %s\n", infname);
    return -1;
  }
  outfile = fopen(outfname, mode);
  if (outfile == (FILE *)NULL) {
    printf("Can't open write file %s\n", outfname);
    fclose(infile);
    return -1;
  }
  fputs("/* AUTO GEN PLEASE DO NOT MODIFY IT */\n", outfile);
  fputs("/* AUTO GEN PLEASE DO NOT MODIFY IT */\n", outfile);
  fputs("\n", outfile);
  fputs("\n", outfile);
  fprintf(outfile, "UCHAR %s[] = {\n", fw_name);
  while (1) {
    char cc[3];
    c = getc(infile);
    if (feof(infile))
      break;
    memset(cc, 0, 2);
    if (i >= 16) {
      fputs("\n", outfile);
      i = 0;
    }
    if (i == 0)
      fputs("\t", outfile);
    else if (i < 16)
      fputs(" ", outfile);
    fputs("0x", outfile);
    sprintf(cc, "%02x", c);
    fputs(cc, outfile);
    fputs(",", outfile);
    i++;
  }
  fputs("\n};\n", outfile);
  fclose(infile);
  fclose(outfile);
}


x86 assembly (clang, -O0):
<bin2h>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11f1 <bin2h+0x61>
mov    -0x10(%rbp),%rsi
lea    0xe22(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138a <bin2h+0x1fa>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1232 <bin2h+0xa2>
mov    -0x18(%rbp),%rsi
lea    0xdfe(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138a <bin2h+0x1fa>
mov    -0x40(%rbp),%rsi
lea    0xdf3(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x40(%rbp),%rsi
lea    0xde3(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x40(%rbp),%rsi
lea    0xdf9(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x40(%rbp),%rsi
lea    0xde9(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdd7(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   10b0 <getc@plt>
mov    %al,-0x41(%rbp)
mov    -0x38(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     12aa <bin2h+0x11a>
jmp    1368 <bin2h+0x1d8>
lea    -0x4b(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1060 <memset@plt>
cmpl   $0x10,-0x48(%rbp)
jl     12db <bin2h+0x14b>
mov    -0x40(%rbp),%rsi
lea    0xd87(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x0,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jne    12fa <bin2h+0x16a>
mov    -0x40(%rbp),%rsi
lea    0xd78(%rip),%rdi
call   1050 <fputs@plt>
jmp    1319 <bin2h+0x189>
cmpl   $0x10,-0x48(%rbp)
jge    1314 <bin2h+0x184>
mov    -0x40(%rbp),%rsi
lea    0xd5b(%rip),%rdi
call   1050 <fputs@plt>
jmp    1319 <bin2h+0x189>
mov    -0x40(%rbp),%rsi
lea    0xd48(%rip),%rdi
call   1050 <fputs@plt>
lea    -0x4b(%rbp),%rdi
lea    0xd3b(%rip),%rsi
movzbl -0x41(%rbp),%edx
call   10a0 <sprintf@plt>
lea    -0x4b(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x40(%rbp),%rsi
lea    0xd1f(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1286 <bin2h+0xf6>
mov    -0x40(%rbp),%rsi
lea    0xd03(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin2h>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbp
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0xe32(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1290 <bin2h+0xe0>
mov    %rax,%r14
mov    %r12,%rdi
mov    %rbp,%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12a1 <bin2h+0xf1>
mov    %rax,%rbp
lea    0xe33(%rip),%rbx
mov    $0x27,%esi
mov    $0x1,%edx
mov    %rbx,%rdi
mov    %rax,%rcx
call   10c0 <fwrite@plt>
mov    $0x27,%esi
mov    $0x1,%edx
mov    %rbx,%rdi
mov    %rbp,%rcx
call   10c0 <fwrite@plt>
mov    $0xa,%edi
mov    %rbp,%rsi
call   1070 <fputc@plt>
mov    $0xa,%edi
mov    %rbp,%rsi
call   1070 <fputc@plt>
lea    0xe10(%rip),%rsi
mov    %rbp,%rdi
mov    %r15,%rdx
call   1080 <fprintf@plt>
mov    %r14,%rdi
call   10d0 <getc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1090 <feof@plt>
test   %rax,%rax
je     12cc <bin2h+0x11c>
lea    0xdff(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   10c0 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbp,%rdi
jmp    12b3 <bin2h+0x103>
lea    0xd6b(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
jmp    12b8 <bin2h+0x108>
lea    0xd6e(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r12d,%r12d
lea    0x5(%rsp),%r15
lea    0xd90(%rip),%r13
jmp    1356 <bin2h+0x1a6>
nopl   (%rax)
test   %r12d,%r12d
mov    $0x20,%edi
mov    $0x9,%eax
cmove  %eax,%edi
mov    %rbp,%rsi
call   1070 <fputc@plt>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xd5f(%rip),%rdi
mov    %rbp,%rcx
call   10c0 <fwrite@plt>
movzbl %bl,%edx
mov    %r15,%rdi
mov    %r13,%rsi
call   10b0 <sprintf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1050 <fputs@plt>
mov    $0x2c,%edi
mov    %rbp,%rsi
call   1070 <fputc@plt>
add    $0x1,%r12d
mov    %r14,%rdi
call   10d0 <getc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1090 <feof@plt>
test   %rax,%rax
jne    126a <bin2h+0xba>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1060 <memset@plt>
cmp    $0x10,%r12d
jl     12e0 <bin2h+0x130>
mov    $0xa,%edi
mov    %rbp,%rsi
call   1070 <fputc@plt>
xor    %r12d,%r12d
mov    $0x9,%edi
jmp    12f0 <bin2h+0x140>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [20 x i8] c"Can't read file %s\0A\00"
@.str.2 = [26 x i8] c"Can't open write file %s\0A\00"
@.str.3 = [40 x i8] c"/* AUTO GEN PLEASE DO NOT MODIFY IT */\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [16 x i8] c"UCHAR %s[] = {\0A\00"
@.str.6 = [2 x i8] c"\09\00"
@.str.7 = [2 x i8] c" \00"
@.str.8 = [3 x i8] c"0x\00"
@.str.9 = [5 x i8] c"%02x\00"
@.str.10 = [2 x i8] c",\00"
@.str.11 = [5 x i8] c"\0A};\0A\00"
define i32 @bin2h(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i8
%14 = alloca i32
%15 = alloca [3 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 0, i32* %10
store i32 0, i32* %14
%16 = load i8*, i8** %6
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %11
%18 = load i32*, i32** %11
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %4
%21 = load i8*, i8** %6
%22 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %21)
store i32 -1, i32* %5
br label %94
23: ; preds = %4
%24 = load i8*, i8** %7
%25 = load i8*, i8** %9
%26 = call i32* @fopen(i8* %24, i8* %25)
store i32* %26, i32** %12
%27 = load i32*, i32** %12
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %34
29: ; preds = %23
%30 = load i8*, i8** %7
%31 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = load i32*, i32** %11
%33 = call i32 @fclose(i32* %32)
store i32 -1, i32* %5
br label %94
34: ; preds = %23
%35 = load i32*, i32** %12
%36 = call i32 @fputs(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32* %35)
%37 = load i32*, i32** %12
%38 = call i32 @fputs(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32* %37)
%39 = load i32*, i32** %12
%40 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32* %39)
%41 = load i32*, i32** %12
%42 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32* %41)
%43 = load i32*, i32** %12
%44 = load i8*, i8** %8
%45 = call i32 @fprintf(i32* %43, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %34, %74
%47 = load i32*, i32** %11
%48 = call zeroext i8 @getc(i32* %47)
store i8 %48, i8* %13
%49 = load i32*, i32** %11
%50 = call i64 @feof(i32* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %46
br label %87
53: ; preds = %46
%54 = getelementptr inbounds [3 x i8], [3 x i8]* %15, i64 0, i64 0
%55 = call i32 @memset(i8* %54, i32 0, i32 2)
%56 = load i32, i32* %14
%57 = icmp sge i32 %56, 16
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = load i32*, i32** %12
%60 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32* %59)
store i32 0, i32* %14
br label %61
61: ; preds = %58, %53
%62 = load i32, i32* %14
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32*, i32** %12
%66 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32* %65)
br label %74
67: ; preds = %61
%68 = load i32, i32* %14
%69 = icmp slt i32 %68, 16
br i1 %69, label %70, label %73
70: ; preds = %67
%71 = load i32*, i32** %12
%72 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32* %71)
br label %73
73: ; preds = %70, %67
br label %74
74: ; preds = %73, %64
%75 = load i32*, i32** %12
%76 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %75)
%77 = getelementptr inbounds [3 x i8], [3 x i8]* %15, i64 0, i64 0
%78 = load i8, i8* %13
%79 = call i32 @sprintf(i8* %77, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8 zeroext %78)
%80 = getelementptr inbounds [3 x i8], [3 x i8]* %15, i64 0, i64 0
%81 = load i32*, i32** %12
%82 = call i32 @fputs(i8* %80, i32* %81)
%83 = load i32*, i32** %12
%84 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i32* %83)
%85 = load i32, i32* %14
%86 = add nsw i32 %85, 1
store i32 %86, i32* %14
br label %46
87: ; preds = %52
%88 = load i32*, i32** %12
%89 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32* %88)
%90 = load i32*, i32** %11
%91 = call i32 @fclose(i32* %90)
%92 = load i32*, i32** %12
%93 = call i32 @fclose(i32* %92)
br label %94
94: ; preds = %87, %29, %20
%95 = load i32, i32* %5
ret i32 %95
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [20 x i8] c"Can't read file %s\0A\00"
@.str.2 = [26 x i8] c"Can't open write file %s\0A\00"
@.str.3 = [40 x i8] c"/* AUTO GEN PLEASE DO NOT MODIFY IT */\0A\00"
@.str.5 = [16 x i8] c"UCHAR %s[] = {\0A\00"
@.str.8 = [3 x i8] c"0x\00"
@.str.9 = [5 x i8] c"%02x\00"
@.str.11 = [5 x i8] c"\0A};\0A\00"
define i32 @bin2h(i8* %0, i8* %1, i8* %2, i8* nocapture %3) {
%5 = alloca [3 x i8]
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %52
10: ; preds = %4
%11 = tail call i32* @fopen(i8* %1, i8* %3)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%15 = tail call i32 @fclose(i32* %6)
br label %52
16: ; preds = %10
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i64 39, i64 1, i32* %11)
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i64 39, i64 1, i32* %11)
%19 = tail call i32 @fputc(i32 10, i32* %11)
%20 = tail call i32 @fputc(i32 10, i32* %11)
%21 = tail call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%23 = call zeroext i8 @getc(i32* %6)
%24 = call i64 @feof(i32* %6)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %48
26: ; preds = %16, %36
%27 = phi i8 [ %45, %36 ], [ %23, %16 ]
%28 = phi i32 [ %44, %36 ], [ 0, %16 ]
%29 = call i32 @memset(i8* %22, i32 0, i32 2)
%30 = icmp sgt i32 %28, 15
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @fputc(i32 10, i32* %11)
br label %36
33: ; preds = %26
%34 = icmp eq i32 %28, 0
%35 = select i1 %34, i32 9, i32 32
br label %36
36: ; preds = %33, %31
%37 = phi i32 [ 9, %31 ], [ %35, %33 ]
%38 = phi i32 [ 0, %31 ], [ %28, %33 ]
%39 = call i32 @fputc(i32 %37, i32* %11)
%40 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i64 2, i64 1, i32* %11)
%41 = call i32 @sprintf(i8* %22, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8 zeroext %27)
%42 = call i32 @fputs(i8* %22, i32* %11)
%43 = call i32 @fputc(i32 44, i32* %11)
%44 = add nsw i32 %38, 1
%45 = call zeroext i8 @getc(i32* %6)
%46 = call i64 @feof(i32* %6)
%47 = icmp eq i64 %46, 0
br i1 %47, label %26, label %48
48: ; preds = %36, %16
%49 = call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i64 4, i64 1, i32* %11)
%50 = call i32 @fclose(i32* %6)
%51 = call i32 @fclose(i32* %11)
br label %52
52: ; preds = %48, %13, %8
ret i32 -1
}