#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, unsigned long,
                         int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char **argv) {
  printf("zImage-dtb generator by Munjeni @ XDA 2014\n\n");
  if (argc != 4) {
    printf("Syntax: kernel_dt ZIMAGE DT_IMAGE ZIMAGE_DTB_OUT\n\n");
    return 1;
  }
  FILE *dt, *dtout, *zimage, *zimage_dtb;
  int find_result = 0;
  char temp[11];
  char *fname_zimage = argv[1];
  char *fname_zimage_dtb = argv[3];
  char *fname_dt = argv[2];
  char *fname_dt_out = "/tmp/dtb_segment";
  unsigned long int last_address = 0;
  char dt_tmp[3];
  unsigned long int dt_address = 0;
  char buff[1];
  if ((dt = fopen(fname_dt, "r")) == NULL) {
    printf("unable to open %s for reading!\n", fname_dt);
    return 1;
  }
  while (fread(temp, 1, 11, dt) != 0) {
    if (temp[0] == 0x8 && temp[1] == 0 && temp[2] == 0 && temp[3] == 0 &&
        temp[4] == 0x2 && temp[5] == 0 && temp[6] == 0x2 && temp[7] == 0) {
      find_result++;
      dt_tmp[0] = temp[10];
      dt_tmp[1] = temp[9];
      dt_tmp[2] = temp[8];
    }
    if (find_result)
      goto found;
    last_address += 1;
    fseek(dt, last_address, SEEK_SET);
  }
  if (dt)
    fclose(dt);
  if (!find_result) {
    printf("\nError, couldn't find a dt segment in %s!\n", fname_dt);
    return 1;
  }
found:
  last_address += 8;
  dt_address = dt_tmp[0] * 0x10000;
  dt_address += dt_tmp[1] * 0x100;
  dt_address += dt_tmp[2];
  printf("found tag at: 0x%08lx\n", last_address);
  printf("dt address: 0x%08lx\n", dt_address);
  printf("dumping dt segment from %s ...\n", argv[2]);
  if ((dtout = fopen(fname_dt_out, "w")) == NULL) {
    printf("unable to open %s for writing!\n", fname_dt_out);
    return 1;
  }
  fseek(dt, dt_address, SEEK_SET);
  while (fread(buff, 1, 1, dt) != 0) {
    fwrite(buff, 1, 1, dtout);
    dt_address += 1;
    fseek(dt, dt_address, SEEK_SET);
  }
  if (dt)
    fclose(dt);
  if (dtout)
    fclose(dtout);
  printf("%s created tempoorary\n", fname_dt_out);
  printf("making %s ...\n", argv[3]);
  if ((zimage = fopen(fname_zimage, "r")) == NULL) {
    printf("unable to open %s for reading!\n", fname_zimage);
    unlink(fname_dt_out);
    return 1;
  }
  if ((zimage_dtb = fopen(fname_zimage_dtb, "w")) == NULL) {
    printf("unable to open %s for writing!\n", fname_zimage_dtb);
    if (zimage)
      fclose(zimage);
    unlink(fname_dt_out);
    return 1;
  }
  if ((dtout = fopen(fname_dt_out, "r")) == NULL) {
    printf("unable to open %s for reading!\n", fname_dt_out);
    if (zimage)
      fclose(zimage);
    if (zimage_dtb)
      fclose(zimage_dtb);
    unlink(fname_dt_out);
    unlink(fname_zimage_dtb);
    return 1;
  }
  while (fread(buff, 1, 1, zimage) != 0) {
    fwrite(buff, 1, 1, zimage_dtb);
  }
  while (fread(buff, 1, 1, dtout) != 0) {
    fwrite(buff, 1, 1, zimage_dtb);
  }
  if (zimage)
    fclose(zimage);
  if (zimage_dtb)
    fclose(zimage_dtb);
  if (dtout)
    fclose(dtout);
  unlink(fname_dt_out);
  printf("%s removed\nFile %s created sucesfully!", fname_dt_out, argv[3]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x4,-0x8(%rbp)
je     11bb <main+0x4b>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16bb <main+0x54b>
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x58(%rbp)
lea    0xe73(%rip),%rax
mov    %rax,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x78(%rbp)
mov    -0x58(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    123d <main+0xcd>
mov    -0x58(%rbp),%rsi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16bb <main+0x54b>
jmp    1242 <main+0xd2>
lea    -0x3f(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0xb,%edx
call   1040 <fread@plt>
cmp    $0x0,%rax
je     131c <main+0x1ac>
movsbl -0x3f(%rbp),%eax
cmp    $0x8,%eax
jne    12e6 <main+0x176>
movsbl -0x3e(%rbp),%eax
cmp    $0x0,%eax
jne    12e6 <main+0x176>
movsbl -0x3d(%rbp),%eax
cmp    $0x0,%eax
jne    12e6 <main+0x176>
movsbl -0x3c(%rbp),%eax
cmp    $0x0,%eax
jne    12e6 <main+0x176>
movsbl -0x3b(%rbp),%eax
cmp    $0x2,%eax
jne    12e6 <main+0x176>
movsbl -0x3a(%rbp),%eax
cmp    $0x0,%eax
jne    12e6 <main+0x176>
movsbl -0x39(%rbp),%eax
cmp    $0x2,%eax
jne    12e6 <main+0x176>
movsbl -0x38(%rbp),%eax
cmp    $0x0,%eax
jne    12e6 <main+0x176>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x35(%rbp),%al
mov    %al,-0x6b(%rbp)
mov    -0x36(%rbp),%al
mov    %al,-0x6a(%rbp)
mov    -0x37(%rbp),%al
mov    %al,-0x69(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     12f5 <main+0x185>
jmp    135d <main+0x1ed>
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    0x2cd0(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
jmp    1242 <main+0xd2>
cmpq   $0x0,-0x18(%rbp)
je     1330 <main+0x1c0>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x0,-0x34(%rbp)
jne    1358 <main+0x1e8>
mov    -0x58(%rbp),%rsi
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16bb <main+0x54b>
jmp    135d <main+0x1ed>
mov    -0x68(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x68(%rbp)
movsbl -0x6b(%rbp),%eax
shl    $0x10,%eax
cltq
mov    %rax,-0x78(%rbp)
movsbl -0x6a(%rbp),%eax
shl    $0x8,%eax
cltq
add    -0x78(%rbp),%rax
mov    %rax,-0x78(%rbp)
movsbq -0x69(%rbp),%rax
add    -0x78(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x68(%rbp),%rsi
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x78(%rbp),%rsi
lea    0xd24(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd23(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x60(%rbp),%rdi
lea    0xd31(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    140a <main+0x29a>
mov    -0x60(%rbp),%rsi
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16bb <main+0x54b>
mov    -0x18(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    0x2bc7(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
lea    -0x79(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
cmp    $0x0,%rax
je     1479 <main+0x309>
lea    -0x79(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1090 <fwrite@plt>
mov    -0x78(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x78(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    0x2b73(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
jmp    1420 <main+0x2b0>
cmpq   $0x0,-0x18(%rbp)
je     148d <main+0x31d>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     14a1 <main+0x331>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x60(%rbp),%rsi
lea    0xc80(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xc81(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x48(%rbp),%rdi
lea    0xb9d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    150e <main+0x39e>
mov    -0x48(%rbp),%rsi
lea    0xb81(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x60(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x1,-0x4(%rbp)
jmp    16bb <main+0x54b>
mov    -0x50(%rbp),%rdi
lea    0xbf1(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1567 <main+0x3f7>
mov    -0x50(%rbp),%rsi
lea    0xbd5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     1552 <main+0x3e2>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x60(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x1,-0x4(%rbp)
jmp    16bb <main+0x54b>
mov    -0x60(%rbp),%rdi
lea    0xaff(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    15dd <main+0x46d>
mov    -0x60(%rbp),%rsi
lea    0xae3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     15ab <main+0x43b>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x30(%rbp)
je     15bf <main+0x44f>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x60(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x50(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x1,-0x4(%rbp)
jmp    16bb <main+0x54b>
jmp    15e2 <main+0x472>
lea    -0x79(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
cmp    $0x0,%rax
je     1619 <main+0x4a9>
lea    -0x79(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1090 <fwrite@plt>
jmp    15e2 <main+0x472>
jmp    161e <main+0x4ae>
lea    -0x79(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
cmp    $0x0,%rax
je     1655 <main+0x4e5>
lea    -0x79(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1090 <fwrite@plt>
jmp    161e <main+0x4ae>
cmpq   $0x0,-0x28(%rbp)
je     1669 <main+0x4f9>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x30(%rbp)
je     167d <main+0x50d>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     1691 <main+0x521>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x60(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x60(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xaa5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xf7f(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x4,%ebx
jne    127f <main+0xff>
mov    0x8(%rbp),%r15
mov    0x10(%rbp),%r12
mov    0x18(%rbp),%r14
lea    0xe56(%rip),%rsi
mov    %r12,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     128d <main+0x10d>
mov    %rax,%rbx
mov    %r12,0x30(%rsp)
mov    %r15,0x28(%rsp)
mov    %r14,0x20(%rsp)
mov    %rbp,0x18(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x1,%ebp
mov    $0x1,%esi
mov    $0xb,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     1262 <main+0xe2>
mov    $0x8,%r14d
movabs $0x2000200000008,%r13
mov    0x2dc5(%rip),%r12
lea    0x8(%rsp),%r15
movq   0x8(%rsp),%xmm0
movq   %xmm0,%rax
cmp    %r13,%rax
je     12b4 <main+0x134>
lea    -0x7(%r14),%rsi
mov    (%r12),%edx
mov    %rbx,%rdi
call   1090 <fseek@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0xb,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
add    $0x1,%r14
test   %rax,%rax
jne    1220 <main+0xa0>
mov    %rbx,%rdi
call   1060 <fclose@plt>
lea    0xdc2(%rip),%rdi
mov    0x30(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12a3 <main+0x123>
lea    0xebf(%rip),%rdi
call   1040 <puts@plt>
jmp    129e <main+0x11e>
lea    0xd7f(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movsbq 0x12(%rsp),%rax
movsbq 0x11(%rsp),%rbp
movsbq 0x10(%rsp),%r15
shl    $0x10,%rax
shl    $0x8,%rbp
add    %rax,%rbp
lea    (%r15,%rbp,1),%r13
lea    0xd82(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd88(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x18(%rsp),%rax
mov    0x10(%rax),%rsi
lea    0xd83(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xceb(%rip),%rdi
lea    0xd8e(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     152a <main+0x3aa>
mov    %rax,%r14
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <fseek@plt>
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     13aa <main+0x22a>
add    %r15,%rbp
add    $0x1,%rbp
lea    0x7(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0x7(%rsp),%edi
mov    %r14,%rsi
call   1080 <fputc@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <fseek@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    1370 <main+0x1f0>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
lea    0xd0b(%rip),%rdi
lea    0xc38(%rip),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x18(%rsp),%r15
mov    0x18(%r15),%rsi
lea    0xd04(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xc24(%rip),%rsi
mov    0x28(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     153d <main+0x3bd>
mov    %rax,%r13
lea    0xc9d(%rip),%rsi
mov    0x20(%rsp),%r14
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1550 <main+0x3d0>
mov    %rax,%rbx
lea    0xbd3(%rip),%rdi
lea    0xbdd(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1572 <main+0x3f2>
mov    %rax,%rbp
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     1497 <main+0x317>
lea    0x7(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
movsbl 0x7(%rsp),%edi
mov    %rbx,%rsi
call   1080 <fputc@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1050 <fread@plt>
test   %rax,%rax
jne    1470 <main+0x2f0>
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     14e7 <main+0x367>
lea    0x7(%rsp),%r14
nopl   0x0(%rax,%rax,1)
movsbl 0x7(%rsp),%edi
mov    %rbx,%rsi
call   1080 <fputc@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1050 <fread@plt>
test   %rax,%rax
jne    14c0 <main+0x340>
mov    %r13,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
lea    0xafa(%rip),%rbx
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    0x18(%r15),%rdx
lea    0xbd9(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12a3 <main+0x123>
lea    0xb7b(%rip),%rdi
lea    0xac8(%rip),%rsi
jmp    1297 <main+0x117>
lea    0xacf(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1569 <main+0x3e9>
lea    0xb55(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
call   1060 <fclose@plt>
lea    0xa90(%rip),%rdi
jmp    15a5 <main+0x425>
lea    0xa9a(%rip),%rdi
lea    0xa80(%rip),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %rbp,%rdi
call   1030 <unlink@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
jmp    129e <main+0x11e>

LLVM IR (-O0):
@.str = [45 x i8] c"zImage-dtb generator by Munjeni @ XDA 2014\0A\0A\00"
@.str.1 = [51 x i8] c"Syntax: kernel_dt ZIMAGE DT_IMAGE ZIMAGE_DTB_OUT\0A\0A\00"
@.str.2 = [17 x i8] c"/tmp/dtb_segment\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [32 x i8] c"unable to open %s for reading!\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [43 x i8] c"\0AError, couldn't find a dt segment in %s!\0A\00"
@.str.6 = [23 x i8] c"found tag at: 0x%08lx\0A\00"
@.str.7 = [21 x i8] c"dt address: 0x%08lx\0A\00"
@.str.8 = [32 x i8] c"dumping dt segment from %s ...\0A\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [32 x i8] c"unable to open %s for writing!\0A\00"
@.str.11 = [23 x i8] c"%s created tempoorary\0A\00"
@.str.12 = [15 x i8] c"making %s ...\0A\00"
@.str.13 = [39 x i8] c"%s removed\0AFile %s created sucesfully!\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 i32*
%10 = alloca i32
%11 = alloca [11 x i8]
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i64
%17 = alloca [3 x i8]
%18 = alloca i64
%19 = alloca [1 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 4
br i1 %22, label %23, label %25
23: ; preds = %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %288
25: ; preds = %2
store i32 0, i32* %10
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %12
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 3
%31 = load i8*, i8** %30
store i8* %31, i8** %13
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
store i8* %34, i8** %14
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %15
store i64 0, i64* %16
store i64 0, i64* %18
%35 = load i8*, i8** %14
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %36, i32** %6
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %41
38: ; preds = %25
%39 = load i8*, i8** %14
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %39)
store i32 1, i32* %3
br label %288
41: ; preds = %25
br label %42
42: ; preds = %103, %41
%43 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 0
%44 = load i32*, i32** %6
%45 = call i64 @fread(i8* %43, i32 1, i32 11, i32* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %110
47: ; preds = %42
%48 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 8
br i1 %51, label %52, label %99
52: ; preds = %47
%53 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 1
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %99
57: ; preds = %52
%58 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 2
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %99
62: ; preds = %57
%63 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 3
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %99
67: ; preds = %62
%68 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 4
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 2
br i1 %71, label %72, label %99
72: ; preds = %67
%73 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 5
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %99
77: ; preds = %72
%78 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 6
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp eq i32 %80, 2
br i1 %81, label %82, label %99
82: ; preds = %77
%83 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 7
%84 = load i8, i8* %83
%85 = sext i8 %84 to i32
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %99
87: ; preds = %82
%88 = load i32, i32* %10
%89 = add nsw i32 %88, 1
store i32 %89, i32* %10
%90 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 10
%91 = load i8, i8* %90
%92 = getelementptr inbounds [3 x i8], [3 x i8]* %17, i64 0, i64 0
store i8 %91, i8* %92
%93 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 9
%94 = load i8, i8* %93
%95 = getelementptr inbounds [3 x i8], [3 x i8]* %17, i64 0, i64 1
store i8 %94, i8* %95
%96 = getelementptr inbounds [11 x i8], [11 x i8]* %11, i64 0, i64 8
%97 = load i8, i8* %96
%98 = getelementptr inbounds [3 x i8], [3 x i8]* %17, i64 0, i64 2
store i8 %97, i8* %98
br label %99
99: ; preds = %87, %82, %77, %72, %67, %62, %57, %52, %47
%100 = load i32, i32* %10
%101 = icmp ne i32 %100, 0
br i1 %101, label %102, label %103
102: ; preds = %99
br label %123
103: ; preds = %99
%104 = load i64, i64* %16
%105 = add i64 %104, 1
store i64 %105, i64* %16
%106 = load i32*, i32** %6
%107 = load i64, i64* %16
%108 = load i32, i32* @SEEK_SET
%109 = call i32 @fseek(i32* %106, i64 %107, i32 %108)
br label %42
110: ; preds = %42
%111 = load i32*, i32** %6
%112 = icmp ne i32* %111, null
br i1 %112, label %113, label %116
113: ; preds = %110
%114 = load i32*, i32** %6
%115 = call i32 @fclose(i32* %114)
br label %116
116: ; preds = %113, %110
%117 = load i32, i32* %10
%118 = icmp ne i32 %117, 0
br i1 %118, label %122, label %119
119: ; preds = %116
%120 = load i8*, i8** %14
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %120)
store i32 1, i32* %3
br label %288
122: ; preds = %116
br label %123
123: ; preds = %122, %102
%124 = load i64, i64* %16
%125 = add i64 %124, 8
store i64 %125, i64* %16
%126 = getelementptr inbounds [3 x i8], [3 x i8]* %17, i64 0, i64 0
%127 = load i8, i8* %126
%128 = sext i8 %127 to i32
%129 = mul nsw i32 %128, 65536
%130 = sext i32 %129 to i64
store i64 %130, i64* %18
%131 = getelementptr inbounds [3 x i8], [3 x i8]* %17, i64 0, i64 1
%132 = load i8, i8* %131
%133 = sext i8 %132 to i32
%134 = mul nsw i32 %133, 256
%135 = sext i32 %134 to i64
%136 = load i64, i64* %18
%137 = add i64 %136, %135
store i64 %137, i64* %18
%138 = getelementptr inbounds [3 x i8], [3 x i8]* %17, i64 0, i64 2
%139 = load i8, i8* %138
%140 = sext i8 %139 to i64
%141 = load i64, i64* %18
%142 = add i64 %141, %140
store i64 %142, i64* %18
%143 = load i64, i64* %16
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i64 %143)
%145 = load i64, i64* %18
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i64 %145)
%147 = load i8**, i8*** %5
%148 = getelementptr inbounds i8*, i8** %147, i64 2
%149 = load i8*, i8** %148
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i8* %149)
%151 = load i8*, i8** %15
%152 = call i32* @fopen(i8* %151, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %152, i32** %7
%153 = icmp eq i32* %152, null
br i1 %153, label %154, label %157
154: ; preds = %123
%155 = load i8*, i8** %15
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i8* %155)
store i32 1, i32* %3
br label %288
157: ; preds = %123
%158 = load i32*, i32** %6
%159 = load i64, i64* %18
%160 = load i32, i32* @SEEK_SET
%161 = call i32 @fseek(i32* %158, i64 %159, i32 %160)
br label %162
162: ; preds = %167, %157
%163 = getelementptr inbounds [1 x i8], [1 x i8]* %19, i64 0, i64 0
%164 = load i32*, i32** %6
%165 = call i64 @fread(i8* %163, i32 1, i32 1, i32* %164)
%166 = icmp ne i64 %165, 0
br i1 %166, label %167, label %177
167: ; preds = %162
%168 = getelementptr inbounds [1 x i8], [1 x i8]* %19, i64 0, i64 0
%169 = load i32*, i32** %7
%170 = call i32 @fwrite(i8* %168, i32 1, i32 1, i32* %169)
%171 = load i64, i64* %18
%172 = add i64 %171, 1
store i64 %172, i64* %18
%173 = load i32*, i32** %6
%174 = load i64, i64* %18
%175 = load i32, i32* @SEEK_SET
%176 = call i32 @fseek(i32* %173, i64 %174, i32 %175)
br label %162
177: ; preds = %162
%178 = load i32*, i32** %6
%179 = icmp ne i32* %178, null
br i1 %179, label %180, label %183
180: ; preds = %177
%181 = load i32*, i32** %6
%182 = call i32 @fclose(i32* %181)
br label %183
183: ; preds = %180, %177
%184 = load i32*, i32** %7
%185 = icmp ne i32* %184, null
br i1 %185, label %186, label %189
186: ; preds = %183
%187 = load i32*, i32** %7
%188 = call i32 @fclose(i32* %187)
br label %189
189: ; preds = %186, %183
%190 = load i8*, i8** %15
%191 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0), i8* %190)
%192 = load i8**, i8*** %5
%193 = getelementptr inbounds i8*, i8** %192, i64 3
%194 = load i8*, i8** %193
%195 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i8* %194)
%196 = load i8*, i8** %12
%197 = call i32* @fopen(i8* %196, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %197, i32** %8
%198 = icmp eq i32* %197, null
br i1 %198, label %199, label %204
199: ; preds = %189
%200 = load i8*, i8** %12
%201 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %200)
%202 = load i8*, i8** %15
%203 = call i32 @unlink(i8* %202)
store i32 1, i32* %3
br label %288
204: ; preds = %189
%205 = load i8*, i8** %13
%206 = call i32* @fopen(i8* %205, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %206, i32** %9
%207 = icmp eq i32* %206, null
br i1 %207, label %208, label %219
208: ; preds = %204
%209 = load i8*, i8** %13
%210 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i8* %209)
%211 = load i32*, i32** %8
%212 = icmp ne i32* %211, null
br i1 %212, label %213, label %216
213: ; preds = %208
%214 = load i32*, i32** %8
%215 = call i32 @fclose(i32* %214)
br label %216
216: ; preds = %213, %208
%217 = load i8*, i8** %15
%218 = call i32 @unlink(i8* %217)
store i32 1, i32* %3
br label %288
219: ; preds = %204
%220 = load i8*, i8** %15
%221 = call i32* @fopen(i8* %220, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %221, i32** %7
%222 = icmp eq i32* %221, null
br i1 %222, label %223, label %242
223: ; preds = %219
%224 = load i8*, i8** %15
%225 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %224)
%226 = load i32*, i32** %8
%227 = icmp ne i32* %226, null
br i1 %227, label %228, label %231
228: ; preds = %223
%229 = load i32*, i32** %8
%230 = call i32 @fclose(i32* %229)
br label %231
231: ; preds = %228, %223
%232 = load i32*, i32** %9
%233 = icmp ne i32* %232, null
br i1 %233, label %234, label %237
234: ; preds = %231
%235 = load i32*, i32** %9
%236 = call i32 @fclose(i32* %235)
br label %237
237: ; preds = %234, %231
%238 = load i8*, i8** %15
%239 = call i32 @unlink(i8* %238)
%240 = load i8*, i8** %13
%241 = call i32 @unlink(i8* %240)
store i32 1, i32* %3
br label %288
242: ; preds = %219
br label %243
243: ; preds = %248, %242
%244 = getelementptr inbounds [1 x i8], [1 x i8]* %19, i64 0, i64 0
%245 = load i32*, i32** %8
%246 = call i64 @fread(i8* %244, i32 1, i32 1, i32* %245)
%247 = icmp ne i64 %246, 0
br i1 %247, label %248, label %252
248: ; preds = %243
%249 = getelementptr inbounds [1 x i8], [1 x i8]* %19, i64 0, i64 0
%250 = load i32*, i32** %9
%251 = call i32 @fwrite(i8* %249, i32 1, i32 1, i32* %250)
br label %243
252: ; preds = %243
br label %253
253: ; preds = %258, %252
%254 = getelementptr inbounds [1 x i8], [1 x i8]* %19, i64 0, i64 0
%255 = load i32*, i32** %7
%256 = call i64 @fread(i8* %254, i32 1, i32 1, i32* %255)
%257 = icmp ne i64 %256, 0
br i1 %257, label %258, label %262
258: ; preds = %253
%259 = getelementptr inbounds [1 x i8], [1 x i8]* %19, i64 0, i64 0
%260 = load i32*, i32** %9
%261 = call i32 @fwrite(i8* %259, i32 1, i32 1, i32* %260)
br label %253
262: ; preds = %253
%263 = load i32*, i32** %8
%264 = icmp ne i32* %263, null
br i1 %264, label %265, label %268
265: ; preds = %262
%266 = load i32*, i32** %8
%267 = call i32 @fclose(i32* %266)
br label %268
268: ; preds = %265, %262
%269 = load i32*, i32** %9
%270 = icmp ne i32* %269, null
br i1 %270, label %271, label %274
271: ; preds = %268
%272 = load i32*, i32** %9
%273 = call i32 @fclose(i32* %272)
br label %274
274: ; preds = %271, %268
%275 = load i32*, i32** %7
%276 = icmp ne i32* %275, null
br i1 %276, label %277, label %280
277: ; preds = %274
%278 = load i32*, i32** %7
%279 = call i32 @fclose(i32* %278)
br label %280
280: ; preds = %277, %274
%281 = load i8*, i8** %15
%282 = call i32 @unlink(i8* %281)
%283 = load i8*, i8** %15
%284 = load i8**, i8*** %5
%285 = getelementptr inbounds i8*, i8** %284, i64 3
%286 = load i8*, i8** %285
%287 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.13, i64 0, i64 0), i8* %283, i8* %286)
store i32 0, i32* %3
br label %288
288: ; preds = %280, %237, %216, %199, %154, %119, %38, %23
%289 = load i32, i32* %3
ret i32 %289
}

LLVM IR (-O2):
@.str.2 = [17 x i8] c"/tmp/dtb_segment\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [32 x i8] c"unable to open %s for reading!\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [43 x i8] c"\0AError, couldn't find a dt segment in %s!\0A\00"
@.str.6 = [23 x i8] c"found tag at: 0x%08lx\0A\00"
@.str.7 = [21 x i8] c"dt address: 0x%08lx\0A\00"
@.str.8 = [32 x i8] c"dumping dt segment from %s ...\0A\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [32 x i8] c"unable to open %s for writing!\0A\00"
@.str.11 = [23 x i8] c"%s created tempoorary\0A\00"
@.str.12 = [15 x i8] c"making %s ...\0A\00"
@.str.13 = [39 x i8] c"%s removed\0AFile %s created sucesfully!\00"
@str = [44 x i8] c"zImage-dtb generator by Munjeni @ XDA 2014\0A\00"
@str.14 = [50 x i8] c"Syntax: kernel_dt ZIMAGE DT_IMAGE ZIMAGE_DTB_OUT\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [11 x i8]
%4 = alloca [1 x i8]
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%6 = icmp eq i32 %0, 4
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.14, i64 0, i64 0))
br label %135
9: ; preds = %2
%10 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%18 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %25, label %20
20: ; preds = %9
%21 = call i64 @fread(i8* %10, i32 1, i32 11, i32* %18)
%22 = icmp eq i64 %21, 0
br i1 %22, label %39, label %23
23: ; preds = %20
%24 = bitcast [11 x i8]* %3 to <8 x i8>*
br label %27
25: ; preds = %9
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %16)
br label %133
27: ; preds = %23, %33
%28 = phi i64 [ 0, %23 ], [ %34, %33 ]
%29 = load <8 x i8>, <8 x i8>* %24
%30 = freeze <8 x i8> %29
%31 = bitcast <8 x i8> %30 to i64
%32 = icmp eq i64 %31, 562958543355912
br i1 %32, label %42, label %33
33: ; preds = %27
%34 = add i64 %28, 1
%35 = load i32, i32* @SEEK_SET
%36 = tail call i32 @fseek(i32* %18, i64 %34, i32 %35)
%37 = call i64 @fread(i8* %10, i32 1, i32 11, i32* %18)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %27
39: ; preds = %33, %20
%40 = tail call i32 @fclose(i32* %18)
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %16)
br label %133
42: ; preds = %27
%43 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 10
%44 = load i8, i8* %43
%45 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 9
%46 = load i8, i8* %45
%47 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 8
%48 = load i8, i8* %47
%49 = add i64 %28, 8
%50 = sext i8 %44 to i32
%51 = shl nsw i32 %50, 16
%52 = sext i8 %46 to i32
%53 = shl nsw i32 %52, 8
%54 = add nsw i32 %53, %51
%55 = sext i32 %54 to i64
%56 = sext i8 %48 to i64
%57 = add nsw i64 %55, %56
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i64 %49)
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i64 %57)
%60 = load i8*, i8** %15
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i8* %60)
%62 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%63 = icmp eq i32* %62, null
br i1 %63, label %64, label %66
64: ; preds = %42
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %133
66: ; preds = %42
%67 = load i32, i32* @SEEK_SET
%68 = tail call i32 @fseek(i32* %18, i64 %57, i32 %67)
%69 = call i64 @fread(i8* %17, i32 1, i32 1, i32* %18)
%70 = icmp eq i64 %69, 0
br i1 %70, label %81, label %71
71: ; preds = %66, %71
%72 = phi i64 [ %76, %71 ], [ %57, %66 ]
%73 = load i8, i8* %17
%74 = sext i8 %73 to i32
%75 = tail call i32 @fputc(i32 %74, i32* %62)
%76 = add i64 %72, 1
%77 = load i32, i32* @SEEK_SET
%78 = tail call i32 @fseek(i32* %18, i64 %76, i32 %77)
%79 = call i64 @fread(i8* %17, i32 1, i32 1, i32* %18)
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %71
81: ; preds = %71, %66
%82 = tail call i32 @fclose(i32* %18)
%83 = tail call i32 @fclose(i32* %62)
%84 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%85 = load i8*, i8** %13
%86 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i8* %85)
%87 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%88 = icmp eq i32* %87, null
br i1 %88, label %89, label %92
89: ; preds = %81
%90 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%91 = tail call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %133
92: ; preds = %81
%93 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%94 = icmp eq i32* %93, null
br i1 %94, label %95, label %99
95: ; preds = %92
%96 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i8* %14)
%97 = tail call i32 @fclose(i32* %87)
%98 = tail call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %133
99: ; preds = %92
%100 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%101 = icmp eq i32* %100, null
br i1 %101, label %105, label %102
102: ; preds = %99
%103 = call i64 @fread(i8* %17, i32 1, i32 1, i32* %87)
%104 = icmp eq i64 %103, 0
br i1 %104, label %111, label %114
105: ; preds = %99
%106 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%107 = tail call i32 @fclose(i32* %87)
%108 = tail call i32 @fclose(i32* %93)
%109 = tail call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%110 = tail call i32 @unlink(i8* %14)
br label %133
111: ; preds = %114, %102
%112 = call i64 @fread(i8* %17, i32 1, i32 1, i32* %100)
%113 = icmp eq i64 %112, 0
br i1 %113, label %126, label %120
114: ; preds = %102, %114
%115 = load i8, i8* %17
%116 = sext i8 %115 to i32
%117 = tail call i32 @fputc(i32 %116, i32* %93)
%118 = call i64 @fread(i8* %17, i32 1, i32 1, i32* %87)
%119 = icmp eq i64 %118, 0
br i1 %119, label %111, label %114
120: ; preds = %111, %120
%121 = load i8, i8* %17
%122 = sext i8 %121 to i32
%123 = tail call i32 @fputc(i32 %122, i32* %93)
%124 = call i64 @fread(i8* %17, i32 1, i32 1, i32* %100)
%125 = icmp eq i64 %124, 0
br i1 %125, label %126, label %120
126: ; preds = %120, %111
%127 = tail call i32 @fclose(i32* %87)
%128 = tail call i32 @fclose(i32* %93)
%129 = tail call i32 @fclose(i32* %100)
%130 = tail call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%131 = load i8*, i8** %13
%132 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %131)
br label %133
133: ; preds = %126, %105, %95, %89, %64, %39, %25
%134 = phi i32 [ 1, %25 ], [ 1, %64 ], [ 1, %89 ], [ 1, %95 ], [ 1, %105 ], [ 0, %126 ], [ 1, %39 ]
br label %135
135: ; preds = %133, %7
%136 = phi i32 [ 1, %7 ], [ %134, %133 ]
ret i32 %136
}