#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*/ fget(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ unziper();
int kernelcache() {
  char name[120];
  char buildCommand[1024];
  char key[80];
  char keyiv[80];
  char boardID[10];
  unziper();
  chdir("IPSW");
  printf("Enter the kernel filename : ");
  fget(name, 120);
  printf("Enter the key for %s: ", name);
  fget(key, 80);
  printf("Enter the key IV for %s: ", name);
  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):
<kernelcache>:
push   %rbp
mov    %rsp,%rbp
sub    $0x530,%rsp
mov    $0x0,%al
call   1070 <unziper@plt>
lea    0xe87(%rip),%rdi
call   1030 <chdir@plt>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    $0x78,%esi
call   1060 <fget@plt>
lea    -0x80(%rbp),%rsi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x4d0(%rbp),%rdi
mov    $0x50,%esi
call   1060 <fget@plt>
lea    -0x80(%rbp),%rsi
lea    0xe71(%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    0xe4f(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x480(%rbp),%rdi
call   1040 <system@plt>
lea    -0x80(%rbp),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x530,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernelcache>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x528,%rsp
xor    %eax,%eax
call   1070 <unziper@plt>
lea    0xe84(%rip),%rdi
call   1030 <chdir@plt>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xa0(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x78,%esi
call   1060 <fget@plt>
lea    0xe77(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x50(%rsp),%r14
mov    %r14,%rdi
mov    $0x50,%esi
call   1060 <fget@plt>
lea    0xe6b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x50,%esi
call   1060 <fget@plt>
lea    0xe64(%rip),%rsi
lea    0x120(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rdx
mov    %rbx,%rcx
mov    %r14,%r8
mov    %r15,%r9
call   1080 <sprintf@plt>
mov    %r12,%rdi
call   1040 <system@plt>
lea    0xe65(%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

LLVM IR (-O0):
@.str = [5 x i8] c"IPSW\00"
@.str.1 = [29 x i8] c"Enter the kernel filename : \00"
@.str.2 = [23 x i8] c"Enter the key for %s: \00"
@.str.3 = [26 x i8] c"Enter the key IV for %s: \00"
@.str.4 = [44 x i8] c"..\\bin\\xpwntool IPSW\\%s %s.dec -k %s -iv %s\00"
@.str.5 = [36 x i8] c"%s.dec copied at the folder's root\0A\00"
define i32 @kernelcache() {
%1 = alloca [120 x i8]
%2 = alloca [1024 x i8]
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = alloca [10 x i8]
%6 = call i32 (...) @unziper()
%7 = call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds [120 x i8], [120 x i8]* %1, i64 0, i64 0
%10 = call i32 @fget(i8* %9, i32 120)
%11 = getelementptr inbounds [120 x i8], [120 x i8]* %1, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%14 = call i32 @fget(i8* %13, i32 80)
%15 = getelementptr inbounds [120 x i8], [120 x i8]* %1, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%18 = call i32 @fget(i8* %17, i32 80)
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%20 = getelementptr inbounds [120 x i8], [120 x i8]* %1, i64 0, i64 0
%21 = getelementptr inbounds [120 x i8], [120 x i8]* %1, i64 0, i64 0
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%24 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %20, i8* %21, i8* %22, i8* %23)
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%26 = call i32 @system(i8* %25)
%27 = getelementptr inbounds [120 x i8], [120 x i8]* %1, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"IPSW\00"
@.str.1 = [29 x i8] c"Enter the kernel filename : \00"
@.str.2 = [23 x i8] c"Enter the key for %s: \00"
@.str.3 = [26 x i8] c"Enter the key IV for %s: \00"
@.str.4 = [44 x i8] c"..\\bin\\xpwntool IPSW\\%s %s.dec -k %s -iv %s\00"
@.str.5 = [36 x i8] c"%s.dec copied at the folder's root\0A\00"
define i32 @kernelcache() {
%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 ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @fget(i8* %5, i32 120)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%14 = call i32 @fget(i8* %7, i32 80)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%16 = call i32 @fget(i8* %8, i32 80)
%17 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %5, i8* %5, i8* %7, i8* %8)
%18 = call i32 @system(i8* %6)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %5)
ret i32 0
}