#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*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ restore_sigmask();
void run_gzip(int fd_out, int fd_in) {
  int pid;
  pid = fork();
  switch (pid) {
  case 0:
    restore_sigmask();
    dup2(fd_in, 0);
    dup2(fd_out, 1);
    close(fd_in);
    close(fd_out);
    close(2);
    execlp("gzip", "gzip", NULL);
    exit(-1);
  case -1:
    exit(-1);
  default:
    close(fd_in);
    close(fd_out);
  }
}


x86 assembly (clang, -O0):
<run_gzip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0xffffffff,%eax
je     11f1 <run_gzip+0x91>
jmp    118c <run_gzip+0x2c>
mov    -0x10(%rbp),%eax
test   %eax,%eax
jne    11fb <run_gzip+0x9b>
jmp    119c <run_gzip+0x3c>
mov    $0x0,%al
call   1040 <restore_sigmask@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
mov    $0x2,%edi
call   1050 <close@plt>
lea    0xe25(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1070 <execlp@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_gzip>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     11d0 <run_gzip+0x70>
test   %eax,%eax
je     118b <run_gzip+0x2b>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <close@plt>
xor    %eax,%eax
call   1040 <restore_sigmask@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0x2,%edi
call   1050 <close@plt>
lea    0xe3a(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1070 <execlp@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"gzip\00"
define void @run_gzip(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = call i32 (...) @fork()
store i32 %6, i32* %5
%7 = load i32, i32* %5
switch i32 %7, label %23 [
i32 0, label %8
i32 -1, label %21
]
8: ; preds = %2
%9 = call i32 (...) @restore_sigmask()
%10 = load i32, i32* %4
%11 = call i32 @dup2(i32 %10, i32 0)
%12 = load i32, i32* %3
%13 = call i32 @dup2(i32 %12, i32 1)
%14 = load i32, i32* %4
%15 = call i32 @close(i32 %14)
%16 = load i32, i32* %3
%17 = call i32 @close(i32 %16)
%18 = call i32 @close(i32 2)
%19 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* null)
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %2
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %2
%24 = load i32, i32* %4
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* %3
%27 = call i32 @close(i32 %26)
br label %28
28: ; preds = %23
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"gzip\00"
define void @run_gzip(i32 %0, i32 %1) {
%3 = tail call i32 (...) @fork()
switch i32 %3, label %15 [
i32 0, label %4
i32 -1, label %13
]
4: ; preds = %2
%5 = tail call i32 (...) @restore_sigmask()
%6 = tail call i32 @dup2(i32 %1, i32 0)
%7 = tail call i32 @dup2(i32 %0, i32 1)
%8 = tail call i32 @close(i32 %1)
%9 = tail call i32 @close(i32 %0)
%10 = tail call i32 @close(i32 2)
%11 = tail call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* null)
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
%16 = tail call i32 @close(i32 %1)
%17 = tail call i32 @close(i32 %0)
ret void
}