#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 STDIN_FILENO;
int STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execlp(char *, char *, int /*<<< orphan*/ *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ pipe(int *);
int /*<<< orphan*/ stderr;
int start_dcc_subprocess(int *fd_in, int *fd_out) {
  int outpipe[2];
  if (pipe(outpipe) != 0)
    return -1;
  int inpipe[2];
  if (pipe(inpipe) != 0)
    return -1;
  *fd_in = inpipe[0];
  *fd_out = outpipe[1];
  pid_t pid = fork();
  if (pid == 0) {
    close(STDIN_FILENO);
    close(STDOUT_FILENO);
    dup2(outpipe[0], STDIN_FILENO);
    close(outpipe[1]);
    dup2(inpipe[1], STDOUT_FILENO);
    close(inpipe[0]);
    fprintf(stderr, "in the child\n");
    execlp("zynq-dcc", "zynq-dcc", NULL);
    fprintf(stderr, "after exec, didn't work!\n");
  } else {
    fprintf(stderr, "in parent, pid %u\n", pid);
    close(outpipe[0]);
    close(inpipe[1]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<start_dcc_subprocess>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0x0,%rax
je     118f <start_dcc_subprocess+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    129c <start_dcc_subprocess+0x13c>
lea    -0x28(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0x0,%rax
je     11ae <start_dcc_subprocess+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    129c <start_dcc_subprocess+0x13c>
mov    -0x28(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    126a <start_dcc_subprocess+0x10a>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%edi
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x24(%rbp),%edi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x28(%rbp),%edi
call   1040 <close@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    0xdcc(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1070 <execlp@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1295 <start_dcc_subprocess+0x135>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_dcc_subprocess>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    126a <start_dcc_subprocess+0x10a>
mov    %rsp,%rdi
call   1050 <pipe@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    126a <start_dcc_subprocess+0x10a>
mov    (%rsp),%eax
mov    %eax,(%r15)
mov    0xc(%rsp),%eax
mov    %eax,(%r14)
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11e9 <start_dcc_subprocess+0x89>
mov    0x2e19(%rip),%rcx
mov    (%rcx),%edi
lea    0xe69(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
jmp    126a <start_dcc_subprocess+0x10a>
mov    0x2de0(%rip),%rbx
mov    (%rbx),%edi
call   1040 <close@plt>
mov    0x2df2(%rip),%r14
mov    (%r14),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
mov    (%rbx),%esi
call   1030 <dup2@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
mov    (%r14),%esi
call   1030 <dup2@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x2da3(%rip),%r14
mov    (%r14),%edi
lea    0xdc1(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xdbf(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1070 <execlp@plt>
mov    (%r14),%edi
lea    0xdb4(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"in the child\0A\00"
@.str.1 = [9 x i8] c"zynq-dcc\00"
@.str.2 = [26 x i8] c"after exec, didn't work!\0A\00"
@.str.3 = [19 x i8] c"in parent, pid %u\0A\00"
define i32 @start_dcc_subprocess(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [2 x i32]
%7 = alloca [2 x i32]
%8 = alloca i64
store i32* %0, i32** %4
store i32* %1, i32** %5
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%10 = call i64 @pipe(i32* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %63
13: ; preds = %2
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%15 = call i64 @pipe(i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -1, i32* %3
br label %63
18: ; preds = %13
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%20 = load i32, i32* %19
%21 = load i32*, i32** %4
store i32 %20, i32* %21
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%23 = load i32, i32* %22
%24 = load i32*, i32** %5
store i32 %23, i32* %24
%25 = call i64 (...) @fork()
store i64 %25, i64* %8
%26 = load i64, i64* %8
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %52
28: ; preds = %18
%29 = load i32, i32* @STDIN_FILENO
%30 = call i32 @close(i32 %29)
%31 = load i32, i32* @STDOUT_FILENO
%32 = call i32 @close(i32 %31)
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%34 = load i32, i32* %33
%35 = load i32, i32* @STDIN_FILENO
%36 = call i32 @dup2(i32 %34, i32 %35)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32 @close(i32 %38)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%41 = load i32, i32* %40
%42 = load i32, i32* @STDOUT_FILENO
%43 = call i32 @dup2(i32 %41, i32 %42)
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%45 = load i32, i32* %44
%46 = call i32 @close(i32 %45)
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%49 = call i32 @execlp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* null)
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %62
52: ; preds = %18
%53 = load i32, i32* @stderr
%54 = load i64, i64* %8
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 %54)
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%57 = load i32, i32* %56
%58 = call i32 @close(i32 %57)
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%60 = load i32, i32* %59
%61 = call i32 @close(i32 %60)
br label %62
62: ; preds = %52, %28
store i32 0, i32* %3
br label %63
63: ; preds = %62, %17, %12
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"in the child\0A\00"
@.str.1 = [9 x i8] c"zynq-dcc\00"
@.str.2 = [26 x i8] c"after exec, didn't work!\0A\00"
@.str.3 = [19 x i8] c"in parent, pid %u\0A\00"
define i32 @start_dcc_subprocess(i32* nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
%5 = bitcast [2 x i32]* %3 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%7 = call i64 @pipe(i32* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %51
9: ; preds = %2
%10 = bitcast [2 x i32]* %4 to i8*
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%12 = call i64 @pipe(i32* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %49
14: ; preds = %9
%15 = load i32, i32* %11
store i32 %15, i32* %0
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%17 = load i32, i32* %16
store i32 %17, i32* %1
%18 = call i64 (...) @fork()
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %41
20: ; preds = %14
%21 = load i32, i32* @STDIN_FILENO
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* @STDOUT_FILENO
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %6
%26 = load i32, i32* @STDIN_FILENO
%27 = call i32 @dup2(i32 %25, i32 %26)
%28 = load i32, i32* %16
%29 = call i32 @close(i32 %28)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%31 = load i32, i32* %30
%32 = load i32, i32* @STDOUT_FILENO
%33 = call i32 @dup2(i32 %31, i32 %32)
%34 = load i32, i32* %11
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%38 = call i32 @execlp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* null)
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %49
41: ; preds = %14
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 %18)
%44 = load i32, i32* %6
%45 = call i32 @close(i32 %44)
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%47 = load i32, i32* %46
%48 = call i32 @close(i32 %47)
br label %49
49: ; preds = %20, %41, %9
%50 = phi i32 [ -1, %9 ], [ 0, %41 ], [ 0, %20 ]
br label %51
51: ; preds = %2, %49
%52 = phi i32 [ %50, %49 ], [ -1, %2 ]
ret i32 %52
}