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

/* Variables and functions */
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, const char **argv) {
  pid_t pid;
  if (0 == (pid = fork())) {
    chdir("/");
    setsid();
    fclose(stdin);
    fclose(stdout);
    fclose(stderr);
    while (1) {
    }
  } else {
    printf("%d\n", pid);
  }
  return 0;
}


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)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jne    11be <main+0x6e>
lea    0xe7d(%rip),%rdi
call   1040 <chdir@plt>
mov    $0x0,%al
call   1060 <setsid@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
jmp    11b9 <main+0x69>
mov    -0x14(%rbp),%esi
lea    0xe3a(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     116e <main+0x1e>
lea    0xe9f(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe8b(%rip),%rdi
call   1040 <chdir@plt>
xor    %eax,%eax
call   1060 <setsid@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
nopl   0x0(%rax,%rax,1)
jmp    11b0 <main+0x60>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@stdin = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
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 = call i32 (...) @fork()
store i32 %7, i32* %6
%8 = icmp eq i32 0, %7
br i1 %8, label %9, label %19
9: ; preds = %2
%10 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (...) @setsid()
%12 = load i32, i32* @stdin
%13 = call i32 @fclose(i32 %12)
%14 = load i32, i32* @stdout
%15 = call i32 @fclose(i32 %14)
%16 = load i32, i32* @stderr
%17 = call i32 @fclose(i32 %16)
br label %18
18: ; preds = %9, %18
br label %18
19: ; preds = %2
%20 = load i32, i32* %6
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@stdin = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %2
%6 = tail call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (...) @setsid()
%8 = load i32, i32* @stdin
%9 = tail call i32 @fclose(i32 %8)
%10 = load i32, i32* @stdout
%11 = tail call i32 @fclose(i32 %10)
%12 = load i32, i32* @stderr
%13 = tail call i32 @fclose(i32 %12)
br label %14
14: ; preds = %14, %5
br label %14
15: ; preds = %2
%16 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %3)
ret i32 0
}