#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 close(int);
int dup2(int, int);
int setsid();
int process_son(int p[2]) {
  if ((setsid()) == -1)
    return (-1);
  if ((close(p[0])) == -1)
    return (-1);
  if ((dup2(p[1], 1)) == -1)
    return (-1);
  return (0);
}


x86 assembly (clang, -O0):
<process_son>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <setsid@plt>
cmp    $0xffffffff,%eax
jne    1158 <process_son+0x28>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <process_son+0x75>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    1178 <process_son+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <process_son+0x75>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    119e <process_son+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <process_son+0x75>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_son>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <setsid@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     116d <process_son+0x3d>
mov    (%r14),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
je     116d <process_son+0x3d>
mov    0x4(%r14),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
sete   %bl
neg    %ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @process_son(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
store i32* %0, i32** %3
%4 = call i32 (...) @setsid()
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 -1, i32* %2
br label %22
7: ; preds = %1
%8 = load i32*, i32** %3
%9 = getelementptr inbounds i32, i32* %8, i64 0
%10 = load i32, i32* %9
%11 = call i32 @close(i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %7
store i32 -1, i32* %2
br label %22
14: ; preds = %7
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 1
%17 = load i32, i32* %16
%18 = call i32 @dup2(i32 %17, i32 1)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 -1, i32* %2
br label %22
21: ; preds = %14
store i32 0, i32* %2
br label %22
22: ; preds = %21, %20, %13, %6
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
define i32 @process_son(i32* nocapture %0) {
%2 = tail call i32 (...) @setsid()
%3 = icmp eq i32 %2, -1
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = load i32, i32* %0
%6 = tail call i32 @close(i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = getelementptr inbounds i32, i32* %0, i64 1
%10 = load i32, i32* %9
%11 = tail call i32 @dup2(i32 %10, i32 1)
%12 = icmp eq i32 %11, -1
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %8, %4, %1
%15 = phi i32 [ -1, %1 ], [ -1, %4 ], [ %13, %8 ]
ret i32 %15
}