#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);
    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    1342 <bin2h+0x1b2>
mov    -0x18(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1228 <bin2h+0x98>
mov    -0x18(%rbp),%rsi
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1342 <bin2h+0x1b2>
mov    -0x38(%rbp),%rsi
lea    0xe01(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x38(%rbp),%rsi
lea    0xdf1(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x38(%rbp),%rsi
lea    0xe08(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x38(%rbp),%rsi
lea    0xdf8(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xde6(%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     12a0 <bin2h+0x110>
jmp    1320 <bin2h+0x190>
lea    -0x43(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1060 <memset@plt>
cmpl   $0x10,-0x40(%rbp)
jl     12d1 <bin2h+0x141>
mov    -0x38(%rbp),%rsi
lea    0xd96(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xd91(%rip),%rdi
call   1050 <fputs@plt>
lea    -0x43(%rbp),%rdi
lea    0xd84(%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    0xd68(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    127c <bin2h+0xec>
mov    -0x38(%rbp),%rsi
lea    0xd4d(%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     1297 <bin2h+0xe7>
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     12c6 <bin2h+0x116>
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
call   1030 <fclose@plt>
jmp    12b2 <bin2h+0x102>
lea    0xd64(%rip),%rdi
mov    %rbx,%rsi
jmp    12ad <bin2h+0xfd>
lea    0xd6f(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@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    0xda0(%rip),%rbp
jmp    134c <bin2h+0x19c>
nopw   0x0(%rax,%rax,1)
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 %76
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 %29
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)
store i32 -1, i32* %4
br label %76
29: ; preds = %21
%30 = load i32*, i32** %10
%31 = call i32 @fputs(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32* %30)
%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 ([2 x i8], [2 x i8]* @.str.5, 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 = load i8*, i8** %7
%40 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %29, %56
%42 = load i32*, i32** %9
%43 = call zeroext i8 @getc(i32* %42)
store i8 %43, i8* %11
%44 = load i32*, i32** %9
%45 = call i64 @feof(i32* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %41
br label %69
48: ; preds = %41
%49 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 0
%50 = call i32 @memset(i8* %49, i32 0, i32 2)
%51 = load i32, i32* %12
%52 = icmp sge i32 %51, 16
br i1 %52, label %53, label %56
53: ; preds = %48
%54 = load i32*, i32** %10
%55 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32* %54)
store i32 0, i32* %12
br label %56
56: ; preds = %53, %48
%57 = load i32*, i32** %10
%58 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %57)
%59 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 0
%60 = load i8, i8* %11
%61 = call i32 @sprintf(i8* %59, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8 zeroext %60)
%62 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 0
%63 = load i32*, i32** %10
%64 = call i32 @fputs(i8* %62, i32* %63)
%65 = load i32*, i32** %10
%66 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32* %65)
%67 = load i32, i32* %12
%68 = add nsw i32 %67, 1
store i32 %68, i32* %12
br label %41
69: ; preds = %47
%70 = load i32*, i32** %10
%71 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32* %70)
%72 = load i32*, i32** %9
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %10
%75 = call i32 @fclose(i32* %74)
br label %76
76: ; preds = %69, %26, %18
%77 = load i32, i32* %4
ret i32 %77
}

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 %45
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 %14
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)
br label %45
14: ; preds = %9
%15 = 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)
%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 i32 @fputc(i32 10, i32* %10)
%18 = tail call i32 @fputc(i32 10, i32* %10)
%19 = tail call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %2)
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%21 = call zeroext i8 @getc(i32* %5)
%22 = call i64 @feof(i32* %5)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %41
24: ; preds = %14, %31
%25 = phi i8 [ %38, %31 ], [ %21, %14 ]
%26 = phi i32 [ %37, %31 ], [ 0, %14 ]
%27 = call i32 @memset(i8* %20, i32 0, i32 2)
%28 = icmp sgt i32 %26, 15
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 @fputc(i32 10, i32* %10)
br label %31
31: ; preds = %24, %29
%32 = phi i32 [ 0, %29 ], [ %26, %24 ]
%33 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i64 2, i64 1, i32* %10)
%34 = call i32 @sprintf(i8* %20, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8 zeroext %25)
%35 = call i32 @fputs(i8* %20, i32* %10)
%36 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i64 2, i64 1, i32* %10)
%37 = add nsw i32 %32, 1
%38 = call zeroext i8 @getc(i32* %5)
%39 = call i64 @feof(i32* %5)
%40 = icmp eq i64 %39, 0
br i1 %40, label %24, label %41
41: ; preds = %31, %14
%42 = call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i64 4, i64 1, i32* %10)
%43 = call i32 @fclose(i32* %5)
%44 = call i32 @fclose(i32* %10)
br label %45
45: ; preds = %41, %12, %7
ret i32 -1
}