#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*/ exit(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ stricmp(int /*<<< orphan*/, char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ wfile_abstmpnam(char *);
int /*<<< orphan*/ wfile_basespec(char *, char *);
int /*<<< orphan*/ wfile_ext(char *);
int /*<<< orphan*/ wfile_fullname(char *, char *, char *);
char *wfile_get_wd();
int /*<<< orphan*/ wfile_make_absolute(char *);
int /*<<< orphan*/ wfile_makedir(char *);
int /*<<< orphan*/ wfile_set_wd(char *);
int wfile_status(char *);
int archive_extract(char *archfile, char *file_to_extract, char *tempname) {
  char archname_full[512];
  char tempdir[512];
  char cwd[512];
  char basefile[512];
  char cmd[512 + 128];
  strcpy(archname_full, archfile);
  wfile_make_absolute(archname_full);
  wfile_basespec(basefile, file_to_extract);
  wfile_abstmpnam(tempdir);
  wfile_makedir(tempdir);
  strcpy(cwd, wfile_get_wd());
  wfile_set_wd(tempdir);
  if (!stricmp(wfile_ext(archfile), "7z"))
    sprintf(cmd, "7z -r e \"%s\" \"%s\" 1> nul 2> nul", archname_full,
            file_to_extract);
  else
    sprintf(cmd, "unzip -o -j \"%s\" \"%s\" 1> nul 2> nul", archname_full,
            file_to_extract);
  system(cmd);
  wfile_set_wd(cwd);
  wfile_fullname(tempname, tempdir, basefile);
  if (wfile_status(tempname) != 1) {
    printf("Internal error executing command '%s'!\n", cmd);
    exit(10);
  }
  return (1);
}


x86 assembly (clang, -O0):
<archive_extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0xab0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x220(%rbp),%rdi
call   10c0 <wfile_make_absolute@plt>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <wfile_basespec@plt>
lea    -0x420(%rbp),%rdi
call   10f0 <wfile_abstmpnam@plt>
lea    -0x420(%rbp),%rdi
call   1030 <wfile_makedir@plt>
lea    -0x620(%rbp),%rax
mov    %rax,-0xaa8(%rbp)
mov    $0x0,%al
call   1090 <wfile_get_wd@plt>
mov    -0xaa8(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    -0x420(%rbp),%rdi
call   1050 <wfile_set_wd@plt>
mov    -0x8(%rbp),%rdi
call   10d0 <wfile_ext@plt>
mov    %eax,%edi
lea    0xd73(%rip),%rsi
call   1060 <stricmp@plt>
cmp    $0x0,%eax
jne    12be <archive_extract+0xce>
lea    -0xaa0(%rbp),%rdi
lea    -0x220(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xd4f(%rip),%rsi
call   1100 <sprintf@plt>
jmp    12dc <archive_extract+0xec>
lea    -0xaa0(%rbp),%rdi
lea    -0x220(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xd4c(%rip),%rsi
call   1100 <sprintf@plt>
lea    -0xaa0(%rbp),%rdi
call   1070 <system@plt>
lea    -0x620(%rbp),%rdi
call   1050 <wfile_set_wd@plt>
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
lea    -0x820(%rbp),%rdx
call   10e0 <wfile_fullname@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <wfile_status@plt>
cmp    $0x1,%eax
je     133a <archive_extract+0x14a>
lea    -0xaa0(%rbp),%rsi
lea    0xd1c(%rip),%rdi
call   1080 <printf@plt>
mov    $0xa,%edi
call   1110 <exit@plt>
mov    $0x1,%eax
add    $0xab0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<archive_extract>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa88,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0x880(%rsp),%r12
mov    %r12,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
call   10c0 <wfile_make_absolute@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   10b0 <wfile_basespec@plt>
lea    0x680(%rsp),%r13
mov    %r13,%rdi
call   10f0 <wfile_abstmpnam@plt>
mov    %r13,%rdi
call   1030 <wfile_makedir@plt>
xor    %eax,%eax
call   1090 <wfile_get_wd@plt>
lea    0x480(%rsp),%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %r13,%rdi
call   1050 <wfile_set_wd@plt>
mov    %rbp,%rdi
call   10d0 <wfile_ext@plt>
lea    0xd87(%rip),%rsi
mov    %eax,%edi
call   1060 <stricmp@plt>
test   %eax,%eax
lea    0xd7a(%rip),%rax
lea    0xd93(%rip),%rsi
cmove  %rax,%rsi
lea    0x200(%rsp),%rbp
mov    %rbp,%rdi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1100 <sprintf@plt>
mov    %rbp,%rdi
call   1070 <system@plt>
mov    %r14,%rdi
call   1050 <wfile_set_wd@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rsp,%rdx
call   10e0 <wfile_fullname@plt>
mov    %r15,%rdi
call   10a0 <wfile_status@plt>
cmp    $0x1,%eax
jne    12ec <archive_extract+0xfc>
mov    $0x1,%eax
add    $0xa88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd54(%rip),%rdi
lea    0x200(%rsp),%rsi
call   1080 <printf@plt>
mov    $0xa,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"7z\00"
@.str.1 = [32 x i8] c"7z -r e \22%s\22 \22%s\22 1> nul 2> nul\00"
@.str.2 = [36 x i8] c"unzip -o -j \22%s\22 \22%s\22 1> nul 2> nul\00"
@.str.3 = [40 x i8] c"Internal error executing command '%s'!\0A\00"
define i32 @archive_extract(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [512 x i8]
%8 = alloca [512 x i8]
%9 = alloca [512 x i8]
%10 = alloca [512 x i8]
%11 = alloca [640 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%13 = load i8*, i8** %4
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%16 = call i32 @wfile_make_absolute(i8* %15)
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%18 = load i8*, i8** %5
%19 = call i32 @wfile_basespec(i8* %17, i8* %18)
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%21 = call i32 @wfile_abstmpnam(i8* %20)
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%23 = call i32 @wfile_makedir(i8* %22)
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%25 = call i8* (...) @wfile_get_wd()
%26 = call i32 @strcpy(i8* %24, i8* %25)
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%28 = call i32 @wfile_set_wd(i8* %27)
%29 = load i8*, i8** %4
%30 = call i32 @wfile_ext(i8* %29)
%31 = call i32 @stricmp(i32 %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%32 = icmp ne i32 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %3
%34 = getelementptr inbounds [640 x i8], [640 x i8]* %11, i64 0, i64 0
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%36 = load i8*, i8** %5
%37 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %35, i8* %36)
br label %43
38: ; preds = %3
%39 = getelementptr inbounds [640 x i8], [640 x i8]* %11, i64 0, i64 0
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%41 = load i8*, i8** %5
%42 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %40, i8* %41)
br label %43
43: ; preds = %38, %33
%44 = getelementptr inbounds [640 x i8], [640 x i8]* %11, i64 0, i64 0
%45 = call i32 @system(i8* %44)
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%47 = call i32 @wfile_set_wd(i8* %46)
%48 = load i8*, i8** %6
%49 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%50 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%51 = call i32 @wfile_fullname(i8* %48, i8* %49, i8* %50)
%52 = load i8*, i8** %6
%53 = call i32 @wfile_status(i8* %52)
%54 = icmp ne i32 %53, 1
br i1 %54, label %55, label %59
55: ; preds = %43
%56 = getelementptr inbounds [640 x i8], [640 x i8]* %11, i64 0, i64 0
%57 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %56)
%58 = call i32 @exit(i32 10)
unreachable
59: ; preds = %43
ret i32 1
}

LLVM IR (-O2):
@.str = [3 x i8] c"7z\00"
@.str.1 = [32 x i8] c"7z -r e \22%s\22 \22%s\22 1> nul 2> nul\00"
@.str.2 = [36 x i8] c"unzip -o -j \22%s\22 \22%s\22 1> nul 2> nul\00"
@.str.3 = [40 x i8] c"Internal error executing command '%s'!\0A\00"
define i32 @archive_extract(i8* %0, i8* %1, i8* %2) {
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = alloca [512 x i8]
%8 = alloca [640 x i8]
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [640 x i8], [640 x i8]* %8, i64 0, i64 0
%14 = call i32 @strcpy(i8* %9, i8* %0)
%15 = call i32 @wfile_make_absolute(i8* %9)
%16 = call i32 @wfile_basespec(i8* %12, i8* %1)
%17 = call i32 @wfile_abstmpnam(i8* %10)
%18 = call i32 @wfile_makedir(i8* %10)
%19 = call i8* (...) @wfile_get_wd()
%20 = call i32 @strcpy(i8* %11, i8* %19)
%21 = call i32 @wfile_set_wd(i8* %10)
%22 = call i32 @wfile_ext(i8* %0)
%23 = call i32 @stricmp(i32 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0)
%26 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) %25, i8* %9, i8* %1)
%27 = call i32 @system(i8* %13)
%28 = call i32 @wfile_set_wd(i8* %11)
%29 = call i32 @wfile_fullname(i8* %2, i8* %10, i8* %12)
%30 = call i32 @wfile_status(i8* %2)
%31 = icmp eq i32 %30, 1
br i1 %31, label %35, label %32
32: ; preds = %3
%33 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%34 = call i32 @exit(i32 10)
unreachable
35: ; preds = %3
ret i32 1
}