#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;
unsigned long atoi(unsigned char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, unsigned long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
size_t fwrite(unsigned char *, int, unsigned long, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int scan_file_for_data(char *, unsigned char **, int, int /*<<< orphan*/,
                       unsigned long *);
int backup_recovery_ramdisk(char *bootimage, unsigned long start_location,
                            char *outputimage) {
  FILE *bFile;
  FILE *rFile;
  FILE *oFile;
  unsigned long blSize, offset_table, ramdisk_len;
  unsigned char *bbuffer;
  size_t result;
  unsigned char ramdisk_lens[4], *p;
  int return_val, i;
  printf("Reading the original boot image...\n");
  bFile = fopen(bootimage, "rb");
  if (bFile == NULL) {
    printf("Unabled to open original boot image '%s'.\nFailed\n", bootimage);
    exit(0);
  }
  fseek(bFile, 0, SEEK_END);
  blSize = ftell(bFile);
  rewind(bFile);
  printf("Size of original boot is %lu\n", blSize);
  bbuffer = (unsigned char *)malloc(sizeof(unsigned char) * blSize);
  if (bbuffer == NULL) {
    printf("File read error on original boot image '%s'!\nFailed\n", bootimage);
    exit(0);
  }
  result = fread(bbuffer, 1, blSize, bFile);
  if (result != blSize) {
    printf("Error reading original boot image '%s'\nFailed\n", bootimage);
    exit(0);
  }
  unsigned char needle[13] = "recovery_len=";
  return_val = scan_file_for_data(bootimage, &needle, 13, 0, &offset_table);
  if (return_val < 0) {
    fclose(bFile);
    printf("Ramdisk offset table not found in %s!\nFailed\n", bootimage);
    exit(0);
  }
  printf("Ramdisk offset table found at 0x%08x\n", offset_table);
  for (i = 0; i < 4; i++) {
    p = bbuffer + offset_table + i;
    if (*p == ';') {
      ramdisk_lens[i] = 0;
    } else {
      ramdisk_lens[i] = *p;
    }
  }
  ramdisk_len = atoi(ramdisk_lens);
  ramdisk_len *= 512;
  printf("Ramdisk length: %lu\n", ramdisk_len);
  printf("Opening the output image for writing...\n");
  oFile = fopen(outputimage, "wb");
  if (oFile == NULL) {
    printf("Unabled to open output image '%s'.\nFailed\n", outputimage);
    exit(0);
  }
  printf("Writing backup ramdisk...\n");
  result = fwrite(bbuffer + start_location, 1, ramdisk_len, oFile);
  if (result != ramdisk_len) {
    printf("Write count does not match! (1)\n");
  } else {
    printf("Finished backing up ramdisk image '%s'\n", outputimage);
  }
  fclose(bFile);
  fclose(oFile);
  free(bbuffer);
  return 1;
}


x86 assembly (clang, -O0):
<backup_recovery_ramdisk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    122d <backup_recovery_ramdisk+0x5d>
mov    -0x8(%rbp),%rsi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2db0(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <rewind@plt>
mov    -0x38(%rbp),%rsi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x38(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    12a0 <backup_recovery_ramdisk+0xd0>
mov    -0x8(%rbp),%rsi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     12e1 <backup_recovery_ramdisk+0x111>
mov    -0x8(%rbp),%rsi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    0xf17(%rip),%rax
mov    %rax,-0x7d(%rbp)
mov    0xf15(%rip),%eax
mov    %eax,-0x75(%rbp)
mov    0xf10(%rip),%al
mov    %al,-0x71(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x7d(%rbp),%rsi
mov    $0xd,%edx
xor    %ecx,%ecx
lea    -0x40(%rbp),%r8
call   1040 <scan_file_for_data@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jge    1345 <backup_recovery_ramdisk+0x175>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x8(%rbp),%rsi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    -0x40(%rbp),%rsi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x70(%rbp)
cmpl   $0x4,-0x70(%rbp)
jge    13ba <backup_recovery_ramdisk+0x1ea>
mov    -0x50(%rbp),%rax
add    -0x40(%rbp),%rax
movslq -0x70(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x3b,%eax
jne    1399 <backup_recovery_ramdisk+0x1c9>
movslq -0x70(%rbp),%rax
movb   $0x0,-0x5c(%rbp,%rax,1)
jmp    13a7 <backup_recovery_ramdisk+0x1d7>
mov    -0x68(%rbp),%rax
mov    (%rax),%cl
movslq -0x70(%rbp),%rax
mov    %cl,-0x5c(%rbp,%rax,1)
jmp    13ac <backup_recovery_ramdisk+0x1dc>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    135e <backup_recovery_ramdisk+0x18e>
lea    -0x5c(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
shl    $0x9,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xd6f(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    142b <backup_recovery_ramdisk+0x25b>
mov    -0x18(%rbp),%rsi
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x50(%rbp),%rdi
add    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
cmp    -0x48(%rbp),%rax
je     1478 <backup_recovery_ramdisk+0x2a8>
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    148a <backup_recovery_ramdisk+0x2ba>
mov    -0x18(%rbp),%rsi
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<backup_recovery_ramdisk>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,%r14
mov    %rdi,%r13
lea    0xf76(%rip),%rdi
call   1050 <puts@plt>
lea    0xdf4(%rip),%rsi
mov    %r13,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     13dd <backup_recovery_ramdisk+0x1fd>
mov    %rax,%r12
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %r12,%rdi
call   10a0 <ftell@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1090 <rewind@plt>
lea    0xde8(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebx,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     13e6 <backup_recovery_ramdisk+0x206>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1060 <fread@plt>
cmp    %rbx,%rax
jne    13ef <backup_recovery_ramdisk+0x20f>
movabs $0x3d6e656c5f797265,%rax
65 6e 3d
mov    %rax,0x1d(%rsp)
movabs $0x797265766f636572,%rax
65 72 79
mov    %rax,0x18(%rsp)
lea    0x18(%rsp),%rsi
xor    %ebx,%ebx
lea    0x8(%rsp),%r8
mov    %r13,%rdi
mov    $0xd,%edx
xor    %ecx,%ecx
call   1040 <scan_file_for_data@plt>
test   %eax,%eax
js     13f8 <backup_recovery_ramdisk+0x218>
mov    0x8(%rsp),%rsi
lea    0xe12(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x8(%rsp),%rax
movzbl (%r15,%rax,1),%ecx
cmp    $0x3b,%cl
cmove  %ebx,%ecx
mov    %cl,0x4(%rsp)
movzbl 0x1(%r15,%rax,1),%ecx
cmp    $0x3b,%cl
cmove  %ebx,%ecx
mov    %cl,0x5(%rsp)
movzbl 0x2(%r15,%rax,1),%ecx
cmp    $0x3b,%cl
cmove  %ebx,%ecx
mov    %cl,0x6(%rsp)
movzbl 0x3(%r15,%rax,1),%eax
cmp    $0x3b,%al
cmove  %ebx,%eax
mov    %al,0x7(%rsp)
lea    0x4(%rsp),%rdi
call   10e0 <atoi@plt>
mov    %rax,%rbp
shl    $0x9,%rbp
lea    0xdd6(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe53(%rip),%rdi
call   1050 <puts@plt>
lea    0xdce(%rip),%rsi
mov    0x10(%rsp),%r13
mov    %r13,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1409 <backup_recovery_ramdisk+0x229>
mov    %rax,%rbx
lea    0xe4f(%rip),%rdi
call   1050 <puts@plt>
mov    %r15,%rdi
add    %r14,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    %rbx,%rcx
call   1100 <fwrite@plt>
cmp    %rbp,%rax
jne    13a5 <backup_recovery_ramdisk+0x1c5>
lea    0xdb5(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    13b1 <backup_recovery_ramdisk+0x1d1>
lea    0xe2f(%rip),%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
call   1070 <fclose@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc1f(%rip),%rdi
jmp    1410 <backup_recovery_ramdisk+0x230>
lea    0xc66(%rip),%rdi
jmp    1410 <backup_recovery_ramdisk+0x230>
lea    0xc92(%rip),%rdi
jmp    1410 <backup_recovery_ramdisk+0x230>
mov    %r12,%rdi
call   1070 <fclose@plt>
lea    0xcb0(%rip),%rdi
jmp    1410 <backup_recovery_ramdisk+0x230>
lea    0xd13(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"Reading the original boot image...\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [50 x i8] c"Unabled to open original boot image '%s'.\0AFailed\0A\00"
@SEEK_END = global i32 0
@.str.3 = [30 x i8] c"Size of original boot is %lu\0A\00"
@.str.4 = [53 x i8] c"File read error on original boot image '%s'!\0AFailed\0A\00"
@.str.5 = [47 x i8] c"Error reading original boot image '%s'\0AFailed\0A\00"
@__const.backup_recovery_ramdisk.needle = [13 x i8] c"recovery_len="
@.str.6 = [46 x i8] c"Ramdisk offset table not found in %s!\0AFailed\0A\00"
@.str.7 = [38 x i8] c"Ramdisk offset table found at 0x%08x\0A\00"
@.str.8 = [21 x i8] c"Ramdisk length: %lu\0A\00"
@.str.9 = [41 x i8] c"Opening the output image for writing...\0A\00"
@.str.10 = [3 x i8] c"wb\00"
@.str.11 = [43 x i8] c"Unabled to open output image '%s'.\0AFailed\0A\00"
@.str.12 = [27 x i8] c"Writing backup ramdisk...\0A\00"
@.str.13 = [33 x i8] c"Write count does not match! (1)\0A\00"
@.str.14 = [40 x i8] c"Finished backing up ramdisk image '%s'\0A\00"
define i32 @backup_recovery_ramdisk(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i64
%15 = alloca [4 x i8]
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32
%19 = alloca [13 x i8]
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%21 = load i8*, i8** %4
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %7
%23 = load i32*, i32** %7
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %29
25: ; preds = %3
%26 = load i8*, i8** %4
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %3
%30 = load i32*, i32** %7
%31 = load i32, i32* @SEEK_END
%32 = call i32 @fseek(i32* %30, i32 0, i32 %31)
%33 = load i32*, i32** %7
%34 = call i64 @ftell(i32* %33)
store i64 %34, i64* %10
%35 = load i32*, i32** %7
%36 = call i32 @rewind(i32* %35)
%37 = load i64, i64* %10
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i64 %37)
%39 = load i64, i64* %10
%40 = mul i64 1, %39
%41 = trunc i64 %40 to i32
%42 = call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to i8*
store i8* %43, i8** %13
%44 = load i8*, i8** %13
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %50
46: ; preds = %29
%47 = load i8*, i8** %4
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%49 = call i32 @exit(i32 0)
unreachable
50: ; preds = %29
%51 = load i8*, i8** %13
%52 = load i64, i64* %10
%53 = load i32*, i32** %7
%54 = call i64 @fread(i8* %51, i32 1, i64 %52, i32* %53)
store i64 %54, i64* %14
%55 = load i64, i64* %14
%56 = load i64, i64* %10
%57 = icmp ne i64 %55, %56
br i1 %57, label %58, label %62
58: ; preds = %50
%59 = load i8*, i8** %4
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i8* %59)
%61 = call i32 @exit(i32 0)
unreachable
62: ; preds = %50
%63 = bitcast [13 x i8]* %19 to i8*
%64 = load i8*, i8** %4
%65 = bitcast [13 x i8]* %19 to i8**
%66 = call i32 @scan_file_for_data(i8* %64, i8** %65, i32 13, i32 0, i64* %11)
store i32 %66, i32* %17
%67 = load i32, i32* %17
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %75
69: ; preds = %62
%70 = load i32*, i32** %7
%71 = call i32 @fclose(i32* %70)
%72 = load i8*, i8** %4
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), i8* %72)
%74 = call i32 @exit(i32 0)
unreachable
75: ; preds = %62
%76 = load i64, i64* %11
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i64 %76)
store i32 0, i32* %18
br label %78
78: ; preds = %103, %75
%79 = load i32, i32* %18
%80 = icmp slt i32 %79, 4
br i1 %80, label %81, label %106
81: ; preds = %78
%82 = load i8*, i8** %13
%83 = load i64, i64* %11
%84 = getelementptr inbounds i8, i8* %82, i64 %83
%85 = load i32, i32* %18
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %84, i64 %86
store i8* %87, i8** %16
%88 = load i8*, i8** %16
%89 = load i8, i8* %88
%90 = zext i8 %89 to i32
%91 = icmp eq i32 %90, 59
br i1 %91, label %92, label %96
92: ; preds = %81
%93 = load i32, i32* %18
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 %94
store i8 0, i8* %95
br label %102
96: ; preds = %81
%97 = load i8*, i8** %16
%98 = load i8, i8* %97
%99 = load i32, i32* %18
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 %100
store i8 %98, i8* %101
br label %102
102: ; preds = %96, %92
br label %103
103: ; preds = %102
%104 = load i32, i32* %18
%105 = add nsw i32 %104, 1
store i32 %105, i32* %18
br label %78
106: ; preds = %78
%107 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 0
%108 = call i64 @atoi(i8* %107)
store i64 %108, i64* %12
%109 = load i64, i64* %12
%110 = mul i64 %109, 512
store i64 %110, i64* %12
%111 = load i64, i64* %12
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i64 %111)
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0))
%114 = load i8*, i8** %6
%115 = call i32* @fopen(i8* %114, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
store i32* %115, i32** %9
%116 = load i32*, i32** %9
%117 = icmp eq i32* %116, null
br i1 %117, label %118, label %122
118: ; preds = %106
%119 = load i8*, i8** %6
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.11, i64 0, i64 0), i8* %119)
%121 = call i32 @exit(i32 0)
unreachable
122: ; preds = %106
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0))
%124 = load i8*, i8** %13
%125 = load i64, i64* %5
%126 = getelementptr inbounds i8, i8* %124, i64 %125
%127 = load i64, i64* %12
%128 = load i32*, i32** %9
%129 = call i64 @fwrite(i8* %126, i32 1, i64 %127, i32* %128)
store i64 %129, i64* %14
%130 = load i64, i64* %14
%131 = load i64, i64* %12
%132 = icmp ne i64 %130, %131
br i1 %132, label %133, label %135
133: ; preds = %122
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.13, i64 0, i64 0))
br label %138
135: ; preds = %122
%136 = load i8*, i8** %6
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0), i8* %136)
br label %138
138: ; preds = %135, %133
%139 = load i32*, i32** %7
%140 = call i32 @fclose(i32* %139)
%141 = load i32*, i32** %9
%142 = call i32 @fclose(i32* %141)
%143 = load i8*, i8** %13
%144 = call i32 @free(i8* %143)
ret i32 1
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [50 x i8] c"Unabled to open original boot image '%s'.\0AFailed\0A\00"
@SEEK_END = global i32 0
@.str.3 = [30 x i8] c"Size of original boot is %lu\0A\00"
@.str.4 = [53 x i8] c"File read error on original boot image '%s'!\0AFailed\0A\00"
@.str.5 = [47 x i8] c"Error reading original boot image '%s'\0AFailed\0A\00"
@__const.backup_recovery_ramdisk.needle = [13 x i8] c"recovery_len="
@.str.6 = [46 x i8] c"Ramdisk offset table not found in %s!\0AFailed\0A\00"
@.str.7 = [38 x i8] c"Ramdisk offset table found at 0x%08x\0A\00"
@.str.8 = [21 x i8] c"Ramdisk length: %lu\0A\00"
@.str.10 = [3 x i8] c"wb\00"
@.str.11 = [43 x i8] c"Unabled to open output image '%s'.\0AFailed\0A\00"
@.str.14 = [40 x i8] c"Finished backing up ramdisk image '%s'\0A\00"
@str = [35 x i8] c"Reading the original boot image...\00"
@str.15 = [40 x i8] c"Opening the output image for writing...\00"
@str.16 = [26 x i8] c"Writing backup ramdisk...\00"
@str.17 = [32 x i8] c"Write count does not match! (1)\00"
define i32 @backup_recovery_ramdisk(i8* %0, i64 %1, i8* %2) {
%4 = alloca i64
%5 = alloca [4 x i8]
%6 = alloca [13 x i8]
%7 = bitcast i64* %4 to i8*
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %3
%16 = load i32, i32* @SEEK_END
%17 = tail call i32 @fseek(i32* %10, i32 0, i32 %16)
%18 = tail call i64 @ftell(i32* %10)
%19 = tail call i32 @rewind(i32* %10)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i64 %18)
%21 = trunc i64 %18 to i32
%22 = tail call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = icmp eq i64 %22, 0
br i1 %24, label %25, label %28
25: ; preds = %15
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%27 = tail call i32 @exit(i32 0)
unreachable
28: ; preds = %15
%29 = tail call i64 @fread(i8* %23, i32 1, i64 %18, i32* %10)
%30 = icmp eq i64 %29, %18
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%33 = tail call i32 @exit(i32 0)
unreachable
34: ; preds = %28
%35 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%36 = bitcast [13 x i8]* %6 to i8**
%37 = call i32 @scan_file_for_data(i8* %0, i8** %36, i32 13, i32 0, i64* %4)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = call i32 @fclose(i32* %10)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), i8* %0)
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %34
%44 = load i64, i64* %4
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i64 %44)
%46 = load i64, i64* %4
%47 = getelementptr inbounds i8, i8* %23, i64 %46
%48 = load i8, i8* %47
%49 = icmp eq i8 %48, 59
%50 = select i1 %49, i8 0, i8 %48
store i8 %50, i8* %8
%51 = getelementptr inbounds i8, i8* %47, i64 1
%52 = load i8, i8* %51
%53 = icmp eq i8 %52, 59
%54 = select i1 %53, i8 0, i8 %52
%55 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
store i8 %54, i8* %55
%56 = getelementptr inbounds i8, i8* %47, i64 2
%57 = load i8, i8* %56
%58 = icmp eq i8 %57, 59
%59 = select i1 %58, i8 0, i8 %57
%60 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
store i8 %59, i8* %60
%61 = getelementptr inbounds i8, i8* %47, i64 3
%62 = load i8, i8* %61
%63 = icmp eq i8 %62, 59
%64 = select i1 %63, i8 0, i8 %62
%65 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
store i8 %64, i8* %65
%66 = call i64 @atoi(i8* %8)
%67 = shl i64 %66, 9
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i64 %67)
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.15, i64 0, i64 0))
%70 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%71 = icmp eq i32* %70, null
br i1 %71, label %72, label %75
72: ; preds = %43
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.11, i64 0, i64 0), i8* %2)
%74 = call i32 @exit(i32 0)
unreachable
75: ; preds = %43
%76 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.16, i64 0, i64 0))
%77 = getelementptr inbounds i8, i8* %23, i64 %1
%78 = call i64 @fwrite(i8* %77, i32 1, i64 %67, i32* %70)
%79 = icmp eq i64 %78, %67
br i1 %79, label %82, label %80
80: ; preds = %75
%81 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.17, i64 0, i64 0))
br label %84
82: ; preds = %75
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0), i8* %2)
br label %84
84: ; preds = %82, %80
%85 = call i32 @fclose(i32* %10)
%86 = call i32 @fclose(i32* %70)
%87 = call i32 @free(i8* %23)
ret i32 1
}