#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*/ Z_DEFAULT_COMPRESSION;
int Z_OK;
int def(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int inf(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ zerr(int);
int main(int argc, char **argv) {
  int ret;
  int a = 0;
  FILE *in, *out;
  if (argc < 3) {
    fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr);
    return 1;
  }
  if (strcmp(argv[1], "-d") == 0) {
    a = 1;
    if (argc < 4) {
      fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr);
      return 1;
    }
  }
  in = fopen(argv[1 + a], "rb");
  if (!in) {
    fputs("cannot open input file\n", stderr);
    return 1;
  }
  out = fopen(argv[2 + a], "wb");
  if (!out) {
    fclose(out);
    fputs("cannot create output file\n", stderr);
    return 1;
  }
  if (a == 0) {
    ret = def(in, out, Z_DEFAULT_COMPRESSION);
    fclose(in);
    fclose(out);
    if (ret != Z_OK)
      zerr(ret);
    return ret;
  } else {
    ret = inf(in, out);
    fclose(in);
    fclose(out);
    if (ret != Z_OK)
      zerr(ret);
    return ret;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11b8 <main+0x48>
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
lea    0xe59(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    134c <main+0x1dc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe62(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    120d <main+0x9d>
movl   $0x1,-0x18(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    1208 <main+0x98>
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
lea    0xe09(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    134c <main+0x1dc>
jmp    120d <main+0x9d>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe07(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    125a <main+0xea>
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
lea    0xde6(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    134c <main+0x1dc>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdd5(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12b0 <main+0x140>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%esi
lea    0xdab(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    134c <main+0x1dc>
cmpl   $0x0,-0x18(%rbp)
jne    130a <main+0x19a>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2d07(%rip),%rax
mov    (%rax),%edx
call   1080 <def@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    0x2d01(%rip),%rcx
cmp    (%rcx),%eax
je     12ff <main+0x18f>
mov    -0x14(%rbp),%edi
call   1030 <zerr@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    134c <main+0x1dc>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <inf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    0x2cba(%rip),%rcx
cmp    (%rcx),%eax
je     1346 <main+0x1d6>
mov    -0x14(%rbp),%edi
call   1030 <zerr@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edi
jg     1192 <main+0x22>
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    0xe73(%rip),%rdi
jmp    1235 <main+0xc5>
mov    %rsi,%r12
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0xe87(%rip),%rsi
call   1060 <strcmp@plt>
mov    %rax,%r15
xor    %ebx,%ebx
test   %rax,%rax
jne    11bb <main+0x4b>
mov    $0x1,%ebx
cmp    $0x3,%ebp
jbe    117d <main+0xd>
mov    %ebx,%eax
mov    0x8(%r12,%rax,8),%rdi
lea    0xe63(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     120c <main+0x9c>
mov    %rax,%r14
or     $0x2,%ebx
mov    (%r12,%rbx,8),%rdi
lea    0xe63(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     121e <main+0xae>
mov    %rax,%r12
test   %r15,%r15
je     124a <main+0xda>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <def@plt>
jmp    1255 <main+0xe5>
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
lea    0xe13(%rip),%rdi
jmp    1235 <main+0xc5>
xor    %edi,%edi
call   1040 <fclose@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
lea    0xe15(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <inf@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    0x2d82(%rip),%rax
cmp    (%rax),%ebx
je     123f <main+0xcf>
mov    %ebx,%edi
call   1030 <zerr@plt>
jmp    123f <main+0xcf>

LLVM IR (-O0):
@.str = [41 x i8] c"zpipe usage: zpipe [-d] < source > dest\0A\00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"-d\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [24 x i8] c"cannot open input file\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [27 x i8] c"cannot create output file\0A\00"
@Z_DEFAULT_COMPRESSION = global i32 0
@Z_OK = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fputs(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 1, i32* %3
br label %92
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %15
store i32 1, i32* %7
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 4
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = call i32 @fputs(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %25)
store i32 1, i32* %3
br label %92
27: ; preds = %21
br label %28
28: ; preds = %27, %15
%29 = load i8**, i8*** %5
%30 = load i32, i32* %7
%31 = add nsw i32 1, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %29, i64 %32
%34 = load i8*, i8** %33
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %35, i32** %8
%36 = load i32*, i32** %8
%37 = icmp ne i32* %36, null
br i1 %37, label %41, label %38
38: ; preds = %28
%39 = load i32, i32* @stderr
%40 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %39)
store i32 1, i32* %3
br label %92
41: ; preds = %28
%42 = load i8**, i8*** %5
%43 = load i32, i32* %7
%44 = add nsw i32 2, %43
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %42, i64 %45
%47 = load i8*, i8** %46
%48 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %48, i32** %9
%49 = load i32*, i32** %9
%50 = icmp ne i32* %49, null
br i1 %50, label %56, label %51
51: ; preds = %41
%52 = load i32*, i32** %9
%53 = call i32 @fclose(i32* %52)
%54 = load i32, i32* @stderr
%55 = call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %54)
store i32 1, i32* %3
br label %92
56: ; preds = %41
%57 = load i32, i32* %7
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %76
59: ; preds = %56
%60 = load i32*, i32** %8
%61 = load i32*, i32** %9
%62 = load i32, i32* @Z_DEFAULT_COMPRESSION
%63 = call i32 @def(i32* %60, i32* %61, i32 %62)
store i32 %63, i32* %6
%64 = load i32*, i32** %8
%65 = call i32 @fclose(i32* %64)
%66 = load i32*, i32** %9
%67 = call i32 @fclose(i32* %66)
%68 = load i32, i32* %6
%69 = load i32, i32* @Z_OK
%70 = icmp ne i32 %68, %69
br i1 %70, label %71, label %74
71: ; preds = %59
%72 = load i32, i32* %6
%73 = call i32 @zerr(i32 %72)
br label %74
74: ; preds = %71, %59
%75 = load i32, i32* %6
store i32 %75, i32* %3
br label %92
76: ; preds = %56
%77 = load i32*, i32** %8
%78 = load i32*, i32** %9
%79 = call i32 @inf(i32* %77, i32* %78)
store i32 %79, i32* %6
%80 = load i32*, i32** %8
%81 = call i32 @fclose(i32* %80)
%82 = load i32*, i32** %9
%83 = call i32 @fclose(i32* %82)
%84 = load i32, i32* %6
%85 = load i32, i32* @Z_OK
%86 = icmp ne i32 %84, %85
br i1 %86, label %87, label %90
87: ; preds = %76
%88 = load i32, i32* %6
%89 = call i32 @zerr(i32 %88)
br label %90
90: ; preds = %87, %76
%91 = load i32, i32* %6
store i32 %91, i32* %3
br label %92
92: ; preds = %90, %74, %51, %38, %24, %12
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
@.str = [41 x i8] c"zpipe usage: zpipe [-d] < source > dest\0A\00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"-d\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [24 x i8] c"cannot open input file\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [27 x i8] c"cannot create output file\0A\00"
@Z_DEFAULT_COMPRESSION = global i32 0
@Z_OK = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fputs(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %57
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %7
%13 = icmp ult i32 %0, 4
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = load i32, i32* @stderr
%16 = tail call i32 @fputs(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %57
17: ; preds = %12, %7
%18 = phi i32 [ 1, %12 ], [ 0, %7 ]
%19 = add nuw nsw i32 %18, 1
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %1, i64 %20
%22 = load i8*, i8** %21
%23 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load i32, i32* @stderr
%27 = tail call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %26)
br label %57
28: ; preds = %17
%29 = or i32 %18, 2
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %1, i64 %30
%32 = load i8*, i8** %31
%33 = tail call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %39
35: ; preds = %28
%36 = tail call i32 @fclose(i32* null)
%37 = load i32, i32* @stderr
%38 = tail call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %37)
br label %57
39: ; preds = %28
br i1 %11, label %49, label %40
40: ; preds = %39
%41 = load i32, i32* @Z_DEFAULT_COMPRESSION
%42 = tail call i32 @def(i32* %23, i32* %33, i32 %41)
%43 = tail call i32 @fclose(i32* %23)
%44 = tail call i32 @fclose(i32* %33)
%45 = load i32, i32* @Z_OK
%46 = icmp eq i32 %42, %45
br i1 %46, label %57, label %47
47: ; preds = %40
%48 = tail call i32 @zerr(i32 %42)
br label %57
49: ; preds = %39
%50 = tail call i32 @inf(i32* %23, i32* %33)
%51 = tail call i32 @fclose(i32* %23)
%52 = tail call i32 @fclose(i32* %33)
%53 = load i32, i32* @Z_OK
%54 = icmp eq i32 %50, %53
br i1 %54, label %57, label %55
55: ; preds = %49
%56 = tail call i32 @zerr(i32 %50)
br label %57
57: ; preds = %49, %55, %40, %47, %35, %25, %14, %4
%58 = phi i32 [ 1, %4 ], [ 1, %14 ], [ 1, %35 ], [ 1, %25 ], [ %42, %47 ], [ %42, %40 ], [ %50, %55 ], [ %50, %49 ]
ret i32 %58
}