#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*/ SEEK_SET;
int /*<<< orphan*/ _filesize(int /*<<< orphan*/ *);
int /*<<< orphan*/ checksum(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
char *int2le(int /*<<< orphan*/);
int /*<<< orphan*/ merge_hxf(char *, int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  FILE *outfile;
  fprintf(stderr, "HXFmerge v"
                  "0.2"
                  " - (C) 2008 Maurus Cuelenaere\n");
  fprintf(stderr, "This is free software; see the source for copying "
                  "conditions.  There is NO\n");
  fprintf(stderr, "warranty; not even for MERCHANTABILITY or FITNESS FOR A "
                  "PARTICULAR PURPOSE.\n\n");
  if (argc != 3) {
    print_usage();
    return 1;
  }
  if (strcmp((char *)(argv[1] + strlen(argv[1]) - 1), "/") != 0) {
    fprintf(stderr, "[ERR]  Input path must end with a /\n");
    return 2;
  }
  if ((outfile = fopen(argv[2], "wb+")) == NULL) {
    fprintf(stderr, "[ERR]  Cannot open %s\n", argv[2]);
    return 3;
  }
  fseek(outfile, 0x40, SEEK_SET);
  merge_hxf(argv[1], outfile, "");
  fflush(outfile);
  fprintf(stderr, "[INFO] Filling header...\n");
  fflush(outfile);
  fseek(outfile, 0, SEEK_SET);
  if (fwrite("WADF0100200804111437", 20, 1, outfile) != 1) {
    fprintf(stderr, "[ERR]  Cannot write to %s\n", argv[1]);
    fclose(outfile);
    return 4;
  };
  if (fwrite(int2le(_filesize(outfile)), 4, 1, outfile) != 1) {
    fprintf(stderr, "[ERR]  Cannot write to %s\n", argv[1]);
    fclose(outfile);
    return 4;
  };
  if (fwrite(int2le(checksum(outfile)), 4, 1, outfile) != 1) {
    fprintf(stderr, "[ERR]  Cannot write to %s\n", argv[1]);
    fclose(outfile);
    return 4;
  };
  if (fwrite(int2le(0), 4, 1, outfile) != 1) {
    fprintf(stderr, "[ERR]  Cannot write to %s\n", argv[1]);
    fclose(outfile);
    return 4;
  };
  if (fwrite("Chinachip PMP firmware V1.0\0\0\0\0\0", 32, 1, outfile) != 1) {
    fprintf(stderr, "[ERR]  Cannot write to %s\n", argv[1]);
    fclose(outfile);
    return 4;
  };
  fclose(outfile);
  fprintf(stderr, "[INFO] Done!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
cmpl   $0x3,-0x8(%rbp)
je     1248 <main+0x78>
mov    $0x0,%al
call   10f0 <print_usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1555 <main+0x385>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0xffffffffffffffff,%rdi
lea    0xe51(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     12a7 <main+0xd7>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1555 <main+0x385>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe37(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    12f4 <main+0x124>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    1555 <main+0x385>
mov    -0x18(%rbp),%rdi
mov    0x2cd9(%rip),%rax
mov    (%rax),%edx
mov    $0x40,%esi
call   10b0 <fseek@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rsi
lea    0xda7(%rip),%rdx
call   1060 <merge_hxf@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <fflush@plt>
mov    0x2cad(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <fflush@plt>
mov    -0x18(%rbp),%rdi
mov    0x2c81(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x18(%rbp),%rcx
lea    0xdb7(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
cmp    $0x1,%eax
je     13b7 <main+0x1e7>
mov    0x2c56(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x4,-0x4(%rbp)
jmp    1555 <main+0x385>
mov    -0x18(%rbp),%rdi
call   1070 <_filesize@plt>
mov    %eax,%edi
call   10d0 <int2le@plt>
mov    %rax,%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
cmp    $0x1,%eax
je     141a <main+0x24a>
mov    0x2bf3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd39(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x4,-0x4(%rbp)
jmp    1555 <main+0x385>
mov    -0x18(%rbp),%rdi
call   1050 <checksum@plt>
mov    %eax,%edi
call   10d0 <int2le@plt>
mov    %rax,%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
cmp    $0x1,%eax
je     147d <main+0x2ad>
mov    0x2b90(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xcd6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x4,-0x4(%rbp)
jmp    1555 <main+0x385>
xor    %edi,%edi
call   10d0 <int2le@plt>
mov    %rax,%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
cmp    $0x1,%eax
je     14d7 <main+0x307>
mov    0x2b36(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc7c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x4,-0x4(%rbp)
jmp    1555 <main+0x385>
mov    -0x18(%rbp),%rcx
lea    0xc7e(%rip),%rdi
mov    $0x20,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
cmp    $0x1,%eax
je     152e <main+0x35e>
mov    0x2adf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc25(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x4,-0x4(%rbp)
jmp    1555 <main+0x385>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2aa2(%rip),%rax
mov    (%rax),%edi
lea    0xc0b(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x2dfd(%rip),%rbx
mov    (%rbx),%edi
lea    0xe14(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe30(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe6c(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
cmp    $0x3,%ebp
jne    1256 <main+0x86>
mov    0x8(%r15),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%rbp,1),%rdi
add    $0xffffffffffffffff,%rdi
lea    0xe91(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     126f <main+0x9f>
mov    (%rbx),%edi
lea    0xe80(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x2,%ebp
jmp    1262 <main+0x92>
xor    %eax,%eax
call   10f0 <print_usage@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%r15),%rdi
lea    0xe73(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     13cf <main+0x1ff>
mov    %rax,%r14
mov    0x2d46(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %rax,%rdi
mov    $0x40,%esi
call   10b0 <fseek@plt>
mov    0x8(%r15),%rdi
lea    0xe18(%rip),%rdx
mov    %r14,%rsi
call   1060 <merge_hxf@plt>
mov    %r14,%rdi
call   10a0 <fflush@plt>
mov    (%rbx),%edi
lea    0xe42(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   10a0 <fflush@plt>
mov    0x0(%rbp),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
lea    0xe39(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10e0 <fwrite@plt>
cmp    $0x1,%eax
jne    13ed <main+0x21d>
mov    %r14,%rdi
call   1070 <_filesize@plt>
mov    %eax,%edi
call   10d0 <int2le@plt>
mov    $0x4,%ebp
mov    %rax,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10e0 <fwrite@plt>
cmp    $0x1,%eax
jne    1413 <main+0x243>
mov    %r14,%rdi
call   1050 <checksum@plt>
mov    %eax,%edi
call   10d0 <int2le@plt>
mov    $0x4,%ebp
mov    %rax,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10e0 <fwrite@plt>
cmp    $0x1,%eax
jne    1413 <main+0x243>
xor    %edi,%edi
call   10d0 <int2le@plt>
mov    $0x4,%ebp
mov    %rax,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10e0 <fwrite@plt>
cmp    $0x1,%eax
jne    1413 <main+0x243>
lea    0xdc7(%rip),%rdi
mov    $0x20,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10e0 <fwrite@plt>
cmp    $0x1,%eax
jne    1413 <main+0x243>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    (%rbx),%edi
lea    0xd91(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1262 <main+0x92>
mov    (%rbx),%edi
mov    0x10(%r15),%rdx
lea    0xd15(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x3,%ebp
jmp    1262 <main+0x92>
mov    (%rbx),%edi
mov    0x8(%r15),%rdx
lea    0xd3d(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0x4,%ebp
jmp    1262 <main+0x92>
mov    (%rbx),%edi
mov    0x8(%r15),%rdx
lea    0xd17(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    1262 <main+0x92>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"HXFmerge v0.2 - (C) 2008 Maurus Cuelenaere\0A\00"
@.str.1 = [76 x i8] c"This is free software; see the source for copying conditions. There is NO\0A\00"
@.str.2 = [78 x i8] c"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\0A\0A\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [37 x i8] c"[ERR] Input path must end with a /\0A\00"
@.str.5 = [4 x i8] c"wb+\00"
@.str.6 = [23 x i8] c"[ERR] Cannot open %s\0A\00"
@SEEK_SET = global i32 0
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [26 x i8] c"[INFO] Filling header...\0A\00"
@.str.9 = [21 x i8] c"WADF0100200804111437\00"
@.str.10 = [27 x i8] c"[ERR] Cannot write to %s\0A\00"
@.str.11 = [33 x i8] c"Chinachip PMP firmware V1.0\00\00\00\00\00\00"
@.str.12 = [14 x i8] c"[INFO] Done!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @stderr
%8 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (...) @print_usage()
store i32 1, i32* %3
br label %134
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @strlen(i8* %23)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %20, i64 %25
%27 = getelementptr inbounds i8, i8* %26, i64 -1
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %17
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %3
br label %134
33: ; preds = %17
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store i32* %37, i32** %6
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %45
39: ; preds = %33
%40 = load i32, i32* @stderr
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %43)
store i32 3, i32* %3
br label %134
45: ; preds = %33
%46 = load i32*, i32** %6
%47 = load i32, i32* @SEEK_SET
%48 = call i32 @fseek(i32* %46, i32 64, i32 %47)
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = load i32*, i32** %6
%53 = call i32 @merge_hxf(i8* %51, i32* %52, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
%54 = load i32*, i32** %6
%55 = call i32 @fflush(i32* %54)
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
%58 = load i32*, i32** %6
%59 = call i32 @fflush(i32* %58)
%60 = load i32*, i32** %6
%61 = load i32, i32* @SEEK_SET
%62 = call i32 @fseek(i32* %60, i32 0, i32 %61)
%63 = load i32*, i32** %6
%64 = call i32 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i32 20, i32 1, i32* %63)
%65 = icmp ne i32 %64, 1
br i1 %65, label %66, label %74
66: ; preds = %45
%67 = load i32, i32* @stderr
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 1
%70 = load i8*, i8** %69
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i8* %70)
%72 = load i32*, i32** %6
%73 = call i32 @fclose(i32* %72)
store i32 4, i32* %3
br label %134
74: ; preds = %45
%75 = load i32*, i32** %6
%76 = call i32 @_filesize(i32* %75)
%77 = call i8* @int2le(i32 %76)
%78 = load i32*, i32** %6
%79 = call i32 @fwrite(i8* %77, i32 4, i32 1, i32* %78)
%80 = icmp ne i32 %79, 1
br i1 %80, label %81, label %89
81: ; preds = %74
%82 = load i32, i32* @stderr
%83 = load i8**, i8*** %5
%84 = getelementptr inbounds i8*, i8** %83, i64 1
%85 = load i8*, i8** %84
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i8* %85)
%87 = load i32*, i32** %6
%88 = call i32 @fclose(i32* %87)
store i32 4, i32* %3
br label %134
89: ; preds = %74
%90 = load i32*, i32** %6
%91 = call i32 @checksum(i32* %90)
%92 = call i8* @int2le(i32 %91)
%93 = load i32*, i32** %6
%94 = call i32 @fwrite(i8* %92, i32 4, i32 1, i32* %93)
%95 = icmp ne i32 %94, 1
br i1 %95, label %96, label %104
96: ; preds = %89
%97 = load i32, i32* @stderr
%98 = load i8**, i8*** %5
%99 = getelementptr inbounds i8*, i8** %98, i64 1
%100 = load i8*, i8** %99
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i8* %100)
%102 = load i32*, i32** %6
%103 = call i32 @fclose(i32* %102)
store i32 4, i32* %3
br label %134
104: ; preds = %89
%105 = call i8* @int2le(i32 0)
%106 = load i32*, i32** %6
%107 = call i32 @fwrite(i8* %105, i32 4, i32 1, i32* %106)
%108 = icmp ne i32 %107, 1
br i1 %108, label %109, label %117
109: ; preds = %104
%110 = load i32, i32* @stderr
%111 = load i8**, i8*** %5
%112 = getelementptr inbounds i8*, i8** %111, i64 1
%113 = load i8*, i8** %112
%114 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i8* %113)
%115 = load i32*, i32** %6
%116 = call i32 @fclose(i32* %115)
store i32 4, i32* %3
br label %134
117: ; preds = %104
%118 = load i32*, i32** %6
%119 = call i32 @fwrite(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0), i32 32, i32 1, i32* %118)
%120 = icmp ne i32 %119, 1
br i1 %120, label %121, label %129
121: ; preds = %117
%122 = load i32, i32* @stderr
%123 = load i8**, i8*** %5
%124 = getelementptr inbounds i8*, i8** %123, i64 1
%125 = load i8*, i8** %124
%126 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i8* %125)
%127 = load i32*, i32** %6
%128 = call i32 @fclose(i32* %127)
store i32 4, i32* %3
br label %134
129: ; preds = %117
%130 = load i32*, i32** %6
%131 = call i32 @fclose(i32* %130)
%132 = load i32, i32* @stderr
%133 = call i32 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
store i32 0, i32* %3
br label %134
134: ; preds = %129, %121, %109, %96, %81, %66, %39, %30, %15
%135 = load i32, i32* %3
ret i32 %135
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"HXFmerge v0.2 - (C) 2008 Maurus Cuelenaere\0A\00"
@.str.1 = [76 x i8] c"This is free software; see the source for copying conditions. There is NO\0A\00"
@.str.2 = [78 x i8] c"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\0A\0A\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [37 x i8] c"[ERR] Input path must end with a /\0A\00"
@.str.5 = [4 x i8] c"wb+\00"
@.str.6 = [23 x i8] c"[ERR] Cannot open %s\0A\00"
@SEEK_SET = global i32 0
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [26 x i8] c"[INFO] Filling header...\0A\00"
@.str.9 = [21 x i8] c"WADF0100200804111437\00"
@.str.10 = [27 x i8] c"[ERR] Cannot write to %s\0A\00"
@.str.11 = [33 x i8] c"Chinachip PMP firmware V1.0\00\00\00\00\00\00"
@.str.12 = [14 x i8] c"[INFO] Done!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @stderr
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32 %0, 3
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 (...) @print_usage()
br label %92
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 -1
%19 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %12
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %92
24: ; preds = %12
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %25
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %31)
br label %92
33: ; preds = %24
%34 = load i32, i32* @SEEK_SET
%35 = tail call i32 @fseek(i32* %27, i32 64, i32 %34)
%36 = load i8*, i8** %13
%37 = tail call i32 @merge_hxf(i8* %36, i32* %27, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
%38 = tail call i32 @fflush(i32* %27)
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
%41 = tail call i32 @fflush(i32* %27)
%42 = load i32, i32* @SEEK_SET
%43 = tail call i32 @fseek(i32* %27, i32 0, i32 %42)
%44 = tail call i32 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i32 20, i32 1, i32* %27)
%45 = icmp eq i32 %44, 1
br i1 %45, label %51, label %46
46: ; preds = %33
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %13
%49 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i8* %48)
%50 = tail call i32 @fclose(i32* %27)
br label %92
51: ; preds = %33
%52 = tail call i32 @_filesize(i32* %27)
%53 = tail call i8* @int2le(i32 %52)
%54 = tail call i32 @fwrite(i8* %53, i32 4, i32 1, i32* %27)
%55 = icmp eq i32 %54, 1
br i1 %55, label %61, label %56
56: ; preds = %51
%57 = load i32, i32* @stderr
%58 = load i8*, i8** %13
%59 = tail call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i8* %58)
%60 = tail call i32 @fclose(i32* %27)
br label %92
61: ; preds = %51
%62 = tail call i32 @checksum(i32* %27)
%63 = tail call i8* @int2le(i32 %62)
%64 = tail call i32 @fwrite(i8* %63, i32 4, i32 1, i32* %27)
%65 = icmp eq i32 %64, 1
br i1 %65, label %71, label %66
66: ; preds = %61
%67 = load i32, i32* @stderr
%68 = load i8*, i8** %13
%69 = tail call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i8* %68)
%70 = tail call i32 @fclose(i32* %27)
br label %92
71: ; preds = %61
%72 = tail call i8* @int2le(i32 0)
%73 = tail call i32 @fwrite(i8* %72, i32 4, i32 1, i32* %27)
%74 = icmp eq i32 %73, 1
br i1 %74, label %80, label %75
75: ; preds = %71
%76 = load i32, i32* @stderr
%77 = load i8*, i8** %13
%78 = tail call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i8* %77)
%79 = tail call i32 @fclose(i32* %27)
br label %92
80: ; preds = %71
%81 = tail call i32 @fwrite(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0), i32 32, i32 1, i32* %27)
%82 = icmp eq i32 %81, 1
br i1 %82, label %88, label %83
83: ; preds = %80
%84 = load i32, i32* @stderr
%85 = load i8*, i8** %13
%86 = tail call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i8* %85)
%87 = tail call i32 @fclose(i32* %27)
br label %92
88: ; preds = %80
%89 = tail call i32 @fclose(i32* %27)
%90 = load i32, i32* @stderr
%91 = tail call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
br label %92
92: ; preds = %88, %83, %75, %66, %56, %46, %29, %21, %10
%93 = phi i32 [ 1, %10 ], [ 2, %21 ], [ 3, %29 ], [ 4, %46 ], [ 4, %56 ], [ 4, %66 ], [ 4, %75 ], [ 4, %83 ], [ 0, %88 ]
ret i32 %93
}