#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 O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ assert(int);
char *catExec(char const *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execlp(char *, char *, char *, char *, ...);
int fork();
int open(char const *, int, int);
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int setCloexec(int);
int sscanf(char const *, char *, char *, char *, char *);
int compress(const char *path) {
  const char *zcat = catExec(path);
  assert(zcat != NULL);
  int fd[2];
  if (pipe(fd) == -1)
    return -1;
  int err = setCloexec(fd[1]);
  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[0], STDIN_FILENO);
    close(fd[0]);
    int fd_open = open(path, O_WRONLY | O_CREAT, 0640);
    dup2(fd_open, STDOUT_FILENO);
    close(fd_open);
    if (n == 2)
      execlp(arg0, arg0, arg1, NULL);
    else
      execlp(arg0, arg0, arg1, arg2, NULL);
    _exit(EXIT_FAILURE);
  } else {
    close(fd[0]);
    perror(arg0);
    return fd[1];
  }
}


x86 assembly (clang, -O0):
<compress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <catExec@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    1209 <compress+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    1350 <compress+0x190>
mov    -0x1c(%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    0xdc4(%rip),%rsi
call   10a0 <sscanf@plt>
mov    %eax,-0x64(%rbp)
mov    $0x1,%al
cmpl   $0x2,-0x64(%rbp)
mov    %al,-0x6d(%rbp)
je     125d <compress+0x9d>
cmpl   $0x3,-0x64(%rbp)
sete   %al
mov    %al,-0x6d(%rbp)
mov    -0x6d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x68(%rbp)
cmpl   $0xffffffff,-0x68(%rbp)
jne    128a <compress+0xca>
movl   $0xffffffff,-0x4(%rbp)
jmp    1350 <compress+0x190>
cmpl   $0x0,-0x68(%rbp)
jne    1339 <compress+0x179>
mov    -0x20(%rbp),%edi
mov    0x2d2a(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d00(%rip),%rax
mov    (%rax),%esi
mov    0x2d37(%rip),%rax
or     (%rax),%esi
mov    $0x1a0,%edx
call   10b0 <open@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%edi
mov    0x2d0e(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    -0x6c(%rbp),%edi
call   1050 <close@plt>
cmpl   $0x2,-0x64(%rbp)
jne    130f <compress+0x14f>
lea    -0x40(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x50(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    $0x0,%al
call   10d0 <execlp@plt>
jmp    132b <compress+0x16b>
lea    -0x40(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x60(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   10d0 <execlp@plt>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
lea    -0x40(%rbp),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%rbx
call   1090 <catExec@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     125e <compress+0x9e>
mov    0xc(%rsp),%edi
call   1070 <setCloexec@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1080 <assert@plt>
lea    0xdf5(%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   10e0 <fork@plt>
cmp    $0xffffffff,%eax
je     1263 <compress+0xa3>
test   %eax,%eax
je     126a <compress+0xaa>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
lea    0x10(%rsp),%rdi
call   10c0 <perror@plt>
mov    0xc(%rsp),%eax
jmp    1263 <compress+0xa3>
mov    $0xffffffff,%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x8(%rsp),%edi
mov    0x2d53(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0x2d2c(%rip),%rax
mov    0x2d65(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1a0,%edx
call   10b0 <open@plt>
mov    %eax,%ebx
mov    0x2d3b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <dup2@plt>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0x10(%rsp),%rdi
lea    0x20(%rsp),%rdx
cmp    $0x2,%ebp
jne    12da <compress+0x11a>
mov    %rdi,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   10d0 <execlp@plt>
jmp    12ec <compress+0x12c>
lea    0x30(%rsp),%rcx
mov    %rdi,%rsi
xor    %r8d,%r8d
xor    %eax,%eax
call   10d0 <execlp@plt>
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

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

LLVM IR (-O2):
@.str = [9 x i8] c"%s %s %s\00"
@STDIN_FILENO = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@STDOUT_FILENO = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @compress(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* @catExec(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 %58, label %14
14: ; preds = %1
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%16 = load i32, i32* %15
%17 = call i32 @setCloexec(i32 %16)
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%24 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22, i8* %23)
%25 = and i32 %24, -2
%26 = icmp eq i32 %25, 2
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = call i32 (...) @fork()
switch i32 %29, label %51 [
i32 -1, label %56
i32 0, label %30
]
30: ; preds = %14
%31 = icmp eq i32 %24, 2
%32 = load i32, i32* %11
%33 = load i32, i32* @STDIN_FILENO
%34 = call i32 @dup2(i32 %32, i32 %33)
%35 = load i32, i32* %11
%36 = call i32 @close(i32 %35)
%37 = load i32, i32* @O_WRONLY
%38 = load i32, i32* @O_CREAT
%39 = or i32 %38, %37
%40 = call i32 @open(i8* %0, i32 %39, i32 416)
%41 = load i32, i32* @STDOUT_FILENO
%42 = call i32 @dup2(i32 %40, i32 %41)
%43 = call i32 @close(i32 %40)
br i1 %31, label %44, label %46
44: ; preds = %30
%45 = call i32 (i8*, i8*, i8*, i8*, ...) @execlp(i8* %21, i8* %21, i8* %22, i8* null)
br label %48
46: ; preds = %30
%47 = call i32 (i8*, i8*, i8*, i8*, ...) @execlp(i8* %21, i8* %21, i8* %22, i8* %23, i8* null)
br label %48
48: ; preds = %46, %44
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @_exit(i32 %49)
unreachable
51: ; preds = %14
%52 = load i32, i32* %11
%53 = call i32 @close(i32 %52)
%54 = call i32 @perror(i8* %21)
%55 = load i32, i32* %15
br label %56
56: ; preds = %14, %51
%57 = phi i32 [ %55, %51 ], [ %29, %14 ]
br label %58
58: ; preds = %1, %56
%59 = phi i32 [ %57, %56 ], [ -1, %1 ]
ret i32 %59
}