#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 */
struct stat {
  unsigned long st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
unsigned char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ mkstemp(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ rename(char *, char *);
scalar_t__ stat(char *, struct stat *);
void main(int argc, char *argv[]) {
  FILE *fp1;
  FILE *fp2;
  char tmpFilename[50] = "packbin.XXXXXX";
  unsigned long imgSize;
  unsigned long padTo;
  struct stat fileStat;
  int i;
  unsigned char ch;
  unsigned char *pch;
  unsigned char chksum;
  unsigned int tmp;
  for (i = 0; i < argc; i++)
    printf("arg[%d]:%s\n", argc, argv[i]);
  if (argc != 4) {
    printf("Usage: kfspad rootfs kernel_file output_file\n");
    printf(
        "    rootfs        Name of the root file system binary image file\n");
    printf("    kernel_file   Name of the kernel binary image file.\n");
    printf("    output_file   Name of the output binary image file.\n");
    return;
  }
  if ((fp1 = fopen(argv[1], "r+b")) == 0) {
    printf("Cannot open %s !!\n", argv[1]);
    return;
  }
  if (stat(argv[1], &fileStat) != 0) {
    printf("Cannot get file statistics !!\n");
    fclose(fp1);
    exit(-1);
  }
  imgSize = fileStat.st_size;
  printf("Root File System Image Size = 0x%lx %d\n", imgSize, imgSize);
  mkstemp(tmpFilename);
  if ((fp2 = fopen(tmpFilename, "w+b")) == 0) {
    printf("Cannot open temprary file !!\n");
    return;
  }
  fseek(fp1, 0L, SEEK_SET);
  chksum = 0;
  for (i = 0; i < imgSize; i++) {
    ch = fgetc(fp1);
    fputc(ch, fp2);
  }
  close(fp1);
  padTo = (16 - (imgSize & 0x0F)) & 0x0F;
  i = 0;
  while (i++ < padTo)
    fputc(0, fp2);
  if ((fp1 = fopen(argv[2], "r+b")) == 0) {
    printf("Cannot open %s !!\n", argv[2]);
    return;
  }
  if (stat(argv[2], &fileStat) != 0) {
    printf("Cannot get file statistics !!\n");
    fclose(fp1);
    exit(-1);
  }
  imgSize = fileStat.st_size;
  printf("Kernel Image Size = 0x%lx %d\n", imgSize, imgSize);
  for (i = 0; i < imgSize; i++) {
    ch = fgetc(fp1);
    fputc(ch, fp2);
  }
  fclose(fp1);
  fclose(fp2);
  printf("Binary image %s generated!\n", argv[3]);
  remove(argv[3]);
  rename(tmpFilename, argv[3]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe13(%rip),%rsi
mov    $0x32,%edx
call   10a0 <memcpy@plt>
movl   $0x0,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1235 <main+0x65>
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x7c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    11fe <main+0x2e>
cmpl   $0x4,-0x4(%rbp)
je     127c <main+0xac>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1512 <main+0x342>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe95(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    12b9 <main+0xe9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1512 <main+0x342>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x78(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%rax
je     12f5 <main+0x125>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x78(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rsi
mov    -0x68(%rbp),%rdx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
call   10b0 <mkstemp@plt>
lea    -0x60(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    134d <main+0x17d>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1512 <main+0x342>
mov    -0x18(%rbp),%rdi
mov    0x2c88(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <fseek@plt>
movb   $0x0,-0x89(%rbp)
movl   $0x0,-0x7c(%rbp)
movslq -0x7c(%rbp),%rax
cmp    -0x68(%rbp),%rax
jae    13a8 <main+0x1d8>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x7d(%rbp)
mov    -0x7d(%rbp),%al
mov    -0x20(%rbp),%rsi
movzbl %al,%edi
call   1080 <fputc@plt>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    1371 <main+0x1a1>
mov    -0x18(%rbp),%rdi
call   1070 <close@plt>
mov    -0x68(%rbp),%rcx
and    $0xf,%rcx
mov    $0x10,%eax
sub    %rcx,%rax
and    $0xf,%rax
mov    %rax,-0x70(%rbp)
movl   $0x0,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x7c(%rbp)
cltq
cmp    -0x70(%rbp),%rax
jae    13f7 <main+0x227>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1080 <fputc@plt>
jmp    13d0 <main+0x200>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd1a(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1434 <main+0x264>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xcfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1512 <main+0x342>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x78(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%rax
je     1470 <main+0x2a0>
lea    0xce1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x78(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rsi
mov    -0x68(%rbp),%rdx
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x7c(%rbp)
movslq -0x7c(%rbp),%rax
cmp    -0x68(%rbp),%rax
jae    14cc <main+0x2fc>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x7d(%rbp)
mov    -0x7d(%rbp),%al
mov    -0x20(%rbp),%rsi
movzbl %al,%edi
call   1080 <fputc@plt>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    1495 <main+0x2c5>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xcd1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <remove@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   10e0 <rename@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
movaps 0xe3d(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe21(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe05(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movw   $0x0,0x40(%rsp)
test   %edi,%edi
jle    13d4 <main+0x204>
mov    %rsi,%r15
mov    %edi,%r12d
mov    %edi,%ebx
lea    0xe14(%rip),%r14
xor    %ebp,%ebp
mov    (%r15,%rbp,8),%rdx
mov    %r14,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1220 <main+0x50>
cmp    $0x4,%r12d
jne    13d4 <main+0x204>
mov    0x8(%r15),%rdi
lea    0xdef(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%r12
mov    0x8(%r15),%rax
test   %r12,%r12
je     1410 <main+0x240>
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   10a0 <stat@plt>
test   %rax,%rax
jne    1459 <main+0x289>
mov    0x8(%rsp),%rbp
lea    0xdcf(%rip),%rdi
mov    %rbp,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   10b0 <mkstemp@plt>
lea    0xdd6(%rip),%rsi
mov    %r14,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     142d <main+0x25d>
mov    %rax,%r14
mov    0x2d1e(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
test   %rbp,%rbp
je     12f9 <main+0x129>
mov    %rbp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1070 <fgetc@plt>
movzbl %al,%edi
mov    %r14,%rsi
call   1090 <fputc@plt>
add    $0xffffffffffffffff,%rbx
jne    12e0 <main+0x110>
mov    %r12,%rdi
call   1080 <close@plt>
neg    %ebp
and    $0xf,%rbp
je     1320 <main+0x150>
nopl   0x0(%rax)
xor    %edi,%edi
mov    %r14,%rsi
call   1090 <fputc@plt>
add    $0xffffffffffffffff,%rbp
jne    1310 <main+0x140>
mov    0x10(%r15),%rdi
lea    0xd13(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%r12
mov    0x10(%r15),%rax
test   %r12,%r12
je     143b <main+0x26b>
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   10a0 <stat@plt>
test   %rax,%rax
jne    1459 <main+0x289>
mov    0x8(%rsp),%rbx
lea    0xd1f(%rip),%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
test   %rbx,%rbx
je     1399 <main+0x1c9>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
call   1070 <fgetc@plt>
movzbl %al,%edi
mov    %r14,%rsi
call   1090 <fputc@plt>
add    $0xffffffffffffffff,%rbx
jne    1380 <main+0x1b0>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    0x18(%r15),%rsi
lea    0xceb(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%r15),%rdi
call   1030 <remove@plt>
mov    0x18(%r15),%rsi
lea    0x10(%rsp),%rdi
call   10e0 <rename@plt>
jmp    144c <main+0x27c>
lea    0xd1b(%rip),%rdi
call   1040 <puts@plt>
lea    0xd3c(%rip),%rdi
call   1040 <puts@plt>
lea    0xd71(%rip),%rdi
call   1040 <puts@plt>
lea    0xd9d(%rip),%rdi
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
lea    0xc2b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <printf@plt>
lea    0xc87(%rip),%rdi
call   1040 <puts@plt>
jmp    144c <main+0x27c>
lea    0xc00(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc78(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@__const.main.tmpFilename = [50 x i8] c"packbin.XXXXXX\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [12 x i8] c"arg[%d]:%s\0A\00"
@.str.1 = [46 x i8] c"Usage: kfspad rootfs kernel_file output_file\0A\00"
@.str.2 = [66 x i8] c" rootfs Name of the root file system binary image file\0A\00"
@.str.3 = [57 x i8] c" kernel_file Name of the kernel binary image file.\0A\00"
@.str.4 = [57 x i8] c" output_file Name of the output binary image file.\0A\00"
@.str.5 = [4 x i8] c"r+b\00"
@.str.6 = [19 x i8] c"Cannot open %s !!\0A\00"
@.str.7 = [31 x i8] c"Cannot get file statistics !!\0A\00"
@.str.8 = [40 x i8] c"Root File System Image Size = 0x%lx %d\0A\00"
@.str.9 = [4 x i8] c"w+b\00"
@.str.10 = [30 x i8] c"Cannot open temprary file !!\0A\00"
@SEEK_SET = global i32 0
@.str.11 = [30 x i8] c"Kernel Image Size = 0x%lx %d\0A\00"
@.str.12 = [28 x i8] c"Binary image %s generated!\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [50 x i8]
%8 = alloca i64
%9 = alloca i64
%10 = alloca %struct.stat
%11 = alloca i32
%12 = alloca i8
%13 = alloca i8*
%14 = alloca i8
%15 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%16 = bitcast [50 x i8]* %7 to i8*
store i32 0, i32* %11
br label %17
17: ; preds = %29, %2
%18 = load i32, i32* %11
%19 = load i32, i32* %3
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %32
21: ; preds = %17
%22 = load i32, i32* %3
%23 = load i8**, i8*** %4
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %22, i8* %27)
br label %29
29: ; preds = %21
%30 = load i32, i32* %11
%31 = add nsw i32 %30, 1
store i32 %31, i32* %11
br label %17
32: ; preds = %17
%33 = load i32, i32* %3
%34 = icmp ne i32 %33, 4
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0))
br label %169
40: ; preds = %32
%41 = load i8**, i8*** %4
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32* @fopen(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store i32* %44, i32** %5
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %51
46: ; preds = %40
%47 = load i8**, i8*** %4
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %49)
br label %169
51: ; preds = %40
%52 = load i8**, i8*** %4
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = call i64 @stat(i8* %54, %struct.stat* %10)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %51
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%59 = load i32*, i32** %5
%60 = call i32 @fclose(i32* %59)
%61 = call i32 @exit(i32 -1)
unreachable
62: ; preds = %51
%63 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%64 = load i64, i64* %63
store i64 %64, i64* %8
%65 = load i64, i64* %8
%66 = load i64, i64* %8
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), i64 %65, i64 %66)
%68 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%69 = call i32 @mkstemp(i8* %68)
%70 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%71 = call i32* @fopen(i8* %70, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
store i32* %71, i32** %6
%72 = icmp eq i32* %71, null
br i1 %72, label %73, label %75
73: ; preds = %62
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0))
br label %169
75: ; preds = %62
%76 = load i32*, i32** %5
%77 = load i32, i32* @SEEK_SET
%78 = call i32 @fseek(i32* %76, i64 0, i32 %77)
store i8 0, i8* %14
store i32 0, i32* %11
br label %79
79: ; preds = %90, %75
%80 = load i32, i32* %11
%81 = sext i32 %80 to i64
%82 = load i64, i64* %8
%83 = icmp ult i64 %81, %82
br i1 %83, label %84, label %93
84: ; preds = %79
%85 = load i32*, i32** %5
%86 = call zeroext i8 @fgetc(i32* %85)
store i8 %86, i8* %12
%87 = load i8, i8* %12
%88 = load i32*, i32** %6
%89 = call i32 @fputc(i8 zeroext %87, i32* %88)
br label %90
90: ; preds = %84
%91 = load i32, i32* %11
%92 = add nsw i32 %91, 1
store i32 %92, i32* %11
br label %79
93: ; preds = %79
%94 = load i32*, i32** %5
%95 = call i32 @close(i32* %94)
%96 = load i64, i64* %8
%97 = and i64 %96, 15
%98 = sub i64 16, %97
%99 = and i64 %98, 15
store i64 %99, i64* %9
store i32 0, i32* %11
br label %100
100: ; preds = %106, %93
%101 = load i32, i32* %11
%102 = add nsw i32 %101, 1
store i32 %102, i32* %11
%103 = sext i32 %101 to i64
%104 = load i64, i64* %9
%105 = icmp ult i64 %103, %104
br i1 %105, label %106, label %109
106: ; preds = %100
%107 = load i32*, i32** %6
%108 = call i32 @fputc(i8 zeroext 0, i32* %107)
br label %100
109: ; preds = %100
%110 = load i8**, i8*** %4
%111 = getelementptr inbounds i8*, i8** %110, i64 2
%112 = load i8*, i8** %111
%113 = call i32* @fopen(i8* %112, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store i32* %113, i32** %5
%114 = icmp eq i32* %113, null
br i1 %114, label %115, label %120
115: ; preds = %109
%116 = load i8**, i8*** %4
%117 = getelementptr inbounds i8*, i8** %116, i64 2
%118 = load i8*, i8** %117
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %118)
br label %169
120: ; preds = %109
%121 = load i8**, i8*** %4
%122 = getelementptr inbounds i8*, i8** %121, i64 2
%123 = load i8*, i8** %122
%124 = call i64 @stat(i8* %123, %struct.stat* %10)
%125 = icmp ne i64 %124, 0
br i1 %125, label %126, label %131
126: ; preds = %120
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%128 = load i32*, i32** %5
%129 = call i32 @fclose(i32* %128)
%130 = call i32 @exit(i32 -1)
unreachable
131: ; preds = %120
%132 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%133 = load i64, i64* %132
store i64 %133, i64* %8
%134 = load i64, i64* %8
%135 = load i64, i64* %8
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0), i64 %134, i64 %135)
store i32 0, i32* %11
br label %137
137: ; preds = %148, %131
%138 = load i32, i32* %11
%139 = sext i32 %138 to i64
%140 = load i64, i64* %8
%141 = icmp ult i64 %139, %140
br i1 %141, label %142, label %151
142: ; preds = %137
%143 = load i32*, i32** %5
%144 = call zeroext i8 @fgetc(i32* %143)
store i8 %144, i8* %12
%145 = load i8, i8* %12
%146 = load i32*, i32** %6
%147 = call i32 @fputc(i8 zeroext %145, i32* %146)
br label %148
148: ; preds = %142
%149 = load i32, i32* %11
%150 = add nsw i32 %149, 1
store i32 %150, i32* %11
br label %137
151: ; preds = %137
%152 = load i32*, i32** %5
%153 = call i32 @fclose(i32* %152)
%154 = load i32*, i32** %6
%155 = call i32 @fclose(i32* %154)
%156 = load i8**, i8*** %4
%157 = getelementptr inbounds i8*, i8** %156, i64 3
%158 = load i8*, i8** %157
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0), i8* %158)
%160 = load i8**, i8*** %4
%161 = getelementptr inbounds i8*, i8** %160, i64 3
%162 = load i8*, i8** %161
%163 = call i32 @remove(i8* %162)
%164 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%165 = load i8**, i8*** %4
%166 = getelementptr inbounds i8*, i8** %165, i64 3
%167 = load i8*, i8** %166
%168 = call i32 @rename(i8* %164, i8* %167)
br label %169
169: ; preds = %151, %115, %73, %46, %35
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@__const.main.tmpFilename = [50 x i8] c"packbin.XXXXXX\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [12 x i8] c"arg[%d]:%s\0A\00"
@.str.5 = [4 x i8] c"r+b\00"
@.str.6 = [19 x i8] c"Cannot open %s !!\0A\00"
@.str.8 = [40 x i8] c"Root File System Image Size = 0x%lx %d\0A\00"
@.str.9 = [4 x i8] c"w+b\00"
@SEEK_SET = global i32 0
@.str.11 = [30 x i8] c"Kernel Image Size = 0x%lx %d\0A\00"
@.str.12 = [28 x i8] c"Binary image %s generated!\0A\00"
@str.13 = [29 x i8] c"Cannot open temprary file !!\00"
@str.14 = [30 x i8] c"Cannot get file statistics !!\00"
@str.15 = [45 x i8] c"Usage: kfspad rootfs kernel_file output_file\00"
@str.16 = [65 x i8] c" rootfs Name of the root file system binary image file\00"
@str.17 = [56 x i8] c" kernel_file Name of the kernel binary image file.\00"
@str.18 = [56 x i8] c" output_file Name of the output binary image file.\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca [50 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %15, %10 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %13)
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, %9
br i1 %16, label %17, label %10
17: ; preds = %10
%18 = icmp eq i32 %0, 4
br i1 %18, label %24, label %19
19: ; preds = %2, %17
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.15, i64 0, i64 0))
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str.16, i64 0, i64 0))
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.17, i64 0, i64 0))
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.18, i64 0, i64 0))
br label %103
24: ; preds = %17
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%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
%29 = load i8*, i8** %25
br i1 %28, label %30, label %32
30: ; preds = %24
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %29)
br label %103
32: ; preds = %24
%33 = call i64 @stat(i8* %29, %struct.stat* %4)
%34 = icmp eq i64 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %32
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.14, i64 0, i64 0))
%37 = call i32 @fclose(i32* %27)
%38 = call i32 @exit(i32 -1)
unreachable
39: ; preds = %32
%40 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%41 = load i64, i64* %40
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), i64 %41, i64 %41)
%43 = call i32 @mkstemp(i8* %5)
%44 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.13, i64 0, i64 0))
br label %103
48: ; preds = %39
%49 = load i32, i32* @SEEK_SET
%50 = call i32 @fseek(i32* %27, i64 0, i32 %49)
%51 = icmp eq i64 %41, 0
br i1 %51, label %58, label %52
52: ; preds = %48, %52
%53 = phi i64 [ %56, %52 ], [ 0, %48 ]
%54 = call zeroext i8 @fgetc(i32* %27)
%55 = call i32 @fputc(i8 zeroext %54, i32* %44)
%56 = add nuw i64 %53, 1
%57 = icmp eq i64 %56, %41
br i1 %57, label %58, label %52
58: ; preds = %52, %48
%59 = call i32 @close(i32* %27)
%60 = sub i64 0, %41
%61 = and i64 %60, 15
%62 = icmp eq i64 %61, 0
br i1 %62, label %68, label %63
63: ; preds = %58, %63
%64 = phi i64 [ %65, %63 ], [ 0, %58 ]
%65 = add nuw nsw i64 %64, 1
%66 = call i32 @fputc(i8 zeroext 0, i32* %44)
%67 = icmp eq i64 %65, %61
br i1 %67, label %68, label %63
68: ; preds = %63, %58
%69 = getelementptr inbounds i8*, i8** %1, i64 2
%70 = load i8*, i8** %69
%71 = call i32* @fopen(i8* %70, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%72 = icmp eq i32* %71, null
%73 = load i8*, i8** %69
br i1 %72, label %74, label %76
74: ; preds = %68
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %73)
br label %103
76: ; preds = %68
%77 = call i64 @stat(i8* %73, %struct.stat* %4)
%78 = icmp eq i64 %77, 0
br i1 %78, label %83, label %79
79: ; preds = %76
%80 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.14, i64 0, i64 0))
%81 = call i32 @fclose(i32* %71)
%82 = call i32 @exit(i32 -1)
unreachable
83: ; preds = %76
%84 = load i64, i64* %40
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0), i64 %84, i64 %84)
%86 = icmp eq i64 %84, 0
br i1 %86, label %93, label %87
87: ; preds = %83, %87
%88 = phi i64 [ %91, %87 ], [ 0, %83 ]
%89 = call zeroext i8 @fgetc(i32* %71)
%90 = call i32 @fputc(i8 zeroext %89, i32* %44)
%91 = add nuw i64 %88, 1
%92 = icmp eq i64 %91, %84
br i1 %92, label %93, label %87
93: ; preds = %87, %83
%94 = call i32 @fclose(i32* %71)
%95 = call i32 @fclose(i32* %44)
%96 = getelementptr inbounds i8*, i8** %1, i64 3
%97 = load i8*, i8** %96
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0), i8* %97)
%99 = load i8*, i8** %96
%100 = call i32 @remove(i8* %99)
%101 = load i8*, i8** %96
%102 = call i32 @rename(i8* %5, i8* %101)
br label %103
103: ; preds = %93, %74, %46, %30, %19
ret void
}