#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 */

/* Variables and functions */
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fget(char *, int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ unziper();
int Ramdisk() {
  char name[120];
  char buildCommand[1024];
  char key[80];
  char keyiv[80];
  unziper();
  chdir("IPSW");
  printf("Enter the Ramdisk name : ");
  fget(name, 120);
  if (fopen(name, "r") == NULL) {
    printf("File %s is missing\n", name);
    exit(1);
  }
  printf("Enter key for Ramdisk : ");
  fget(key, 80);
  printf("Enter the IV key for the Update Ramdisk : ");
  fget(keyiv, 80);
  sprintf(buildCommand, "..\\bin\\xpwntool IPSW\\%s %s.dec -k %s -iv %s ", name,
          name, key, keyiv);
  system(buildCommand);
  printf("%s.dec copied at the folder's root\n", name);
  return 0;
}


x86 assembly (clang, -O0):
<Ramdisk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x520,%rsp
mov    $0x0,%al
call   1080 <unziper@plt>
lea    0xe67(%rip),%rdi
call   1030 <chdir@plt>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    $0x78,%esi
call   1060 <fget@plt>
lea    -0x80(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1070 <fopen@plt>
cmp    $0x0,%rax
jne    11f0 <Ramdisk+0x70>
lea    -0x80(%rbp),%rsi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x4d0(%rbp),%rdi
mov    $0x50,%esi
call   1060 <fget@plt>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x520(%rbp),%rdi
mov    $0x50,%esi
call   1060 <fget@plt>
lea    -0x480(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    -0x80(%rbp),%rcx
lea    -0x4d0(%rbp),%r8
lea    -0x520(%rbp),%r9
lea    0xe27(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x480(%rbp),%rdi
call   1040 <system@plt>
lea    -0x80(%rbp),%rsi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x520,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Ramdisk>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x528,%rsp
xor    %eax,%eax
call   1080 <unziper@plt>
lea    0xe64(%rip),%rdi
call   1030 <chdir@plt>
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x78,%esi
call   1060 <fget@plt>
lea    0xe59(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     126d <Ramdisk+0xed>
lea    0xe57(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd0(%rsp),%r14
mov    %r14,%rdi
mov    $0x50,%esi
call   1060 <fget@plt>
lea    0xe4d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x80(%rsp),%r15
mov    %r15,%rdi
mov    $0x50,%esi
call   1060 <fget@plt>
lea    0xe55(%rip),%rsi
lea    0x120(%rsp),%r12
mov    %rsp,%rbx
mov    %r12,%rdi
mov    %rbx,%rdx
mov    %rbx,%rcx
mov    %r14,%r8
mov    %r15,%r9
call   1090 <sprintf@plt>
mov    %r12,%rdi
call   1040 <system@plt>
lea    0xe54(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x528,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdad(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"IPSW\00"
@.str.1 = [26 x i8] c"Enter the Ramdisk name : \00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [20 x i8] c"File %s is missing\0A\00"
@.str.4 = [25 x i8] c"Enter key for Ramdisk : \00"
@.str.5 = [43 x i8] c"Enter the IV key for the Update Ramdisk : \00"
@.str.6 = [45 x i8] c"..\\bin\\xpwntool IPSW\\%s %s.dec -k %s -iv %s \00"
@.str.7 = [36 x i8] c"%s.dec copied at the folder's root\0A\00"
define i32 @Ramdisk() {
%1 = alloca [120 x i8]
%2 = alloca [1024 x i8]
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = call i32 (...) @unziper()
%6 = call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [120 x i8], [120 x i8]* %1, i64 0, i64 0
%9 = call i32 @fget(i8* %8, i32 120)
%10 = getelementptr inbounds [120 x i8], [120 x i8]* %1, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = getelementptr inbounds [120 x i8], [120 x i8]* %1, i64 0, i64 0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%20 = call i32 @fget(i8* %19, i32 80)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%23 = call i32 @fget(i8* %22, i32 80)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%25 = getelementptr inbounds [120 x i8], [120 x i8]* %1, i64 0, i64 0
%26 = getelementptr inbounds [120 x i8], [120 x i8]* %1, i64 0, i64 0
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%29 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i8* %25, i8* %26, i8* %27, i8* %28)
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%31 = call i32 @system(i8* %30)
%32 = getelementptr inbounds [120 x i8], [120 x i8]* %1, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"IPSW\00"
@.str.1 = [26 x i8] c"Enter the Ramdisk name : \00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [20 x i8] c"File %s is missing\0A\00"
@.str.4 = [25 x i8] c"Enter key for Ramdisk : \00"
@.str.5 = [43 x i8] c"Enter the IV key for the Update Ramdisk : \00"
@.str.6 = [45 x i8] c"..\\bin\\xpwntool IPSW\\%s %s.dec -k %s -iv %s \00"
@.str.7 = [36 x i8] c"%s.dec copied at the folder's root\0A\00"
define i32 @Ramdisk() {
%1 = alloca [120 x i8]
%2 = alloca [1024 x i8]
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = getelementptr inbounds [120 x i8], [120 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%9 = tail call i32 (...) @unziper()
%10 = tail call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @fget(i8* %5, i32 120)
%13 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @fget(i8* %7, i32 80)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%22 = call i32 @fget(i8* %8, i32 80)
%23 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i8* %5, i8* %5, i8* %7, i8* %8)
%24 = call i32 @system(i8* %6)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %5)
ret i32 0
}