#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*/ ECANCELED;
int /*<<< orphan*/ ENOENT;
int /*<<< orphan*/ ENOMEM;
int asprintf(char **, char *, char const *, char const *);
int /*<<< orphan*/ errno;
int fail(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int system(char *);
int unzip(const char *targetdir, const char *zipfile) {
  int status;
  char *command;
  status = asprintf(&command, "unzip -n -qq -d '%s' '%s'", targetdir, zipfile);
  if (status < 0)
    return fail(ENOMEM, NULL);
  status = system(command);
  free(command);
  switch (status) {
  case -1:
    return fail(errno, "Can't excute unzip");
  case 0:
  case 1:
    return 0;
  case 4:
  case 5:
  case 6:
  case 7:
    return fail(ENOMEM, NULL);
  case 9:
    return fail(ENOENT, "File to unzip doesn't exist: %s", zipfile);
  default:
    return fail(ECANCELED, "Error while unziping %s to %s", zipfile, targetdir);
  }
}


x86 assembly (clang, -O0):
<unzip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    0xec9(%rip),%rsi
call   1060 <asprintf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1191 <unzip+0x51>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x0,%al
call   1040 <fail@plt>
mov    %eax,-0x4(%rbp)
jmp    125b <unzip+0x11b>
mov    -0x28(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0xa,%eax
ja     1239 <unzip+0xf9>
mov    -0x30(%rbp),%rax
lea    0xe3a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1040 <fail@plt>
mov    %eax,-0x4(%rbp)
jmp    125b <unzip+0x11b>
movl   $0x0,-0x4(%rbp)
jmp    125b <unzip+0x11b>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x0,%al
call   1040 <fail@plt>
mov    %eax,-0x4(%rbp)
jmp    125b <unzip+0x11b>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1040 <fail@plt>
mov    %eax,-0x4(%rbp)
jmp    125b <unzip+0x11b>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1040 <fail@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unzip>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xed6(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1060 <asprintf@plt>
test   %eax,%eax
js     119a <unzip+0x5a>
mov    0x8(%rsp),%rdi
call   1050 <system@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x1,%ebx
cmp    $0xa,%ebx
ja     11c8 <unzip+0x88>
xor    %eax,%eax
lea    0xe6f(%rip),%rcx
movslq (%rcx,%rbx,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <fail@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
jmp    11a5 <unzip+0x65>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xea1(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1040 <fail@plt>
jmp    11ac <unzip+0x6c>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fail@plt>
jmp    11ac <unzip+0x6c>

LLVM IR (-O0):
@.str = [26 x i8] c"unzip -n -qq -d '%s' '%s'\00"
@ENOMEM = global i32 0
@errno = global i32 0
@.str.1 = [19 x i8] c"Can't excute unzip\00"
@ENOENT = global i32 0
@.str.2 = [32 x i8] c"File to unzip doesn't exist: %s\00"
@ECANCELED = global i32 0
@.str.3 = [30 x i8] c"Error while unziping %s to %s\00"
define i32 @unzip(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = call i32 @asprintf(i8** %7, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @ENOMEM
%15 = call i32 (i32, i8*, ...) @fail(i32 %14, i8* null)
store i32 %15, i32* %3
br label %38
16: ; preds = %2
%17 = load i8*, i8** %7
%18 = call i32 @system(i8* %17)
store i32 %18, i32* %6
%19 = load i8*, i8** %7
%20 = call i32 @free(i8* %19)
%21 = load i32, i32* %6
switch i32 %21, label %33 [
i32 -1, label %22
i32 0, label %25
i32 1, label %25
i32 4, label %26
i32 5, label %26
i32 6, label %26
i32 7, label %26
i32 9, label %29
]
22: ; preds = %16
%23 = load i32, i32* @errno
%24 = call i32 (i32, i8*, ...) @fail(i32 %23, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 %24, i32* %3
br label %38
25: ; preds = %16, %16
store i32 0, i32* %3
br label %38
26: ; preds = %16, %16, %16, %16
%27 = load i32, i32* @ENOMEM
%28 = call i32 (i32, i8*, ...) @fail(i32 %27, i8* null)
store i32 %28, i32* %3
br label %38
29: ; preds = %16
%30 = load i32, i32* @ENOENT
%31 = load i8*, i8** %5
%32 = call i32 (i32, i8*, ...) @fail(i32 %30, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %31)
store i32 %32, i32* %3
br label %38
33: ; preds = %16
%34 = load i32, i32* @ECANCELED
%35 = load i8*, i8** %5
%36 = load i8*, i8** %4
%37 = call i32 (i32, i8*, ...) @fail(i32 %34, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %35, i8* %36)
store i32 %37, i32* %3
br label %38
38: ; preds = %33, %29, %26, %25, %22, %13
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [26 x i8] c"unzip -n -qq -d '%s' '%s'\00"
@ENOMEM = global i32 0
@errno = global i32 0
@.str.1 = [19 x i8] c"Can't excute unzip\00"
@ENOENT = global i32 0
@.str.2 = [32 x i8] c"File to unzip doesn't exist: %s\00"
@ECANCELED = global i32 0
@.str.3 = [30 x i8] c"Error while unziping %s to %s\00"
define i32 @unzip(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @ENOMEM
%9 = call i32 (i32, i8*, ...) @fail(i32 %8, i8* null)
br label %27
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 @system(i8* %11)
%13 = load i8*, i8** %3
%14 = call i32 @free(i8* %13)
switch i32 %12, label %24 [
i32 -1, label %15
i32 0, label %27
i32 1, label %27
i32 4, label %18
i32 5, label %18
i32 6, label %18
i32 7, label %18
i32 9, label %21
]
15: ; preds = %10
%16 = load i32, i32* @errno
%17 = call i32 (i32, i8*, ...) @fail(i32 %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %27
18: ; preds = %10, %10, %10, %10
%19 = load i32, i32* @ENOMEM
%20 = call i32 (i32, i8*, ...) @fail(i32 %19, i8* null)
br label %27
21: ; preds = %10
%22 = load i32, i32* @ENOENT
%23 = call i32 (i32, i8*, ...) @fail(i32 %22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %27
24: ; preds = %10
%25 = load i32, i32* @ECANCELED
%26 = call i32 (i32, i8*, ...) @fail(i32 %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %0)
br label %27
27: ; preds = %10, %10, %24, %21, %18, %15, %7
%28 = phi i32 [ %9, %7 ], [ %26, %24 ], [ %23, %21 ], [ %20, %18 ], [ %17, %15 ], [ 0, %10 ], [ 0, %10 ]
ret i32 %28
}