#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;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execlp(char *, char *, char *, char const *, char const *,
                          ...);
int fork();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int setCloexec(int);
int sscanf(char const *, char *, char *, char *, char *);
char *zcatExec(char const *);
int uncompress(const char *path) {
  const char *zcat = zcatExec(path);
  assert(zcat != NULL);
  int fd[2];
  if (pipe(fd) == -1)
    return -1;
  int err = setCloexec(fd[0]);
  assert(err == 0);
  (void)err;
  char arg0[16], arg1[16], arg2[16];
  int n = sscanf(zcat, "%s %s %s", arg0, arg1, arg2);
  assert(n == 2 || n == 3);
  pid_t pid = fork();
  if (pid == -1)
    return -1;
  if (pid == 0) {
    dup2(fd[1], STDOUT_FILENO);
    close(fd[1]);
    if (n == 2)
      execlp(arg0, arg0, arg1, path, NULL);
    else
      execlp(arg0, arg0, arg1, arg2, path, NULL);
    perror(arg0);
    _exit(EXIT_FAILURE);
  } else {
    close(fd[1]);
    return fd[0];
  }
}


x86 assembly (clang, -O0):
<uncompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <zcatExec@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x20(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11f9 <uncompress+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    130d <uncompress+0x15d>
mov    -0x20(%rbp),%edi
call   1070 <setCloexec@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    -0x50(%rbp),%rcx
lea    -0x60(%rbp),%r8
lea    0xdd4(%rip),%rsi
call   10a0 <sscanf@plt>
mov    %eax,-0x64(%rbp)
mov    $0x1,%al
cmpl   $0x2,-0x64(%rbp)
mov    %al,-0x69(%rbp)
je     124d <uncompress+0x9d>
cmpl   $0x3,-0x64(%rbp)
sete   %al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0x68(%rbp)
cmpl   $0xffffffff,-0x68(%rbp)
jne    127a <uncompress+0xca>
movl   $0xffffffff,-0x4(%rbp)
jmp    130d <uncompress+0x15d>
cmpl   $0x0,-0x68(%rbp)
jne    12ff <uncompress+0x14f>
mov    -0x1c(%rbp),%edi
mov    0x2d62(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
cmpl   $0x2,-0x64(%rbp)
jne    12c8 <uncompress+0x118>
lea    -0x40(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x50(%rbp),%rdx
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   10c0 <execlp@plt>
jmp    12e8 <uncompress+0x138>
lea    -0x40(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x60(%rbp),%rcx
mov    -0x10(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
mov    $0x0,%al
call   10c0 <execlp@plt>
lea    -0x40(%rbp),%rdi
call   10b0 <perror@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uncompress>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%rbx
call   1090 <zcatExec@plt>
mov    %rax,%rbp
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1080 <assert@plt>
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     1244 <uncompress+0x94>
mov    0x8(%rsp),%edi
call   1070 <setCloexec@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1080 <assert@plt>
lea    0xe05(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x20(%rsp),%rcx
lea    0x30(%rsp),%r8
mov    %rbp,%rdi
call   10a0 <sscanf@plt>
mov    %eax,%ebp
and    $0xfffffffe,%eax
xor    %edi,%edi
cmp    $0x2,%eax
sete   %dil
call   1080 <assert@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
cmp    $0xffffffff,%eax
je     1249 <uncompress+0x99>
test   %eax,%eax
je     1250 <uncompress+0xa0>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%eax
jmp    1249 <uncompress+0x99>
mov    $0xffffffff,%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret
mov    0xc(%rsp),%edi
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
lea    0x10(%rsp),%rdi
lea    0x20(%rsp),%rdx
cmp    $0x2,%ebp
jne    128c <uncompress+0xdc>
mov    %rdi,%rsi
mov    %rbx,%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   10c0 <execlp@plt>
jmp    12a1 <uncompress+0xf1>
lea    0x30(%rsp),%rcx
mov    %rdi,%rsi
mov    %rbx,%r8
xor    %r9d,%r9d
xor    %eax,%eax
call   10c0 <execlp@plt>
lea    0x10(%rsp),%rdi
call   10b0 <perror@plt>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%s %s %s\00"
@STDOUT_FILENO = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @uncompress(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [2 x i32]
%6 = alloca i32
%7 = alloca [16 x i8]
%8 = alloca [16 x i8]
%9 = alloca [16 x i8]
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %3
%12 = load i8*, i8** %3
%13 = call i8* @zcatExec(i8* %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%19 = call i32 @pipe(i32* %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %1
store i32 -1, i32* %2
br label %86
22: ; preds = %1
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%24 = load i32, i32* %23
%25 = call i32 @setCloexec(i32 %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 0
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i32, i32* %6
%31 = load i8*, i8** %4
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%35 = call i32 @sscanf(i8* %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %32, i8* %33, i8* %34)
store i32 %35, i32* %10
%36 = load i32, i32* %10
%37 = icmp eq i32 %36, 2
br i1 %37, label %41, label %38
38: ; preds = %22
%39 = load i32, i32* %10
%40 = icmp eq i32 %39, 3
br label %41
41: ; preds = %38, %22
%42 = phi i1 [ true, %22 ], [ %40, %38 ]
%43 = zext i1 %42 to i32
%44 = call i32 @assert(i32 %43)
%45 = call i32 (...) @fork()
store i32 %45, i32* %11
%46 = load i32, i32* %11
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %49
48: ; preds = %41
store i32 -1, i32* %2
br label %86
49: ; preds = %41
%50 = load i32, i32* %11
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %80
52: ; preds = %49
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%54 = load i32, i32* %53
%55 = load i32, i32* @STDOUT_FILENO
%56 = call i32 @dup2(i32 %54, i32 %55)
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%58 = load i32, i32* %57
%59 = call i32 @close(i32 %58)
%60 = load i32, i32* %10
%61 = icmp eq i32 %60, 2
br i1 %61, label %62, label %68
62: ; preds = %52
%63 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%64 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%65 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%66 = load i8*, i8** %3
%67 = call i32 (i8*, i8*, i8*, i8*, i8*, ...) @execlp(i8* %63, i8* %64, i8* %65, i8* %66, i8* null)
br label %75
68: ; preds = %52
%69 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%70 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%71 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%72 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%73 = load i8*, i8** %3
%74 = call i32 (i8*, i8*, i8*, i8*, i8*, ...) @execlp(i8* %69, i8* %70, i8* %71, i8* %72, i8* %73, i8* null)
br label %75
75: ; preds = %68, %62
%76 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%77 = call i32 @perror(i8* %76)
%78 = load i32, i32* @EXIT_FAILURE
%79 = call i32 @_exit(i32 %78)
unreachable
80: ; preds = %49
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%82 = load i32, i32* %81
%83 = call i32 @close(i32 %82)
%84 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%85 = load i32, i32* %84
store i32 %85, i32* %2
br label %86
86: ; preds = %80, %48, %21
%87 = load i32, i32* %2
ret i32 %87
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s %s %s\00"
@STDOUT_FILENO = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @uncompress(i8* %0) {
%2 = alloca [2 x i32]
%3 = alloca [16 x i8]
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = tail call i8* @zcatExec(i8* %0)
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = bitcast [2 x i32]* %2 to i8*
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %52, label %14
14: ; preds = %1
%15 = load i32, i32* %11
%16 = call i32 @setCloexec(i32 %15)
%17 = icmp eq i32 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%23 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %21, i8* %22)
%24 = and i32 %23, -2
%25 = icmp eq i32 %24, 2
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = call i32 (...) @fork()
switch i32 %28, label %45 [
i32 -1, label %50
i32 0, label %29
]
29: ; preds = %14
%30 = icmp eq i32 %23, 2
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%32 = load i32, i32* %31
%33 = load i32, i32* @STDOUT_FILENO
%34 = call i32 @dup2(i32 %32, i32 %33)
%35 = load i32, i32* %31
%36 = call i32 @close(i32 %35)
br i1 %30, label %37, label %39
37: ; preds = %29
%38 = call i32 (i8*, i8*, i8*, i8*, i8*, ...) @execlp(i8* %20, i8* %20, i8* %21, i8* %0, i8* null)
br label %41
39: ; preds = %29
%40 = call i32 (i8*, i8*, i8*, i8*, i8*, ...) @execlp(i8* %20, i8* %20, i8* %21, i8* %22, i8* %0, i8* null)
br label %41
41: ; preds = %39, %37
%42 = call i32 @perror(i8* %20)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @_exit(i32 %43)
unreachable
45: ; preds = %14
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%47 = load i32, i32* %46
%48 = call i32 @close(i32 %47)
%49 = load i32, i32* %11
br label %50
50: ; preds = %14, %45
%51 = phi i32 [ %49, %45 ], [ %28, %14 ]
br label %52
52: ; preds = %1, %50
%53 = phi i32 [ %51, %50 ], [ -1, %1 ]
ret i32 %53
}