#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int readFile(char *, char **);
scalar_t__ strcmp(char *, char *);
int validateTRX(int, char *, char *, int);
int main(int argc, char *argv[]) {
  if (argc > 1) {
    int linksys = 0;
    if (argc > 2 && strcmp(argv[2], "-l") == 0)
      linksys = 1;
    char *data, *filename = argv[1];
    int size = readFile(filename, &data);
    int result = validateTRX(size, data, filename, linksys);
    if (result == 1)
      printf("TRX header is valid!\n");
  } else {
    printf(
        "TRXUtil verifies the TRX header of a binary file. If it is incorrect "
        "or missing, a new file will be written to <oldfilename>.trx with a "
        "complete TRX header. Passing -l (for Linksys mode) will write out a "
        "header with a 932-byte smaller file size, which some Linksys web GUIs "
        "require for some reason. Written by Ari Weinstein on 6/26/12.\nUsage: "
        "%s <file> [-l]\n\nExample:\n%s WR1043ND_firmware.bin\n",
        argv[0], argv[0]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11e5 <main+0xa5>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1196 <main+0x56>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe80(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1196 <main+0x56>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <readFile@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1040 <validateTRX@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x1,-0x30(%rbp)
jne    11e0 <main+0xa0>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1201 <main+0xc1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jl     11ad <main+0x5d>
xor    %ebp,%ebp
cmp    $0x2,%edi
je     117b <main+0x2b>
mov    0x10(%rbx),%rdi
lea    0xe93(%rip),%rsi
call   1060 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    0x8(%rbx),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <readFile@plt>
mov    (%rsp),%rsi
mov    %eax,%edi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1050 <validateTRX@plt>
cmp    $0x1,%eax
jne    11c1 <main+0x71>
lea    0xfe7(%rip),%rdi
call   1030 <puts@plt>
jmp    11c1 <main+0x71>
mov    (%rbx),%rdx
lea    0xe4c(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-l\00"
@.str.1 = [22 x i8] c"TRX header is valid!\0A\00"
@.str.2 = [394 x i8] c"TRXUtil verifies the TRX header of a binary file. If it is incorrect or missing, a new file will be written to <oldfilename>.trx with a complete TRX header. Passing -l (for Linksys mode) will write out a header with a 932-byte smaller file size, which some Linksys web GUIs require for some reason. Written by Ari Weinstein on 6/26/12.\0AUsage: %s <file> [-l]\0A\0AExample:\0A%s WR1043ND_firmware.bin\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %39
13: ; preds = %2
store i32 0, i32* %6
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 2
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %16
store i32 1, i32* %6
br label %23
23: ; preds = %22, %16, %13
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %8
%27 = load i8*, i8** %8
%28 = call i32 @readFile(i8* %27, i8** %7)
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = load i8*, i8** %7
%31 = load i8*, i8** %8
%32 = load i32, i32* %6
%33 = call i32 @validateTRX(i32 %29, i8* %30, i8* %31, i32 %32)
store i32 %33, i32* %10
%34 = load i32, i32* %10
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %38
36: ; preds = %23
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %36, %23
br label %47
39: ; preds = %2
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 0
%45 = load i8*, i8** %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([394 x i8], [394 x i8]* @.str.2, i64 0, i64 0), i8* %42, i8* %45)
br label %47
47: ; preds = %39, %38
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"-l\00"
@.str.2 = [394 x i8] c"TRXUtil verifies the TRX header of a binary file. If it is incorrect or missing, a new file will be written to <oldfilename>.trx with a complete TRX header. Passing -l (for Linksys mode) will write out a header with a 932-byte smaller file size, which some Linksys web GUIs require for some reason. Written by Ari Weinstein on 6/26/12.\0AUsage: %s <file> [-l]\0A\0AExample:\0A%s WR1043ND_firmware.bin\0A\00"
@str = [21 x i8] c"TRX header is valid!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %25
5: ; preds = %2
%6 = icmp eq i32 %0, 2
br i1 %6, label %13, label %7
7: ; preds = %5
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %7, %5
%14 = phi i32 [ 0, %5 ], [ %12, %7 ]
%15 = bitcast i8** %3 to i8*
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @readFile(i8* %17, i8** %3)
%19 = load i8*, i8** %3
%20 = call i32 @validateTRX(i32 %18, i8* %19, i8* %17, i32 %14)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %24
22: ; preds = %13
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %22, %13
br label %28
25: ; preds = %2
%26 = load i8*, i8** %1
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([394 x i8], [394 x i8]* @.str.2, i64 0, i64 0), i8* %26, i8* %26)
br label %28
28: ; preds = %25, %24
ret i32 0
}