#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 def(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int inf(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ zerr(int);
int main(int argc, char **argv) {
  int ret;
  if (argc == 1) {
    ret = def(stdin, stdout, (-1));
    if (ret != 0)
      zerr(ret);
    return ret;
  } else if (argc == 2 && strcmp(argv[1], "-d") == 0) {
    ret = inf(stdin, stdout);
    if (ret != 0)
      zerr(ret);
    return ret;
  } else {
    fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr);
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11ac <main+0x5c>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edx
call   1070 <def@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11a1 <main+0x51>
mov    -0x14(%rbp),%edi
call   1030 <zerr@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1227 <main+0xd7>
cmpl   $0x2,-0x8(%rbp)
jne    120b <main+0xbb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    120b <main+0xbb>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
call   1060 <inf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1200 <main+0xb0>
mov    -0x14(%rbp),%edi
call   1030 <zerr@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1227 <main+0xd7>
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
lea    0xde8(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
je     1186 <main+0x36>
cmp    $0x1,%edi
jne    119b <main+0x4b>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edx
call   1070 <def@plt>
test   %eax,%eax
je     11d2 <main+0x82>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <zerr@plt>
jmp    11d4 <main+0x84>
mov    0x8(%rsi),%rdi
lea    0xe6f(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11b7 <main+0x67>
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
lea    0xe58(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%ebx
jmp    11d4 <main+0x84>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
call   1060 <inf@plt>
test   %eax,%eax
jne    117b <main+0x2b>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stdin = global i32 0
@stdout = global i32 0
@.str = [3 x i8] c"-d\00"
@.str.1 = [41 x i8] c"zpipe usage: zpipe [-d] < source > dest\0A\00"
@stderr = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %20
9: ; preds = %2
%10 = load i32, i32* @stdin
%11 = load i32, i32* @stdout
%12 = call i32 @def(i32 %10, i32 %11, i32 -1)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i32, i32* %6
%17 = call i32 @zerr(i32 %16)
br label %18
18: ; preds = %15, %9
%19 = load i32, i32* %6
store i32 %19, i32* %3
br label %43
20: ; preds = %2
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %40
23: ; preds = %20
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %40
29: ; preds = %23
%30 = load i32, i32* @stdin
%31 = load i32, i32* @stdout
%32 = call i32 @inf(i32 %30, i32 %31)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = load i32, i32* %6
%37 = call i32 @zerr(i32 %36)
br label %38
38: ; preds = %35, %29
%39 = load i32, i32* %6
store i32 %39, i32* %3
br label %43
40: ; preds = %23, %20
%41 = load i32, i32* @stderr
%42 = call i32 @fputs(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %41)
store i32 1, i32* %3
br label %43
43: ; preds = %40, %38, %18
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
@.str = [3 x i8] c"-d\00"
@.str.1 = [41 x i8] c"zpipe usage: zpipe [-d] < source > dest\0A\00"
@stderr = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %22 [
i32 1, label %3
i32 2, label %10
]
3: ; preds = %2
%4 = load i32, i32* @stdin
%5 = load i32, i32* @stdout
%6 = tail call i32 @def(i32 %4, i32 %5, i32 -1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %25, label %8
8: ; preds = %3
%9 = tail call i32 @zerr(i32 %6)
br label %25
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = load i32, i32* @stdin
%17 = load i32, i32* @stdout
%18 = tail call i32 @inf(i32 %16, i32 %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %15
%21 = tail call i32 @zerr(i32 %18)
br label %25
22: ; preds = %2, %10
%23 = load i32, i32* @stderr
%24 = tail call i32 @fputs(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %15, %20, %3, %8, %22
%26 = phi i32 [ 1, %22 ], [ %6, %8 ], [ 0, %3 ], [ %18, %20 ], [ 0, %15 ]
ret i32 %26
}