#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
scalar_t__ chdir(char *);
int /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
scalar_t__ setsid();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int main(void) {
  pid_t pid, sid;
  pid = fork();
  if (pid < 0) {
    exit(EXIT_SUCCESS);
  }
  umask(0);
  sid = setsid();
  if (sid < 0) {
    exit(EXIT_FAILURE);
  }
  if ((chdir("/")) < 0) {
    exit(EXIT_FAILURE);
  }
  close(STDIN_FILENO);
  close(STDOUT_FILENO);
  close(STDERR_FILENO);
  while (1) {
    sleep(30);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11a3 <main+0x33>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %edi,%edi
call   1060 <umask@plt>
mov    $0x0,%al
call   1050 <setsid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11ce <main+0x5e>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe2b(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
jge    11f2 <main+0x82>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    $0x1e,%edi
call   1080 <sleep@plt>
jmp    121c <main+0xac>

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     11ea <main+0x7a>
xor    %edi,%edi
call   1060 <umask@plt>
xor    %eax,%eax
call   1050 <setsid@plt>
test   %rax,%rax
js     11dc <main+0x6c>
lea    0xe69(%rip),%rdi
call   1030 <chdir@plt>
test   %rax,%rax
js     11dc <main+0x6c>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
nopl   0x0(%rax,%rax,1)
mov    $0x1e,%edi
call   1080 <sleep@plt>
jmp    11d0 <main+0x60>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"/\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
store i32 0, i32* %1
%4 = call i64 (...) @fork()
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @EXIT_SUCCESS
%9 = call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = call i32 @umask(i32 0)
%12 = call i64 (...) @setsid()
store i64 %12, i64* %3
%13 = load i64, i64* %3
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %10
%19 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %18
%25 = load i32, i32* @STDIN_FILENO
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* @STDOUT_FILENO
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* @STDERR_FILENO
%30 = call i32 @close(i32 %29)
br label %31
31: ; preds = %24, %31
%32 = call i32 @sleep(i32 30)
br label %31
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"/\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @EXIT_SUCCESS
%5 = tail call i32 @exit(i32 %4)
unreachable
6: ; preds = %0
%7 = tail call i32 @umask(i32 0)
%8 = tail call i64 (...) @setsid()
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %6
%14 = tail call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %13
%20 = load i32, i32* @STDIN_FILENO
%21 = tail call i32 @close(i32 %20)
%22 = load i32, i32* @STDOUT_FILENO
%23 = tail call i32 @close(i32 %22)
%24 = load i32, i32* @STDERR_FILENO
%25 = tail call i32 @close(i32 %24)
br label %26
26: ; preds = %26, %19
%27 = tail call i32 @sleep(i32 30)
br label %26
}