#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/ *);
scalar_t__ load_zipped_file(char *, char *, unsigned char **, int *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
int file_unzip(char *zipfile, char *filename, char *tmpdir) {
  FILE *fp;
  unsigned char *mem;
  char *tmpfile;
  int size;
  int i;
  tmpfile = (char *)malloc(strlen(filename) + strlen(tmpdir) + 2);
  strcpy(tmpfile, tmpdir);
  strcat(tmpfile, "/");
  strcat(tmpfile, filename);
  tmpfile[strlen(tmpfile)] = '\0';
  if (load_zipped_file(zipfile, filename, &mem, &size) == 0) {
    fp = fopen(tmpfile, "wb");
    for (i = 0; i < size; i++)
      fputc(mem[i], fp);
    fclose(fp);
    return 0;
  } else {
    printf("SDLengine error: file not found  %s\n", filename);
    return -1;
  }
}


x86 assembly (clang, -O0):
<file_unzip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <strcat@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
call   1080 <load_zipped_file@plt>
cmp    $0x0,%rax
jne    1294 <file_unzip+0x104>
mov    -0x38(%rbp),%rdi
lea    0xdc4(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    127f <file_unzip+0xef>
mov    -0x30(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x28(%rbp),%rsi
movzbl %al,%edi
call   1070 <fputc@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    124e <file_unzip+0xbe>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ab <file_unzip+0x11b>
mov    -0x18(%rbp),%rsi
lea    0xd66(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_unzip>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
lea    0xe27(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movb   $0x0,(%rbx,%rax,1)
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <load_zipped_file@plt>
test   %rax,%rax
je     1228 <file_unzip+0x98>
lea    0xdec(%rip),%rdi
mov    %r15,%rsi
call   1060 <printf@plt>
mov    $0xffffffff,%eax
jmp    1279 <file_unzip+0xe9>
lea    0xdd3(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r14
cmpl   $0x0,0xc(%rsp)
jle    126f <file_unzip+0xdf>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rsp),%rax
movzbl (%rax,%rbx,1),%edi
mov    %r14,%rsi
call   1070 <fputc@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1250 <file_unzip+0xc0>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [37 x i8] c"SDLengine error: file not found %s\0A\00"
define i32 @file_unzip(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%13 = load i8*, i8** %6
%14 = call i64 @strlen(i8* %13)
%15 = load i8*, i8** %7
%16 = call i64 @strlen(i8* %15)
%17 = add i64 %14, %16
%18 = add i64 %17, 2
%19 = call i64 @malloc(i64 %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %10
%21 = load i8*, i8** %10
%22 = load i8*, i8** %7
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i8*, i8** %10
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%26 = load i8*, i8** %10
%27 = load i8*, i8** %6
%28 = call i32 @strcat(i8* %26, i8* %27)
%29 = load i8*, i8** %10
%30 = load i8*, i8** %10
%31 = call i64 @strlen(i8* %30)
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
%33 = load i8*, i8** %5
%34 = load i8*, i8** %6
%35 = call i64 @load_zipped_file(i8* %33, i8* %34, i8** %9, i32* %11)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %58
37: ; preds = %3
%38 = load i8*, i8** %10
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %39, i32** %8
store i32 0, i32* %12
br label %40
40: ; preds = %52, %37
%41 = load i32, i32* %12
%42 = load i32, i32* %11
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %55
44: ; preds = %40
%45 = load i8*, i8** %9
%46 = load i32, i32* %12
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = load i32*, i32** %8
%51 = call i32 @fputc(i8 zeroext %49, i32* %50)
br label %52
52: ; preds = %44
%53 = load i32, i32* %12
%54 = add nsw i32 %53, 1
store i32 %54, i32* %12
br label %40
55: ; preds = %40
%56 = load i32*, i32** %8
%57 = call i32 @fclose(i32* %56)
store i32 0, i32* %4
br label %61
58: ; preds = %3
%59 = load i8*, i8** %6
%60 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %59)
store i32 -1, i32* %4
br label %61
61: ; preds = %58, %55
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [37 x i8] c"SDLengine error: file not found %s\0A\00"
define i32 @file_unzip(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = bitcast i8** %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%10 = add i64 %8, 2
%11 = add i64 %10, %9
%12 = tail call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 @strcpy(i8* %13, i8* %2)
%15 = tail call i32 @strcat(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @strcat(i8* %13, i8* %1)
%17 = tail call i64 @strlen(i8* dereferenceable(1) %13)
%18 = getelementptr inbounds i8, i8* %13, i64 %17
store i8 0, i8* %18
%19 = call i64 @load_zipped_file(i8* %0, i8* %1, i8** %4, i32* %5)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %37
21: ; preds = %3
%22 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %5
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %21, %25
%26 = phi i64 [ %31, %25 ], [ 0, %21 ]
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 %26
%29 = load i8, i8* %28
%30 = call i32 @fputc(i8 zeroext %29, i32* %22)
%31 = add nuw nsw i64 %26, 1
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %25, label %35
35: ; preds = %25, %21
%36 = call i32 @fclose(i32* %22)
br label %39
37: ; preds = %3
%38 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %39
39: ; preds = %37, %35
%40 = phi i32 [ 0, %35 ], [ -1, %37 ]
ret i32 %40
}