#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*/ infname;
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 *);
int strlen(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;
  }
  if (strlen(rt28xxdir) > (sizeof(infname) - 100)) {
    printf("Environment value \"RT28xx_DIR\" is too long!\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   1090 <memset@plt>
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
lea    0xde0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x828(%rbp)
lea    0xdd8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x830(%rbp)
cmpq   $0x0,-0x828(%rbp)
jne    1267 <main+0x97>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16c0 <main+0x4f0>
cmpq   $0x0,-0x830(%rbp)
jne    128f <main+0xbf>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16c0 <main+0x4f0>
mov    -0x828(%rbp),%rdi
call   1060 <strlen@plt>
cltq
cmp    $0x39c,%rax
jbe    12c3 <main+0xf3>
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16c0 <main+0x4f0>
lea    -0x420(%rbp),%rdi
mov    -0x828(%rbp),%rsi
call   10c0 <strcat@plt>
mov    -0x830(%rbp),%rdi
lea    0xdb1(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1310 <main+0x140>
lea    -0x420(%rbp),%rdi
lea    0xd94(%rip),%rsi
call   10c0 <strcat@plt>
jmp    14dc <main+0x30c>
mov    -0x830(%rbp),%rdi
lea    0xd8f(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    134a <main+0x17a>
lea    -0x420(%rbp),%rdi
lea    0xd72(%rip),%rsi
call   10c0 <strcat@plt>
jmp    14d7 <main+0x307>
mov    -0x830(%rbp),%rdi
lea    0xd6d(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1384 <main+0x1b4>
lea    -0x420(%rbp),%rdi
lea    0xd20(%rip),%rsi
call   10c0 <strcat@plt>
jmp    14d2 <main+0x302>
mov    -0x830(%rbp),%rdi
lea    0xd38(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    13be <main+0x1ee>
lea    -0x420(%rbp),%rdi
lea    0xcfe(%rip),%rsi
call   10c0 <strcat@plt>
jmp    14cd <main+0x2fd>
mov    -0x830(%rbp),%rdi
lea    0xd03(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    13f8 <main+0x228>
lea    -0x420(%rbp),%rdi
lea    0xcc4(%rip),%rsi
call   10c0 <strcat@plt>
jmp    14c8 <main+0x2f8>
mov    -0x830(%rbp),%rdi
lea    0xcce(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1432 <main+0x262>
lea    -0x420(%rbp),%rdi
lea    0xc8a(%rip),%rsi
call   10c0 <strcat@plt>
jmp    14c3 <main+0x2f3>
mov    -0x830(%rbp),%rdi
lea    0xc99(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    146c <main+0x29c>
lea    -0x420(%rbp),%rdi
lea    0xc50(%rip),%rsi
call   10c0 <strcat@plt>
jmp    14be <main+0x2ee>
mov    -0x830(%rbp),%rdi
lea    0xc64(%rip),%rsi
mov    $0x9,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    14a6 <main+0x2d6>
lea    -0x420(%rbp),%rdi
lea    0xc16(%rip),%rsi
call   10c0 <strcat@plt>
jmp    14b9 <main+0x2e9>
lea    -0x420(%rbp),%rdi
lea    0xbe6(%rip),%rsi
call   10c0 <strcat@plt>
jmp    14be <main+0x2ee>
jmp    14c3 <main+0x2f3>
jmp    14c8 <main+0x2f8>
jmp    14cd <main+0x2fd>
jmp    14d2 <main+0x302>
jmp    14d7 <main+0x307>
jmp    14dc <main+0x30c>
lea    -0x820(%rbp),%rdi
mov    -0x828(%rbp),%rsi
call   10c0 <strcat@plt>
lea    -0x820(%rbp),%rdi
lea    0xbeb(%rip),%rsi
call   10c0 <strcat@plt>
lea    -0x420(%rbp),%rdi
lea    0xbec(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1545 <main+0x375>
lea    -0x420(%rbp),%rsi
lea    0xbcc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16c0 <main+0x4f0>
lea    -0x820(%rbp),%rdi
lea    0xbc0(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1588 <main+0x3b8>
lea    -0x820(%rbp),%rsi
lea    0xba0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16c0 <main+0x4f0>
mov    -0x20(%rbp),%rsi
lea    0xb9d(%rip),%rdi
call   1080 <fputs@plt>
mov    -0x20(%rbp),%rsi
lea    0xb8d(%rip),%rdi
call   1080 <fputs@plt>
mov    -0x20(%rbp),%rsi
lea    0xba4(%rip),%rdi
call   1080 <fputs@plt>
mov    -0x20(%rbp),%rsi
lea    0xb94(%rip),%rdi
call   1080 <fputs@plt>
mov    -0x20(%rbp),%rsi
lea    0xb86(%rip),%rdi
call   1080 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   10f0 <getc@plt>
mov    %al,-0x835(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%rax
je     15ff <main+0x42f>
jmp    1697 <main+0x4c7>
lea    -0x838(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1090 <memset@plt>
cmpl   $0x10,-0x834(%rbp)
jl     1639 <main+0x469>
mov    -0x20(%rbp),%rsi
lea    0xb2d(%rip),%rdi
call   1080 <fputs@plt>
movl   $0x0,-0x834(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xb32(%rip),%rdi
call   1080 <fputs@plt>
lea    -0x838(%rbp),%rdi
lea    0xb22(%rip),%rsi
movzbl -0x835(%rbp),%edx
call   10d0 <sprintf@plt>
lea    -0x838(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <fputs@plt>
mov    -0x20(%rbp),%rsi
lea    0xb00(%rip),%rdi
call   1080 <fputs@plt>
mov    -0x834(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x834(%rbp)
jmp    15d8 <main+0x408>
mov    -0x20(%rbp),%rsi
lea    0xadf(%rip),%rdi
call   1080 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
call   10e0 <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   10a0 <memset@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10a0 <memset@plt>
lea    0xdc3(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
lea    0xdbf(%rip),%rdi
call   1030 <getenv@plt>
test   %r14,%r14
je     1276 <main+0x76>
mov    %rax,%rbx
test   %rax,%rax
je     127f <main+0x7f>
mov    %r14,%rdi
call   1070 <strlen@plt>
cmp    $0x39d,%eax
jb     12a2 <main+0xa2>
lea    0xee3(%rip),%rdi
jmp    1286 <main+0x86>
lea    0xe87(%rip),%rdi
jmp    1286 <main+0x86>
lea    0xea9(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x410(%rsp),%rdi
mov    %r14,%rsi
call   10e0 <strcat@plt>
lea    0xd5a(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
lea    0xd4b(%rip),%rbp
test   %rax,%rax
je     13ac <main+0x1ac>
lea    0xd4e(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
lea    0xd3f(%rip),%r15
test   %rax,%rax
je     13a9 <main+0x1a9>
lea    0xd42(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     13ac <main+0x1ac>
lea    0xd2a(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     13a9 <main+0x1a9>
lea    0xd16(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     13a9 <main+0x1a9>
lea    0xd02(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     13a9 <main+0x1a9>
lea    0xcee(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
mov    %r15,%rbp
test   %rax,%rax
je     13ac <main+0x1ac>
lea    0xcd7(%rip),%rsi
mov    %rbx,%rdi
mov    $0x9,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
lea    0xc94(%rip),%rax
lea    0xc75(%rip),%rbp
cmove  %rax,%rbp
jmp    13ac <main+0x1ac>
mov    %r15,%rbp
lea    0x410(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10e0 <strcat@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   10e0 <strcat@plt>
lea    0xc90(%rip),%rsi
mov    %rbp,%rdi
call   10e0 <strcat@plt>
lea    0xc95(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1419 <main+0x219>
mov    %rax,%rbx
lea    0xc95(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
jne    1434 <main+0x234>
lea    0xc81(%rip),%rdi
lea    0x10(%rsp),%rsi
jmp    1428 <main+0x228>
lea    0xc5c(%rip),%rdi
lea    0x410(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    128b <main+0x8b>
mov    %rax,%r14
lea    0xc70(%rip),%rbp
mov    $0x28,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %rax,%rcx
call   1110 <fwrite@plt>
mov    $0x28,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %r14,%rcx
call   1110 <fwrite@plt>
mov    $0xa,%edi
mov    %r14,%rsi
call   10b0 <fputc@plt>
mov    $0xa,%edi
mov    %r14,%rsi
call   10b0 <fputc@plt>
lea    0xc4e(%rip),%rdi
mov    $0x1c,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1110 <fwrite@plt>
mov    %rbx,%rdi
call   1120 <getc@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   10c0 <feof@plt>
test   %rax,%rax
jne    155a <main+0x35a>
xor    %r13d,%r13d
lea    0xd(%rsp),%r15
lea    0xc36(%rip),%rbp
jmp    1530 <main+0x330>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xc1b(%rip),%rdi
mov    %r14,%rcx
call   1110 <fwrite@plt>
movzbl %r12b,%edx
mov    %r15,%rdi
lea    0xc08(%rip),%rsi
call   10f0 <sprintf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1090 <fputs@plt>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %r14,%rcx
call   1110 <fwrite@plt>
add    $0x1,%r13d
mov    %rbx,%rdi
call   1120 <getc@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   10c0 <feof@plt>
test   %rax,%rax
jne    155a <main+0x35a>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   10a0 <memset@plt>
cmp    $0x10,%r13d
jl     14c8 <main+0x2c8>
mov    $0xa,%edi
mov    %r14,%rsi
call   10b0 <fputc@plt>
xor    %r13d,%r13d
jmp    14c8 <main+0x2c8>
lea    0xb9e(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1110 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %edi,%edi
call   1100 <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 = [45 x i8] c"Environment value \22RT28xx_DIR\22 is too long!\0A\00"
@.str.5 = [5 x i8] c"2860\00"
@.str.6 = [19 x i8] c"/common/rt2860.bin\00"
@.str.7 = [5 x i8] c"2870\00"
@.str.8 = [19 x i8] c"/common/rt2870.bin\00"
@.str.9 = [5 x i8] c"3090\00"
@.str.10 = [5 x i8] c"2070\00"
@.str.11 = [5 x i8] c"3070\00"
@.str.12 = [5 x i8] c"3572\00"
@.str.13 = [5 x i8] c"3370\00"
@.str.14 = [10 x i8] c"USB_COMBO\00"
@.str.15 = [20 x i8] c"/include/firmware.h\00"
@.str.16 = [2 x i8] c"r\00"
@.str.17 = [21 x i8] c"Can't read file %s \0A\00"
@.str.18 = [2 x i8] c"w\00"
@.str.19 = [27 x i8] c"Can't open write file %s \0A\00"
@.str.20 = [41 x i8] c"/* AUTO GEN PLEASE DO NOT MODIFY IT */ \0A\00"
@.str.21 = [2 x i8] c"\0A\00"
@.str.22 = [29 x i8] c"UCHAR FirmwareImage [] = { \0A\00"
@.str.23 = [3 x i8] c"0x\00"
@.str.24 = [5 x i8] c"%02x\00"
@.str.25 = [3 x i8] c", \00"
@.str.26 = [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 %176
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 %176
32: ; preds = %27
%33 = load i8*, i8** %10
%34 = call i32 @strlen(i8* %33)
%35 = sext i32 %34 to i64
%36 = icmp ugt i64 %35, 924
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %176
39: ; preds = %32
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%41 = load i8*, i8** %10
%42 = call i32 @strcat(i8* %40, i8* %41)
%43 = load i8*, i8** %11
%44 = call i64 @strncmp(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %39
%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.6, i64 0, i64 0))
br label %108
49: ; preds = %39
%50 = load i8*, i8** %11
%51 = call i64 @strncmp(i8* %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, 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.8, i64 0, i64 0))
br label %107
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.6, i64 0, i64 0))
br label %106
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.8, i64 0, i64 0))
br label %105
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.8, i64 0, i64 0))
br label %104
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.8, i64 0, i64 0))
br label %103
84: ; preds = %77
%85 = load i8*, i8** %11
%86 = call i64 @strncmp(i8* %85, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0), i32 4)
%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.8, i64 0, i64 0))
br label %102
91: ; preds = %84
%92 = load i8*, i8** %11
%93 = call i64 @strncmp(i8* %92, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 9)
%94 = icmp eq i64 %93, 0
br i1 %94, label %95, label %98
95: ; preds = %91
%96 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%97 = call i32 @strcat(i8* %96, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
br label %101
98: ; preds = %91
%99 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%100 = call i32 @strcat(i8* %99, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
br label %101
101: ; preds = %98, %95
br label %102
102: ; preds = %101, %88
br label %103
103: ; preds = %102, %81
br label %104
104: ; preds = %103, %74
br label %105
105: ; preds = %104, %67
br label %106
106: ; preds = %105, %60
br label %107
107: ; preds = %106, %53
br label %108
108: ; preds = %107, %46
%109 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%110 = load i8*, i8** %10
%111 = call i32 @strcat(i8* %109, i8* %110)
%112 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%113 = call i32 @strcat(i8* %112, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.15, i64 0, i64 0))
%114 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%115 = call i32* @fopen(i8* %114, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0))
store i32* %115, i32** %6
%116 = load i32*, i32** %6
%117 = icmp eq i32* %116, null
br i1 %117, label %118, label %121
118: ; preds = %108
%119 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.17, i64 0, i64 0), i8* %119)
store i32 -1, i32* %3
br label %176
121: ; preds = %108
%122 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%123 = call i32* @fopen(i8* %122, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.18, i64 0, i64 0))
store i32* %123, i32** %7
%124 = load i32*, i32** %7
%125 = icmp eq i32* %124, null
br i1 %125, label %126, label %129
126: ; preds = %121
%127 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.19, i64 0, i64 0), i8* %127)
store i32 -1, i32* %3
br label %176
129: ; preds = %121
%130 = load i32*, i32** %7
%131 = call i32 @fputs(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.20, i64 0, i64 0), i32* %130)
%132 = load i32*, i32** %7
%133 = call i32 @fputs(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.20, i64 0, i64 0), i32* %132)
%134 = load i32*, i32** %7
%135 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.21, i64 0, i64 0), i32* %134)
%136 = load i32*, i32** %7
%137 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.21, i64 0, i64 0), i32* %136)
%138 = load i32*, i32** %7
%139 = call i32 @fputs(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.22, i64 0, i64 0), i32* %138)
br label %140
140: ; preds = %129, %155
%141 = load i32*, i32** %6
%142 = call zeroext i8 @getc(i32* %141)
store i8 %142, i8* %13
%143 = load i32*, i32** %6
%144 = call i64 @feof(i32* %143)
%145 = icmp ne i64 %144, 0
br i1 %145, label %146, label %147
146: ; preds = %140
br label %168
147: ; preds = %140
%148 = getelementptr inbounds [3 x i8], [3 x i8]* %14, i64 0, i64 0
%149 = call i32 @memset(i8* %148, i32 0, i32 2)
%150 = load i32, i32* %12
%151 = icmp sge i32 %150, 16
br i1 %151, label %152, label %155
152: ; preds = %147
%153 = load i32*, i32** %7
%154 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.21, i64 0, i64 0), i32* %153)
store i32 0, i32* %12
br label %155
155: ; preds = %152, %147
%156 = load i32*, i32** %7
%157 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.23, i64 0, i64 0), i32* %156)
%158 = getelementptr inbounds [3 x i8], [3 x i8]* %14, i64 0, i64 0
%159 = load i8, i8* %13
%160 = call i32 @sprintf(i8* %158, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.24, i64 0, i64 0), i8 zeroext %159)
%161 = getelementptr inbounds [3 x i8], [3 x i8]* %14, i64 0, i64 0
%162 = load i32*, i32** %7
%163 = call i32 @fputs(i8* %161, i32* %162)
%164 = load i32*, i32** %7
%165 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.25, i64 0, i64 0), i32* %164)
%166 = load i32, i32* %12
%167 = add nsw i32 %166, 1
store i32 %167, i32* %12
br label %140
168: ; preds = %146
%169 = load i32*, i32** %7
%170 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.26, i64 0, i64 0), i32* %169)
%171 = load i32*, i32** %6
%172 = call i32 @fclose(i32* %171)
%173 = load i32*, i32** %7
%174 = call i32 @fclose(i32* %173)
%175 = call i32 @exit(i32 0)
unreachable
176: ; preds = %126, %118, %37, %30, %25
%177 = load i32, i32* %3
ret i32 %177
}

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