#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*/ dup(int);
int /*<<< orphan*/ execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int main() {
  int pfds[2];
  int childpid;
  if (pipe(pfds) == -1) {
    perror("Failed to create pipe; quitting\n");
    exit(1);
  }
  if ((childpid = fork()) == -1) {
    perror("Failed to fork; quitting\n");
    exit(2);
  }
  if (childpid == 0) {
    close(1);
    dup(pfds[1]);
    close(pfds[0]);
    execlp("spamc", "spamc", NULL);
  } else {
    close(0);
    dup(pfds[0]);
    close(pfds[1]);
    execlp("qmail-queue", "qmail-queue", NULL);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11a7 <main+0x37>
lea    0xe68(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    11d0 <main+0x60>
lea    0xe60(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x10(%rbp)
jne    120c <main+0x9c>
mov    $0x1,%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1030 <dup@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
lea    0xe40(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1080 <execlp@plt>
jmp    1236 <main+0xc6>
xor    %edi,%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
call   1030 <dup@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
lea    0xe17(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1080 <execlp@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
je     11df <main+0x6f>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11af <main+0x3f>
cmp    $0xffffffff,%eax
je     11f5 <main+0x85>
xor    %edi,%edi
call   1040 <close@plt>
mov    (%rsp),%edi
call   1030 <dup@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
lea    0xe94(%rip),%rdi
jmp    11d1 <main+0x61>
mov    $0x1,%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
call   1030 <dup@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
lea    0xe6a(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1080 <execlp@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe1a(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe25(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"Failed to create pipe; quitting\0A\00"
@.str.1 = [26 x i8] c"Failed to fork; quitting\0A\00"
@.str.2 = [6 x i8] c"spamc\00"
@.str.3 = [12 x i8] c"qmail-queue\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
store i32 0, i32* %1
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = call i32 (...) @fork()
store i32 %11, i32* %3
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 2)
unreachable
16: ; preds = %10
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = call i32 @close(i32 1)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%22 = load i32, i32* %21
%23 = call i32 @dup(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* null)
br label %37
28: ; preds = %16
%29 = call i32 @close(i32 0)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%31 = load i32, i32* %30
%32 = call i32 @dup(i32 %31)
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%34 = load i32, i32* %33
%35 = call i32 @close(i32 %34)
%36 = call i32 @execlp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %37
37: ; preds = %28, %19
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str = [33 x i8] c"Failed to create pipe; quitting\0A\00"
@.str.1 = [26 x i8] c"Failed to fork; quitting\0A\00"
@.str.2 = [6 x i8] c"spamc\00"
@.str.3 = [12 x i8] c"qmail-queue\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%4 = call i32 @pipe(i32* %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = call i32 (...) @fork()
switch i32 %10, label %22 [
i32 -1, label %11
i32 0, label %14
]
11: ; preds = %9
%12 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 2)
unreachable
14: ; preds = %9
%15 = call i32 @close(i32 1)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%17 = load i32, i32* %16
%18 = call i32 @dup(i32 %17)
%19 = load i32, i32* %3
%20 = call i32 @close(i32 %19)
%21 = call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* null)
br label %30
22: ; preds = %9
%23 = call i32 @close(i32 0)
%24 = load i32, i32* %3
%25 = call i32 @dup(i32 %24)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
%29 = call i32 @execlp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %30
30: ; preds = %22, %14
ret i32 0
}