#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 *);
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) {
  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, "w");
  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;
    }
    fputs("0x", outfile);
    sprintf(cc, "%02x", c);
    fputs(cc, outfile);
    fputs(", ", outfile);
    i++;
  }
  fputs("} ;\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)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11ed <bin2h+0x5d>
mov    -0x10(%rbp),%rsi
lea    0xe26(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    134b <bin2h+0x1bb>
mov    -0x18(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1231 <bin2h+0xa1>
mov    -0x18(%rbp),%rsi
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    134b <bin2h+0x1bb>
mov    -0x38(%rbp),%rsi
lea    0xdf8(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x38(%rbp),%rsi
lea    0xde8(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x38(%rbp),%rsi
lea    0xdff(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x38(%rbp),%rsi
lea    0xdef(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xddd(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   10b0 <getc@plt>
mov    %al,-0x39(%rbp)
mov    -0x30(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     12a9 <bin2h+0x119>
jmp    1329 <bin2h+0x199>
lea    -0x43(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1060 <memset@plt>
cmpl   $0x10,-0x40(%rbp)
jl     12da <bin2h+0x14a>
mov    -0x38(%rbp),%rsi
lea    0xd8d(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xd88(%rip),%rdi
call   1050 <fputs@plt>
lea    -0x43(%rbp),%rdi
lea    0xd7b(%rip),%rsi
movzbl -0x39(%rbp),%edx
call   10a0 <sprintf@plt>
lea    -0x43(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x38(%rbp),%rsi
lea    0xd5f(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1285 <bin2h+0xf5>
mov    -0x38(%rbp),%rsi
lea    0xd44(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x38(%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    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xe35(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1292 <bin2h+0xe2>
mov    %rax,%r14
lea    0xe34(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12a3 <bin2h+0xf3>
mov    %rax,%rbx
lea    0xe36(%rip),%rbp
mov    $0x28,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %rax,%rcx
call   10c0 <fwrite@plt>
mov    $0x28,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
lea    0xe14(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1080 <fprintf@plt>
mov    %r14,%rdi
call   10d0 <getc@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1090 <feof@plt>
test   %rax,%rax
je     12ce <bin2h+0x11e>
lea    0xe05(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
jmp    12b5 <bin2h+0x105>
lea    0xd69(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
jmp    12ba <bin2h+0x10a>
lea    0xd6f(%rip),%rdi
mov    %rbp,%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    %r13d,%r13d
lea    0x5(%rsp),%r15
lea    0xd98(%rip),%rbp
jmp    134c <bin2h+0x19c>
nop
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xd7c(%rip),%rdi
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
movzbl %r12b,%edx
mov    %r15,%rdi
lea    0xd69(%rip),%rsi
call   10b0 <sprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
add    $0x1,%r13d
mov    %r14,%rdi
call   10d0 <getc@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1090 <feof@plt>
test   %rax,%rax
jne    126c <bin2h+0xbc>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1060 <memset@plt>
cmp    $0x10,%r13d
jl     12e0 <bin2h+0x130>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
xor    %r13d,%r13d
jmp    12e0 <bin2h+0x130>

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

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