#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execv(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int main() {
  pid_t p;
  int fd[2], ret;
  ret = pipe(fd);
  if (ret < 0) {
    perror("pipe");
    exit(1);
  }
  dup2(fd[0], 33);
  dup2(fd[1], 34);
  p = fork();
  if (p < 0) {
    perror("fork");
    exit(1);
  }
  if (p == 0)
    execv("riddle", NULL);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <pipe@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    119b <main+0x3b>
lea    0xe74(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%edi
mov    $0x21,%esi
call   1030 <dup2@plt>
mov    -0x14(%rbp),%edi
mov    $0x22,%esi
call   1030 <dup2@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11e1 <main+0x81>
lea    0xe33(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11fc <main+0x9c>
lea    0xe17(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <execv@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1040 <pipe@plt>
test   %eax,%eax
js     11a8 <main+0x48>
mov    (%rsp),%edi
mov    $0x21,%esi
call   1030 <dup2@plt>
mov    0x4(%rsp),%edi
mov    $0x22,%esi
call   1030 <dup2@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
js     11b1 <main+0x51>
jne    11a4 <main+0x44>
lea    0xe6d(%rip),%rdi
xor    %esi,%esi
call   1070 <execv@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe51(%rip),%rdi
jmp    11b8 <main+0x58>
lea    0xe4d(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [7 x i8] c"riddle\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [2 x i32]
%4 = alloca i32
store i32 0, i32* %1
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%14 = load i32, i32* %13
%15 = call i32 @dup2(i32 %14, i32 33)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%17 = load i32, i32* %16
%18 = call i32 @dup2(i32 %17, i32 34)
%19 = call i64 (...) @fork()
store i64 %19, i64* %2
%20 = load i64, i64* %2
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %12
%23 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %12
%26 = load i64, i64* %2
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @execv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* null)
br label %30
30: ; preds = %28, %25
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [7 x i8] c"riddle\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 slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = load i32, i32* %3
%11 = call i32 @dup2(i32 %10, i32 33)
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @dup2(i32 %13, i32 34)
%15 = call i64 (...) @fork()
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %9
%18 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %9
%21 = icmp eq i64 %15, 0
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = call i32 @execv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* null)
br label %24
24: ; preds = %22, %20
ret i32 0
}