#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 EXIT_SUCCESS;
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ fget(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ unziper();
int rootfs() {
  char choice[10];
  char rootfs[80];
  char buildCommand[1024];
  char buildCommand2[1024];
  char key[80];
  char keyiv[80];
  char decrypt[256];
  unziper();
  printf("Entrer rootfs name : ");
  fget(rootfs, 80);
  chdir("IPSW");
  printf("Enter the firmware key : ");
  fget(key, 80);
  sprintf(decrypt, "..\\bin\\dmg.exe extract %s rootfs_decrypt.dmg -k %s",
          rootfs, key);
  system(decrypt);
  printf("Decrypting finished\n");
  sleep(2);
  printf("Do you want to reencrypt the firmware ? \n");
  printf("1) YES\n");
  printf("2) NO\n");
  fget(choice, 10);
  if (strcmp(choice, "yes") == 0 || strcmp(choice, "1") == 0) {
    printf("Building rootfs...\n");
    sprintf(buildCommand2, "%s", rootfs);
    remove(buildCommand2);
    sprintf(buildCommand, "..\\bin\\dmg.exe build rootfs_decrypt.dmg %s",
            rootfs);
    system(buildCommand);
    printf("Compressing IPSW...\n");
    system("..\\bin\\7z.exe u -tzip -mx0 custom_firmware.ipsw -x!7z.exe");
    printf("Your custom firmware has been created\n");
  } else if (strcmp(choice, "no") == 0 || strcmp(choice, "2") == 0) {
    return EXIT_SUCCESS;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rootfs>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa00,%rsp
mov    $0x0,%al
call   1090 <unziper@plt>
lea    0xe57(%rip),%rdi
call   1060 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x50,%esi
call   1070 <fget@plt>
lea    0xe53(%rip),%rdi
call   1040 <chdir@plt>
lea    0xe4c(%rip),%rdi
call   1060 <printf@plt>
lea    -0x8b0(%rbp),%rdi
mov    $0x50,%esi
call   1070 <fget@plt>
lea    -0xa00(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    -0x8b0(%rbp),%rcx
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    -0xa00(%rbp),%rdi
call   1050 <system@plt>
lea    0xe50(%rip),%rdi
call   1060 <printf@plt>
mov    $0x2,%edi
call   10b0 <sleep@plt>
lea    0xe4f(%rip),%rdi
call   1060 <printf@plt>
lea    0xe6d(%rip),%rdi
call   1060 <printf@plt>
lea    0xe69(%rip),%rdi
call   1060 <printf@plt>
lea    -0xe(%rbp),%rdi
mov    $0xa,%esi
call   1070 <fget@plt>
lea    -0xe(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     128d <rootfs+0xfd>
lea    -0xe(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    130c <rootfs+0x17c>
lea    0xe28(%rip),%rdi
call   1060 <printf@plt>
lea    -0x860(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    -0x860(%rbp),%rdi
call   1030 <remove@plt>
lea    -0x460(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    -0x460(%rbp),%rdi
call   1050 <system@plt>
lea    0xe11(%rip),%rdi
call   1060 <printf@plt>
lea    0xe1a(%rip),%rdi
call   1050 <system@plt>
lea    0xe48(%rip),%rdi
call   1060 <printf@plt>
jmp    1356 <rootfs+0x1c6>
lea    -0xe(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1340 <rootfs+0x1b0>
lea    -0xe(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1351 <rootfs+0x1c1>
mov    0x2c99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    135d <rootfs+0x1cd>
jmp    1356 <rootfs+0x1c6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa00,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rootfs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x9b8,%rsp
xor    %r14d,%r14d
xor    %eax,%eax
call   10b0 <unziper@plt>
lea    0xe32(%rip),%rdi
call   1080 <printf@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x50,%esi
call   1090 <fget@plt>
lea    0xe2a(%rip),%rdi
call   1060 <chdir@plt>
lea    0xe23(%rip),%rdi
call   1080 <printf@plt>
lea    0x60(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x50,%esi
call   1090 <fget@plt>
lea    0xe1f(%rip),%rsi
lea    0xb0(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
lea    0xe9b(%rip),%rdi
call   1050 <puts@plt>
mov    $0x2,%edi
call   10d0 <sleep@plt>
lea    0xe99(%rip),%rdi
call   1050 <puts@plt>
lea    0xeb6(%rip),%rdi
call   1050 <puts@plt>
lea    0xeb1(%rip),%rdi
call   1050 <puts@plt>
lea    0x6(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1090 <fget@plt>
lea    0xddf(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     12eb <rootfs+0x13b>
lea    0xdcf(%rip),%rsi
lea    0x6(%rsp),%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     12eb <rootfs+0x13b>
lea    0xe20(%rip),%rsi
lea    0x6(%rsp),%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     12df <rootfs+0x12f>
lea    0xe0d(%rip),%rsi
lea    0x6(%rsp),%rdi
call   10a0 <strcmp@plt>
xor    %r14d,%r14d
test   %rax,%rax
jne    135f <rootfs+0x1af>
mov    0x2cfa(%rip),%rax
mov    (%rax),%r14d
jmp    135f <rootfs+0x1af>
lea    0xe30(%rip),%rdi
call   1050 <puts@plt>
lea    0x1b0(%rsp),%rbx
lea    0x10(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1030 <remove@plt>
lea    0xd50(%rip),%rsi
lea    0x5b0(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
lea    0xdf3(%rip),%rdi
call   1050 <puts@plt>
lea    0xd4b(%rip),%rdi
call   1070 <system@plt>
lea    0xdef(%rip),%rdi
call   1050 <puts@plt>
mov    %r14d,%eax
add    $0x9b8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Entrer rootfs name : \00"
@.str.1 = [5 x i8] c"IPSW\00"
@.str.2 = [26 x i8] c"Enter the firmware key : \00"
@.str.3 = [51 x i8] c"..\\bin\\dmg.exe extract %s rootfs_decrypt.dmg -k %s\00"
@.str.4 = [21 x i8] c"Decrypting finished\0A\00"
@.str.5 = [42 x i8] c"Do you want to reencrypt the firmware ? \0A\00"
@.str.6 = [8 x i8] c"1) YES\0A\00"
@.str.7 = [7 x i8] c"2) NO\0A\00"
@.str.8 = [4 x i8] c"yes\00"
@.str.9 = [2 x i8] c"1\00"
@.str.10 = [20 x i8] c"Building rootfs...\0A\00"
@.str.11 = [3 x i8] c"%s\00"
@.str.12 = [43 x i8] c"..\\bin\\dmg.exe build rootfs_decrypt.dmg %s\00"
@.str.13 = [21 x i8] c"Compressing IPSW...\0A\00"
@.str.14 = [58 x i8] c"..\\bin\\7z.exe u -tzip -mx0 custom_firmware.ipsw -x!7z.exe\00"
@.str.15 = [39 x i8] c"Your custom firmware has been created\0A\00"
@.str.16 = [3 x i8] c"no\00"
@.str.17 = [2 x i8] c"2\00"
@EXIT_SUCCESS = global i32 0
define i32 @rootfs() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca [80 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [80 x i8]
%7 = alloca [80 x i8]
%8 = alloca [256 x i8]
%9 = call i32 (...) @unziper()
%10 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%12 = call i32 @fget(i8* %11, i32 80)
%13 = call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%16 = call i32 @fget(i8* %15, i32 80)
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%20 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i8* %18, i8* %19)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%22 = call i32 @system(i8* %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @sleep(i32 2)
%25 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%27 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%29 = call i32 @fget(i8* %28, i32 10)
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %0
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %52
37: ; preds = %33, %0
%38 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%41 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%43 = call i32 @remove(i8* %42)
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%45 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%46 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %44, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0), i8* %45)
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%48 = call i32 @system(i8* %47)
%49 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0))
%50 = call i32 @system(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.14, i64 0, i64 0))
%51 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.15, i64 0, i64 0))
br label %63
52: ; preds = %33
%53 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %60, label %56
56: ; preds = %52
%57 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%58 = call i64 @strcmp(i8* %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %56, %52
%61 = load i32, i32* @EXIT_SUCCESS
store i32 %61, i32* %1
br label %64
62: ; preds = %56
br label %63
63: ; preds = %62, %37
store i32 0, i32* %1
br label %64
64: ; preds = %63, %60
%65 = load i32, i32* %1
ret i32 %65
}

LLVM IR (-O2):
@.str = [22 x i8] c"Entrer rootfs name : \00"
@.str.1 = [5 x i8] c"IPSW\00"
@.str.2 = [26 x i8] c"Enter the firmware key : \00"
@.str.3 = [51 x i8] c"..\\bin\\dmg.exe extract %s rootfs_decrypt.dmg -k %s\00"
@.str.8 = [4 x i8] c"yes\00"
@.str.9 = [2 x i8] c"1\00"
@.str.12 = [43 x i8] c"..\\bin\\dmg.exe build rootfs_decrypt.dmg %s\00"
@.str.14 = [58 x i8] c"..\\bin\\7z.exe u -tzip -mx0 custom_firmware.ipsw -x!7z.exe\00"
@.str.16 = [3 x i8] c"no\00"
@.str.17 = [2 x i8] c"2\00"
@EXIT_SUCCESS = global i32 0
@str = [20 x i8] c"Decrypting finished\00"
@str.18 = [41 x i8] c"Do you want to reencrypt the firmware ? \00"
@str.19 = [7 x i8] c"1) YES\00"
@str.20 = [6 x i8] c"2) NO\00"
@str.21 = [19 x i8] c"Building rootfs...\00"
@str.22 = [20 x i8] c"Compressing IPSW...\00"
@str.23 = [38 x i8] c"Your custom firmware has been created\00"
define i32 @rootfs() {
%1 = alloca [10 x i8]
%2 = alloca [80 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [80 x i8]
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%13 = tail call i32 (...) @unziper()
%14 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @fget(i8* %8, i32 80)
%16 = call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @fget(i8* %11, i32 80)
%19 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i8* %8, i8* %11)
%20 = call i32 @system(i8* %12)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%22 = call i32 @sleep(i32 2)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.18, i64 0, i64 0))
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.19, i64 0, i64 0))
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.20, i64 0, i64 0))
%26 = call i32 @fget(i8* %7, i32 10)
%27 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %0
%30 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %29, %0
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.21, i64 0, i64 0))
%34 = call i8* @strcpy(i8* %10, i8* %8)
%35 = call i32 @remove(i8* %10)
%36 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0), i8* %8)
%37 = call i32 @system(i8* %9)
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.22, i64 0, i64 0))
%39 = call i32 @system(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.14, i64 0, i64 0))
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.23, i64 0, i64 0))
br label %49
41: ; preds = %29
%42 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %44, %41
%48 = load i32, i32* @EXIT_SUCCESS
br label %49
49: ; preds = %32, %44, %47
%50 = phi i32 [ %48, %47 ], [ 0, %44 ], [ 0, %32 ]
ret i32 %50
}