#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 EXIT_SUCCESS;
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main() {
  pid_t pid;
  pid = fork();
  if (pid != 0)
    exit(EXIT_SUCCESS);
  chdir("/");
  setsid();
  printf("%d\n", getpid());
  fclose(stdin);
  fclose(stdout);
  fclose(stderr);
  while (1) {
    sleep(32);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b3 <main+0x33>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe46(%rip),%rdi
call   1050 <chdir@plt>
mov    $0x0,%al
call   1070 <setsid@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe2c(%rip),%rdi
call   1060 <printf@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1040 <fclose@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1040 <fclose@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1040 <fclose@plt>
mov    $0x20,%edi
call   1090 <sleep@plt>
jmp    1205 <main+0x85>

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
jne    11ec <main+0x6c>
lea    0xe6c(%rip),%rdi
call   1050 <chdir@plt>
xor    %eax,%eax
call   1070 <setsid@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe54(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1040 <fclose@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1040 <fclose@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1040 <fclose@plt>
nop
mov    $0x20,%edi
call   1090 <sleep@plt>
jmp    11e0 <main+0x60>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@.str = [2 x i8] c"/\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@stdin = global i32 0
@stdout = global i32 0
@stderr = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i64 (...) @fork()
store i64 %3, i64* %2
%4 = load i64, i64* %2
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @EXIT_SUCCESS
%8 = call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (...) @setsid()
%12 = call i32 (...) @getpid()
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @stdin
%15 = call i32 @fclose(i32 %14)
%16 = load i32, i32* @stdout
%17 = call i32 @fclose(i32 %16)
%18 = load i32, i32* @stderr
%19 = call i32 @fclose(i32 %18)
br label %20
20: ; preds = %9, %20
%21 = call i32 @sleep(i32 32)
br label %20
}

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