#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
unsigned char getc(int /*<<< orphan*/ *);
scalar_t__ getenv(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char *argv[]) {
  FILE *infile, *outfile;
  char infname[1024];
  char outfname[1024];
  char *rt28xxdir;
  char *chipset;
  int i = 0;
  unsigned char c;
  memset(infname, 0, 1024);
  memset(outfname, 0, 1024);
  rt28xxdir = (char *)getenv("RT28xx_DIR");
  chipset = (char *)getenv("CHIPSET");
  if (!rt28xxdir) {
    printf("Environment value \"RT28xx_DIR\" not export \n");
    return -1;
  }
  if (!chipset) {
    printf("Environment value \"CHIPSET\" not export \n");
    return -1;
  }
  strcat(infname, rt28xxdir);
  if (strncmp(chipset, "2860", 4) == 0)
    strcat(infname, "/common/rt2860.bin");
  else if (strncmp(chipset, "2870", 4) == 0)
    strcat(infname, "/common/rt2870.bin");
  else if (strncmp(chipset, "3090", 4) == 0)
    strcat(infname, "/common/rt2860.bin");
  else if (strncmp(chipset, "2070", 4) == 0)
    strcat(infname, "/common/rt2870.bin");
  else if (strncmp(chipset, "3070", 4) == 0)
    strcat(infname, "/common/rt2870.bin");
  else if (strncmp(chipset, "3572", 4) == 0)
    strcat(infname, "/common/rt2870.bin");
  else if (strncmp(chipset, "3370", 4) == 0)
    strcat(infname, "/common/rt2870.bin");
  else if (strncmp(chipset, "USB_COMBO", 9) == 0)
    strcat(infname, "/common/rt2870.bin");
  else
    strcat(infname, "/common/rt2860.bin");
  strcat(outfname, rt28xxdir);
  strcat(outfname, "/include/firmware.h");
  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);
  fputs("UCHAR FirmwareImage [] = { \n", outfile);
  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);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x834(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
lea    0xdf0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x828(%rbp)
lea    0xde8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x830(%rbp)
cmpq   $0x0,-0x828(%rbp)
jne    1257 <main+0x97>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    167c <main+0x4bc>
cmpq   $0x0,-0x830(%rbp)
jne    127f <main+0xbf>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    167c <main+0x4bc>
lea    -0x420(%rbp),%rdi
mov    -0x828(%rbp),%rsi
call   10b0 <strcat@plt>
mov    -0x830(%rbp),%rdi
lea    0xdc8(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12cc <main+0x10c>
lea    -0x420(%rbp),%rdi
lea    0xdab(%rip),%rsi
call   10b0 <strcat@plt>
jmp    1498 <main+0x2d8>
mov    -0x830(%rbp),%rdi
lea    0xda6(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1306 <main+0x146>
lea    -0x420(%rbp),%rdi
lea    0xd89(%rip),%rsi
call   10b0 <strcat@plt>
jmp    1493 <main+0x2d3>
mov    -0x830(%rbp),%rdi
lea    0xd84(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1340 <main+0x180>
lea    -0x420(%rbp),%rdi
lea    0xd37(%rip),%rsi
call   10b0 <strcat@plt>
jmp    148e <main+0x2ce>
mov    -0x830(%rbp),%rdi
lea    0xd4f(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    137a <main+0x1ba>
lea    -0x420(%rbp),%rdi
lea    0xd15(%rip),%rsi
call   10b0 <strcat@plt>
jmp    1489 <main+0x2c9>
mov    -0x830(%rbp),%rdi
lea    0xd1a(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    13b4 <main+0x1f4>
lea    -0x420(%rbp),%rdi
lea    0xcdb(%rip),%rsi
call   10b0 <strcat@plt>
jmp    1484 <main+0x2c4>
mov    -0x830(%rbp),%rdi
lea    0xce5(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    13ee <main+0x22e>
lea    -0x420(%rbp),%rdi
lea    0xca1(%rip),%rsi
call   10b0 <strcat@plt>
jmp    147f <main+0x2bf>
mov    -0x830(%rbp),%rdi
lea    0xcb0(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1428 <main+0x268>
lea    -0x420(%rbp),%rdi
lea    0xc67(%rip),%rsi
call   10b0 <strcat@plt>
jmp    147a <main+0x2ba>
mov    -0x830(%rbp),%rdi
lea    0xc7b(%rip),%rsi
mov    $0x9,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1462 <main+0x2a2>
lea    -0x420(%rbp),%rdi
lea    0xc2d(%rip),%rsi
call   10b0 <strcat@plt>
jmp    1475 <main+0x2b5>
lea    -0x420(%rbp),%rdi
lea    0xbfd(%rip),%rsi
call   10b0 <strcat@plt>
jmp    147a <main+0x2ba>
jmp    147f <main+0x2bf>
jmp    1484 <main+0x2c4>
jmp    1489 <main+0x2c9>
jmp    148e <main+0x2ce>
jmp    1493 <main+0x2d3>
jmp    1498 <main+0x2d8>
lea    -0x820(%rbp),%rdi
mov    -0x828(%rbp),%rsi
call   10b0 <strcat@plt>
lea    -0x820(%rbp),%rdi
lea    0xc02(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0x420(%rbp),%rdi
lea    0xc03(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1501 <main+0x341>
lea    -0x420(%rbp),%rsi
lea    0xbe3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    167c <main+0x4bc>
lea    -0x820(%rbp),%rdi
lea    0xbd7(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1544 <main+0x384>
lea    -0x820(%rbp),%rsi
lea    0xbb7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    167c <main+0x4bc>
mov    -0x20(%rbp),%rsi
lea    0xbb4(%rip),%rdi
call   1070 <fputs@plt>
mov    -0x20(%rbp),%rsi
lea    0xba4(%rip),%rdi
call   1070 <fputs@plt>
mov    -0x20(%rbp),%rsi
lea    0xbbb(%rip),%rdi
call   1070 <fputs@plt>
mov    -0x20(%rbp),%rsi
lea    0xbab(%rip),%rdi
call   1070 <fputs@plt>
mov    -0x20(%rbp),%rsi
lea    0xb9d(%rip),%rdi
call   1070 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   10e0 <getc@plt>
mov    %al,-0x835(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%rax
je     15bb <main+0x3fb>
jmp    1653 <main+0x493>
lea    -0x838(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1080 <memset@plt>
cmpl   $0x10,-0x834(%rbp)
jl     15f5 <main+0x435>
mov    -0x20(%rbp),%rsi
lea    0xb44(%rip),%rdi
call   1070 <fputs@plt>
movl   $0x0,-0x834(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xb49(%rip),%rdi
call   1070 <fputs@plt>
lea    -0x838(%rbp),%rdi
lea    0xb39(%rip),%rsi
movzbl -0x835(%rbp),%edx
call   10c0 <sprintf@plt>
lea    -0x838(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <fputs@plt>
mov    -0x20(%rbp),%rsi
lea    0xb17(%rip),%rdi
call   1070 <fputs@plt>
mov    -0x834(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x834(%rbp)
jmp    1594 <main+0x3d4>
mov    -0x20(%rbp),%rsi
lea    0xaf6(%rip),%rdi
call   1070 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
lea    0x410(%rsp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
lea    0xdd3(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
lea    0xdcf(%rip),%rdi
call   1030 <getenv@plt>
test   %r14,%r14
je     1361 <main+0x171>
mov    %rax,%rbx
test   %rax,%rax
je     136a <main+0x17a>
lea    0x410(%rsp),%rdi
mov    %r14,%rsi
call   10d0 <strcat@plt>
lea    0xda6(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
lea    0xd97(%rip),%rbp
test   %rax,%rax
je     137e <main+0x18e>
lea    0xd9a(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
lea    0xd8b(%rip),%r15
test   %rax,%rax
je     137b <main+0x18b>
lea    0xd8e(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     137e <main+0x18e>
lea    0xd76(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     137b <main+0x18b>
lea    0xd5e(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     137b <main+0x18b>
lea    0xd4a(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     137b <main+0x18b>
lea    0xd36(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
mov    %r15,%rbp
test   %rax,%rax
je     137e <main+0x18e>
lea    0xd1f(%rip),%rsi
mov    %rbx,%rdi
mov    $0x9,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
lea    0xcdc(%rip),%rax
lea    0xcbd(%rip),%rbp
cmove  %rax,%rbp
jmp    137e <main+0x18e>
lea    0xd9c(%rip),%rdi
jmp    1371 <main+0x181>
lea    0xdbe(%rip),%rdi
call   1050 <puts@plt>
jmp    1401 <main+0x211>
mov    %r15,%rbp
lea    0x410(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10d0 <strcat@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   10d0 <strcat@plt>
lea    0xcbe(%rip),%rsi
mov    %rbp,%rdi
call   10d0 <strcat@plt>
lea    0xcc3(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     13eb <main+0x1fb>
mov    %rax,%rbx
lea    0xcc3(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
jne    1418 <main+0x228>
lea    0xcaf(%rip),%rdi
lea    0x10(%rsp),%rsi
jmp    13fa <main+0x20a>
lea    0xc8a(%rip),%rdi
lea    0x410(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rax,%r14
lea    0xc8c(%rip),%rbp
mov    $0x28,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %rax,%rcx
call   1100 <fwrite@plt>
mov    $0x28,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %r14,%rcx
call   1100 <fwrite@plt>
mov    $0xa,%edi
mov    %r14,%rsi
call   10a0 <fputc@plt>
mov    $0xa,%edi
mov    %r14,%rsi
call   10a0 <fputc@plt>
lea    0xc6a(%rip),%rdi
mov    $0x1c,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1100 <fwrite@plt>
mov    %rbx,%rdi
call   1110 <getc@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %rax,%rax
jne    153e <main+0x34e>
xor    %r13d,%r13d
lea    0xd(%rsp),%r15
lea    0xc52(%rip),%rbp
jmp    1514 <main+0x324>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xc37(%rip),%rdi
mov    %r14,%rcx
call   1100 <fwrite@plt>
movzbl %r12b,%edx
mov    %r15,%rdi
lea    0xc24(%rip),%rsi
call   10e0 <sprintf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <fputs@plt>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %r14,%rcx
call   1100 <fwrite@plt>
add    $0x1,%r13d
mov    %rbx,%rdi
call   1110 <getc@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %rax,%rax
jne    153e <main+0x34e>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1090 <memset@plt>
cmp    $0x10,%r13d
jl     14ac <main+0x2bc>
mov    $0xa,%edi
mov    %r14,%rsi
call   10a0 <fputc@plt>
xor    %r13d,%r13d
jmp    14ac <main+0x2bc>
lea    0xbba(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1100 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"RT28xx_DIR\00"
@.str.1 = [8 x i8] c"CHIPSET\00"
@.str.2 = [44 x i8] c"Environment value \22RT28xx_DIR\22 not export \0A\00"
@.str.3 = [41 x i8] c"Environment value \22CHIPSET\22 not export \0A\00"
@.str.4 = [5 x i8] c"2860\00"
@.str.5 = [19 x i8] c"/common/rt2860.bin\00"
@.str.6 = [5 x i8] c"2870\00"
@.str.7 = [19 x i8] c"/common/rt2870.bin\00"
@.str.8 = [5 x i8] c"3090\00"
@.str.9 = [5 x i8] c"2070\00"
@.str.10 = [5 x i8] c"3070\00"
@.str.11 = [5 x i8] c"3572\00"
@.str.12 = [5 x i8] c"3370\00"
@.str.13 = [10 x i8] c"USB_COMBO\00"
@.str.14 = [20 x i8] c"/include/firmware.h\00"
@.str.15 = [2 x i8] c"r\00"
@.str.16 = [21 x i8] c"Can't read file %s \0A\00"
@.str.17 = [2 x i8] c"w\00"
@.str.18 = [27 x i8] c"Can't open write file %s \0A\00"
@.str.19 = [41 x i8] c"/* AUTO GEN PLEASE DO NOT MODIFY IT */ \0A\00"
@.str.20 = [2 x i8] c"\0A\00"
@.str.21 = [29 x i8] c"UCHAR FirmwareImage [] = { \0A\00"
@.str.22 = [3 x i8] c"0x\00"
@.str.23 = [5 x i8] c"%02x\00"
@.str.24 = [3 x i8] c", \00"
@.str.25 = [5 x i8] c"} ;\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8
%14 = alloca [3 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %12
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 1024)
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 1024)
%19 = call i64 @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %10
%21 = call i64 @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %11
%23 = load i8*, i8** %10
%24 = icmp ne i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %169
27: ; preds = %2
%28 = load i8*, i8** %11
%29 = icmp ne i8* %28, null
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %169
32: ; preds = %27
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%34 = load i8*, i8** %10
%35 = call i32 @strcat(i8* %33, i8* %34)
%36 = load i8*, i8** %11
%37 = call i64 @strncmp(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %32
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%41 = call i32 @strcat(i8* %40, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %101
42: ; preds = %32
%43 = load i8*, i8** %11
%44 = call i64 @strncmp(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%48 = call i32 @strcat(i8* %47, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %100
49: ; preds = %42
%50 = load i8*, i8** %11
%51 = call i64 @strncmp(i8* %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 4)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%55 = call i32 @strcat(i8* %54, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %99
56: ; preds = %49
%57 = load i8*, i8** %11
%58 = call i64 @strncmp(i8* %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 4)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %56
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%62 = call i32 @strcat(i8* %61, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %98
63: ; preds = %56
%64 = load i8*, i8** %11
%65 = call i64 @strncmp(i8* %64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 4)
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%69 = call i32 @strcat(i8* %68, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %97
70: ; preds = %63
%71 = load i8*, i8** %11
%72 = call i64 @strncmp(i8* %71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32 4)
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %70
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%76 = call i32 @strcat(i8* %75, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %96
77: ; preds = %70
%78 = load i8*, i8** %11
%79 = call i64 @strncmp(i8* %78, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i32 4)
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %77
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%83 = call i32 @strcat(i8* %82, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %95
84: ; preds = %77
%85 = load i8*, i8** %11
%86 = call i64 @strncmp(i8* %85, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i32 9)
%87 = icmp eq i64 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %84
%89 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%90 = call i32 @strcat(i8* %89, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %94
91: ; preds = %84
%92 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%93 = call i32 @strcat(i8* %92, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %94
94: ; preds = %91, %88
br label %95
95: ; preds = %94, %81
br label %96
96: ; preds = %95, %74
br label %97
97: ; preds = %96, %67
br label %98
98: ; preds = %97, %60
br label %99
99: ; preds = %98, %53
br label %100
100: ; preds = %99, %46
br label %101
101: ; preds = %100, %39
%102 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%103 = load i8*, i8** %10
%104 = call i32 @strcat(i8* %102, i8* %103)
%105 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%106 = call i32 @strcat(i8* %105, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0))
%107 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%108 = call i32* @fopen(i8* %107, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
store i32* %108, i32** %6
%109 = load i32*, i32** %6
%110 = icmp eq i32* %109, null
br i1 %110, label %111, label %114
111: ; preds = %101
%112 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.16, i64 0, i64 0), i8* %112)
store i32 -1, i32* %3
br label %169
114: ; preds = %101
%115 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%116 = call i32* @fopen(i8* %115, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
store i32* %116, i32** %7
%117 = load i32*, i32** %7
%118 = icmp eq i32* %117, null
br i1 %118, label %119, label %122
119: ; preds = %114
%120 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.18, i64 0, i64 0), i8* %120)
store i32 -1, i32* %3
br label %169
122: ; preds = %114
%123 = load i32*, i32** %7
%124 = call i32 @fputs(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.19, i64 0, i64 0), i32* %123)
%125 = load i32*, i32** %7
%126 = call i32 @fputs(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.19, i64 0, i64 0), i32* %125)
%127 = load i32*, i32** %7
%128 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.20, i64 0, i64 0), i32* %127)
%129 = load i32*, i32** %7
%130 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.20, i64 0, i64 0), i32* %129)
%131 = load i32*, i32** %7
%132 = call i32 @fputs(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.21, i64 0, i64 0), i32* %131)
br label %133
133: ; preds = %122, %148
%134 = load i32*, i32** %6
%135 = call zeroext i8 @getc(i32* %134)
store i8 %135, i8* %13
%136 = load i32*, i32** %6
%137 = call i64 @feof(i32* %136)
%138 = icmp ne i64 %137, 0
br i1 %138, label %139, label %140
139: ; preds = %133
br label %161
140: ; preds = %133
%141 = getelementptr inbounds [3 x i8], [3 x i8]* %14, i64 0, i64 0
%142 = call i32 @memset(i8* %141, i32 0, i32 2)
%143 = load i32, i32* %12
%144 = icmp sge i32 %143, 16
br i1 %144, label %145, label %148
145: ; preds = %140
%146 = load i32*, i32** %7
%147 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.20, i64 0, i64 0), i32* %146)
store i32 0, i32* %12
br label %148
148: ; preds = %145, %140
%149 = load i32*, i32** %7
%150 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.22, i64 0, i64 0), i32* %149)
%151 = getelementptr inbounds [3 x i8], [3 x i8]* %14, i64 0, i64 0
%152 = load i8, i8* %13
%153 = call i32 @sprintf(i8* %151, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.23, i64 0, i64 0), i8 zeroext %152)
%154 = getelementptr inbounds [3 x i8], [3 x i8]* %14, i64 0, i64 0
%155 = load i32*, i32** %7
%156 = call i32 @fputs(i8* %154, i32* %155)
%157 = load i32*, i32** %7
%158 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.24, i64 0, i64 0), i32* %157)
%159 = load i32, i32* %12
%160 = add nsw i32 %159, 1
store i32 %160, i32* %12
br label %133
161: ; preds = %139
%162 = load i32*, i32** %7
%163 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.25, i64 0, i64 0), i32* %162)
%164 = load i32*, i32** %6
%165 = call i32 @fclose(i32* %164)
%166 = load i32*, i32** %7
%167 = call i32 @fclose(i32* %166)
%168 = call i32 @exit(i32 0)
unreachable
169: ; preds = %119, %111, %30, %25
%170 = load i32, i32* %3
ret i32 %170
}

LLVM IR (-O2):
@.str = [11 x i8] c"RT28xx_DIR\00"
@.str.1 = [8 x i8] c"CHIPSET\00"
@.str.4 = [5 x i8] c"2860\00"
@.str.5 = [19 x i8] c"/common/rt2860.bin\00"
@.str.6 = [5 x i8] c"2870\00"
@.str.7 = [19 x i8] c"/common/rt2870.bin\00"
@.str.8 = [5 x i8] c"3090\00"
@.str.9 = [5 x i8] c"2070\00"
@.str.10 = [5 x i8] c"3070\00"
@.str.11 = [5 x i8] c"3572\00"
@.str.12 = [5 x i8] c"3370\00"
@.str.13 = [10 x i8] c"USB_COMBO\00"
@.str.14 = [20 x i8] c"/include/firmware.h\00"
@.str.15 = [2 x i8] c"r\00"
@.str.16 = [21 x i8] c"Can't read file %s \0A\00"
@.str.17 = [2 x i8] c"w\00"
@.str.18 = [27 x i8] c"Can't open write file %s \0A\00"
@.str.19 = [41 x i8] c"/* AUTO GEN PLEASE DO NOT MODIFY IT */ \0A\00"
@.str.21 = [29 x i8] c"UCHAR FirmwareImage [] = { \0A\00"
@.str.22 = [3 x i8] c"0x\00"
@.str.23 = [5 x i8] c"%02x\00"
@.str.24 = [3 x i8] c", \00"
@.str.25 = [5 x i8] c"} ;\0A\00"
@str = [43 x i8] c"Environment value \22RT28xx_DIR\22 not export \00"
@str.26 = [40 x i8] c"Environment value \22CHIPSET\22 not export \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [3 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = call i32 @memset(i8* %6, i32 0, i32 1024)
%9 = call i32 @memset(i8* %7, i32 0, i32 1024)
%10 = call i64 @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%11 = inttoptr i64 %10 to i8*
%12 = call i64 @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%13 = inttoptr i64 %12 to i8*
%14 = icmp eq i64 %10, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %93
17: ; preds = %2
%18 = icmp eq i64 %12, 0
br i1 %18, label %19, label %21
19: ; preds = %17
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.26, i64 0, i64 0))
br label %93
21: ; preds = %17
%22 = call i32 @strcat(i8* %6, i8* %11)
%23 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %47, label %25
25: ; preds = %21
%26 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4)
%27 = icmp eq i64 %26, 0
br i1 %27, label %47, label %28
28: ; preds = %25
%29 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 4)
%30 = icmp eq i64 %29, 0
br i1 %30, label %47, label %31
31: ; preds = %28
%32 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 4)
%33 = icmp eq i64 %32, 0
br i1 %33, label %47, label %34
34: ; preds = %31
%35 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 4)
%36 = icmp eq i64 %35, 0
br i1 %36, label %47, label %37
37: ; preds = %34
%38 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32 4)
%39 = icmp eq i64 %38, 0
br i1 %39, label %47, label %40
40: ; preds = %37
%41 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i32 4)
%42 = icmp eq i64 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %40
%44 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i32 9)
%45 = icmp eq i64 %44, 0
%46 = select i1 %45, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0)
br label %47
47: ; preds = %43, %40, %37, %34, %31, %28, %25, %21
%48 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), %21 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), %25 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), %28 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), %31 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), %34 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), %37 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), %40 ], [ %46, %43 ]
%49 = call i32 @strcat(i8* %6, i8* %48)
%50 = call i32 @strcat(i8* %7, i8* %11)
%51 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0))
%52 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %56
54: ; preds = %47
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.16, i64 0, i64 0), i8* %6)
br label %93
56: ; preds = %47
%57 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
%58 = icmp eq i32* %57, null
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.18, i64 0, i64 0), i8* %7)
br label %93
61: ; preds = %56
%62 = call i64 @fwrite(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.19, i64 0, i64 0), i64 40, i64 1, i32* %57)
%63 = call i64 @fwrite(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.19, i64 0, i64 0), i64 40, i64 1, i32* %57)
%64 = call i32 @fputc(i32 10, i32* %57)
%65 = call i32 @fputc(i32 10, i32* %57)
%66 = call i64 @fwrite(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.21, i64 0, i64 0), i64 28, i64 1, i32* %57)
%67 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%68 = call zeroext i8 @getc(i32* %52)
%69 = call i64 @feof(i32* %52)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %88
71: ; preds = %61, %78
%72 = phi i8 [ %85, %78 ], [ %68, %61 ]
%73 = phi i32 [ %84, %78 ], [ 0, %61 ]
%74 = call i32 @memset(i8* %67, i32 0, i32 2)
%75 = icmp sgt i32 %73, 15
br i1 %75, label %76, label %78
76: ; preds = %71
%77 = call i32 @fputc(i32 10, i32* %57)
br label %78
78: ; preds = %71, %76
%79 = phi i32 [ 0, %76 ], [ %73, %71 ]
%80 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.22, i64 0, i64 0), i64 2, i64 1, i32* %57)
%81 = call i32 @sprintf(i8* %67, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.23, i64 0, i64 0), i8 zeroext %72)
%82 = call i32 @fputs(i8* %67, i32* %57)
%83 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.24, i64 0, i64 0), i64 2, i64 1, i32* %57)
%84 = add nsw i32 %79, 1
%85 = call zeroext i8 @getc(i32* %52)
%86 = call i64 @feof(i32* %52)
%87 = icmp eq i64 %86, 0
br i1 %87, label %71, label %88
88: ; preds = %78, %61
%89 = call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.25, i64 0, i64 0), i64 4, i64 1, i32* %57)
%90 = call i32 @fclose(i32* %52)
%91 = call i32 @fclose(i32* %57)
%92 = call i32 @exit(i32 0)
unreachable
93: ; preds = %59, %54, %19, %15
ret i32 -1
}