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

/* Variables and functions */
int /*<<< orphan*/ execlp(char *, char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *);
int wait(int /*<<< orphan*/ *);
int unzip(char *path) {
  DIR *dir;
  dir = opendir(path);
  if (dir == NULL) {
    return (-1);
  }
  pid_t pid;
  pid = fork();
  if (pid == -1) {
    printf("Fork error.\n");
    exit(-1);
  } else if (pid == 0) {
    execlp("gzip", "gzip", "-dNr", path, NULL);
  }
  while (wait(NULL) != -1) {
  }
  return (0);
}


x86 assembly (clang, -O0):
<unzip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1190 <unzip+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <unzip+0xab>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11ba <unzip+0x5a>
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11e3 <unzip+0x83>
mov    -0x10(%rbp),%rcx
lea    0xe3e(%rip),%rsi
lea    0xe3c(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1060 <execlp@plt>
jmp    11e8 <unzip+0x88>
jmp    11ed <unzip+0x8d>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
cmp    $0xffffffff,%eax
je     1204 <unzip+0xa4>
jmp    11ed <unzip+0x8d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unzip>:
push   %rbx
mov    %rdi,%rbx
call   1040 <opendir@plt>
test   %rax,%rax
je     1194 <unzip+0x34>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     119b <unzip+0x3b>
cmp    $0xffffffff,%eax
jne    11c0 <unzip+0x60>
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    $0xffffffff,%ebx
jmp    11ce <unzip+0x6e>
lea    0xe5e(%rip),%rdi
lea    0xe5c(%rip),%rdx
mov    %rdi,%rsi
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1060 <execlp@plt>
nopw   0x0(%rax,%rax,1)
xor    %ebx,%ebx
xor    %edi,%edi
call   1070 <wait@plt>
cmp    $0xffffffff,%eax
jne    11c0 <unzip+0x60>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Fork error.\0A\00"
@.str.1 = [5 x i8] c"gzip\00"
@.str.2 = [5 x i8] c"-dNr\00"
define i32 @unzip(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @opendir(i8* %6)
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %31
11: ; preds = %1
%12 = call i32 (...) @fork()
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %11
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8*, i8** %3
%23 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %22, i32* null)
br label %24
24: ; preds = %21, %18
br label %25
25: ; preds = %24
br label %26
26: ; preds = %29, %25
%27 = call i32 @wait(i32* null)
%28 = icmp ne i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %26
br label %26
30: ; preds = %26
store i32 0, i32* %2
br label %31
31: ; preds = %30, %10
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"gzip\00"
@.str.2 = [5 x i8] c"-dNr\00"
@str = [12 x i8] c"Fork error.\00"
define i32 @unzip(i8* %0) {
%2 = tail call i32* @opendir(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = tail call i32 (...) @fork()
switch i32 %5, label %11 [
i32 -1, label %6
i32 0, label %9
]
6: ; preds = %4
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %4
%10 = tail call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32* null)
br label %11
11: ; preds = %4, %9
br label %12
12: ; preds = %11, %12
%13 = tail call i32 @wait(i32* null)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %12
15: ; preds = %12, %1
%16 = phi i32 [ -1, %1 ], [ 0, %12 ]
ret i32 %16
}