#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_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  FILE *stin;
  FILE *stout;
  int size;
  unsigned char *buf;
  printf("generate the final fw.\n");
  stout = fopen(argv[3], "wb");
  if (stout == NULL) {
    printf("can not open the file.\n");
    return 1;
  }
  stin = fopen(argv[1], "rb");
  if (stin == 0) {
    printf("no uImage file!\n");
    return 1;
  }
  fseek(stin, 0, SEEK_END);
  size = ftell(stin);
  fseek(stin, 0, SEEK_SET);
  buf = (unsigned char *)malloc(0x3c0000);
  memset(buf, 0xff, 0x3c0000);
  fread(buf, 1, size, stin);
  fseek(stout, 0, SEEK_SET);
  fwrite(buf, 1, 0x3c0000, stout);
  fclose(stin);
  free(buf);
  stin = fopen(argv[2], "rb");
  if (stin == 0) {
    printf("no rootfs file!\n");
    return 1;
  }
  fseek(stin, 0, SEEK_END);
  size = ftell(stin);
  fseek(stin, 0, SEEK_SET);
  buf = (unsigned char *)malloc(0xc00000);
  memset(buf, 0xff, 0xc00000);
  fread(buf, 1, size, stin);
  fseek(stout, 0x3c0000, SEEK_SET);
  fwrite(buf, 1, 0xc00000, stout);
  fclose(stin);
  free(buf);
  fclose(stout);
  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)
lea    0xe43(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe47(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11fd <main+0x5d>
lea    0xe2f(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d4 <main+0x234>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe27(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1238 <main+0x98>
lea    0xe0f(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d4 <main+0x234>
mov    -0x18(%rbp),%rdi
mov    0x2da5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1080 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d75(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    $0x3c0000,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0xff,%esi
mov    $0x3c0000,%edx
call   1070 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d2b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3c0000,%edx
call   10c0 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd45(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    131a <main+0x17a>
lea    0xd3e(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d4 <main+0x234>
mov    -0x18(%rbp),%rdi
mov    0x2cc3(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1080 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2c93(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    $0xc00000,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0xff,%esi
mov    $0xc00000,%edx
call   1070 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x20(%rbp),%rdi
mov    0x2c49(%rip),%rax
mov    (%rax),%edx
mov    $0x3c0000,%esi
call   10a0 <fseek@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0xc00000,%edx
call   10c0 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
lea    0xe51(%rip),%rdi
call   1040 <puts@plt>
mov    0x18(%r15),%rdi
lea    0xe3b(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1352 <main+0x1b2>
mov    %rax,%r14
mov    0x8(%r15),%rdi
lea    0xe22(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     135b <main+0x1bb>
mov    %rax,%rbx
mov    0x2def(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %eax,%r13d
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    $0x3c0000,%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0xff,%esi
mov    $0x3c0000,%edx
call   1070 <memset@plt>
mov    $0x1,%r12d
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    0x2d7e(%rip),%r13
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    0x0(%r13),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x3c0000,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    0x10(%r15),%rdi
lea    0xd63(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     136f <main+0x1cf>
mov    %rax,%rbx
mov    0x2d30(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %eax,%r15d
mov    0x0(%r13),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    $0xc00000,%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0xff,%esi
mov    $0xc00000,%edx
call   1070 <memset@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    0x0(%r13),%edx
mov    %r14,%rdi
mov    $0x3c0000,%esi
call   10a0 <fseek@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0xc00000,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %r12d,%r12d
jmp    137b <main+0x1db>
lea    0xce4(%rip),%rdi
jmp    1362 <main+0x1c2>
lea    0xccb(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r12d
jmp    137b <main+0x1db>
lea    0xca7(%rip),%rdi
call   1040 <puts@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"generate the final fw.\0A\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [24 x i8] c"can not open the file.\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [17 x i8] c"no uImage file!\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.5 = [17 x i8] c"no rootfs file!\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 i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 3
%13 = load i8*, i8** %12
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %7
%15 = load i32*, i32** %7
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %92
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %92
28: ; preds = %19
%29 = load i32*, i32** %6
%30 = load i32, i32* @SEEK_END
%31 = call i32 @fseek(i32* %29, i32 0, i32 %30)
%32 = load i32*, i32** %6
%33 = call i32 @ftell(i32* %32)
store i32 %33, i32* %8
%34 = load i32*, i32** %6
%35 = load i32, i32* @SEEK_SET
%36 = call i32 @fseek(i32* %34, i32 0, i32 %35)
%37 = call i64 @malloc(i32 3932160)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %9
%39 = load i8*, i8** %9
%40 = call i32 @memset(i8* %39, i32 255, i32 3932160)
%41 = load i8*, i8** %9
%42 = load i32, i32* %8
%43 = load i32*, i32** %6
%44 = call i32 @fread(i8* %41, i32 1, i32 %42, i32* %43)
%45 = load i32*, i32** %7
%46 = load i32, i32* @SEEK_SET
%47 = call i32 @fseek(i32* %45, i32 0, i32 %46)
%48 = load i8*, i8** %9
%49 = load i32*, i32** %7
%50 = call i32 @fwrite(i8* %48, i32 1, i32 3932160, i32* %49)
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
%53 = load i8*, i8** %9
%54 = call i32 @free(i8* %53)
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 2
%57 = load i8*, i8** %56
%58 = call i32* @fopen(i8* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %58, i32** %6
%59 = load i32*, i32** %6
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %63
61: ; preds = %28
%62 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %92
63: ; preds = %28
%64 = load i32*, i32** %6
%65 = load i32, i32* @SEEK_END
%66 = call i32 @fseek(i32* %64, i32 0, i32 %65)
%67 = load i32*, i32** %6
%68 = call i32 @ftell(i32* %67)
store i32 %68, i32* %8
%69 = load i32*, i32** %6
%70 = load i32, i32* @SEEK_SET
%71 = call i32 @fseek(i32* %69, i32 0, i32 %70)
%72 = call i64 @malloc(i32 12582912)
%73 = inttoptr i64 %72 to i8*
store i8* %73, i8** %9
%74 = load i8*, i8** %9
%75 = call i32 @memset(i8* %74, i32 255, i32 12582912)
%76 = load i8*, i8** %9
%77 = load i32, i32* %8
%78 = load i32*, i32** %6
%79 = call i32 @fread(i8* %76, i32 1, i32 %77, i32* %78)
%80 = load i32*, i32** %7
%81 = load i32, i32* @SEEK_SET
%82 = call i32 @fseek(i32* %80, i32 3932160, i32 %81)
%83 = load i8*, i8** %9
%84 = load i32*, i32** %7
%85 = call i32 @fwrite(i8* %83, i32 1, i32 12582912, i32* %84)
%86 = load i32*, i32** %6
%87 = call i32 @fclose(i32* %86)
%88 = load i8*, i8** %9
%89 = call i32 @free(i8* %88)
%90 = load i32*, i32** %7
%91 = call i32 @fclose(i32* %90)
store i32 0, i32* %3
br label %92
92: ; preds = %63, %61, %26, %17
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"wb\00"
@.str.3 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@str = [23 x i8] c"generate the final fw.\00"
@str.6 = [16 x i8] c"no rootfs file!\00"
@str.7 = [16 x i8] c"no uImage file!\00"
@str.8 = [23 x i8] c"can not open the file.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%4 = getelementptr inbounds i8*, i8** %1, i64 3
%5 = load i8*, i8** %4
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.8, i64 0, i64 0))
br label %54
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
br label %54
17: ; preds = %10
%18 = load i32, i32* @SEEK_END
%19 = tail call i32 @fseek(i32* %13, i32 0, i32 %18)
%20 = tail call i32 @ftell(i32* %13)
%21 = load i32, i32* @SEEK_SET
%22 = tail call i32 @fseek(i32* %13, i32 0, i32 %21)
%23 = tail call i64 @malloc(i32 3932160)
%24 = inttoptr i64 %23 to i8*
%25 = tail call i32 @memset(i8* %24, i32 255, i32 3932160)
%26 = tail call i32 @fread(i8* %24, i32 1, i32 %20, i32* %13)
%27 = load i32, i32* @SEEK_SET
%28 = tail call i32 @fseek(i32* %6, i32 0, i32 %27)
%29 = tail call i32 @fwrite(i8* %24, i32 1, i32 3932160, i32* %6)
%30 = tail call i32 @fclose(i32* %13)
%31 = tail call i32 @free(i8* %24)
%32 = getelementptr inbounds i8*, i8** %1, i64 2
%33 = load i8*, i8** %32
%34 = tail call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %38
36: ; preds = %17
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.6, i64 0, i64 0))
br label %54
38: ; preds = %17
%39 = load i32, i32* @SEEK_END
%40 = tail call i32 @fseek(i32* %34, i32 0, i32 %39)
%41 = tail call i32 @ftell(i32* %34)
%42 = load i32, i32* @SEEK_SET
%43 = tail call i32 @fseek(i32* %34, i32 0, i32 %42)
%44 = tail call i64 @malloc(i32 12582912)
%45 = inttoptr i64 %44 to i8*
%46 = tail call i32 @memset(i8* %45, i32 255, i32 12582912)
%47 = tail call i32 @fread(i8* %45, i32 1, i32 %41, i32* %34)
%48 = load i32, i32* @SEEK_SET
%49 = tail call i32 @fseek(i32* %6, i32 3932160, i32 %48)
%50 = tail call i32 @fwrite(i8* %45, i32 1, i32 12582912, i32* %6)
%51 = tail call i32 @fclose(i32* %34)
%52 = tail call i32 @free(i8* %45)
%53 = tail call i32 @fclose(i32* %6)
br label %54
54: ; preds = %38, %36, %15, %8
%55 = phi i32 [ 1, %8 ], [ 1, %15 ], [ 1, %36 ], [ 0, %38 ]
ret i32 %55
}