#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 /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ setsid();
void init_daemon() {
  int pid;
  pid = fork();
  if (pid < 0)
    exit(1);
  else if (pid > 0)
    exit(0);
  setsid();
  pid = fork();
  if (pid > 0)
    exit(0);
  else if (pid < 0)
    exit(1);
  return;
}


x86 assembly (clang, -O0):
<init_daemon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1156 <init_daemon+0x26>
mov    $0x1,%edi
call   1040 <exit@plt>
cmpl   $0x0,-0x4(%rbp)
jle    1167 <init_daemon+0x37>
xor    %edi,%edi
call   1040 <exit@plt>
jmp    116c <init_daemon+0x3c>
mov    $0x0,%al
call   1030 <setsid@plt>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    118e <init_daemon+0x5e>
xor    %edi,%edi
call   1040 <exit@plt>
cmpl   $0x0,-0x4(%rbp)
jge    11a2 <init_daemon+0x72>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    11a7 <init_daemon+0x77>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_daemon>:
push   %rax
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
js     1154 <init_daemon+0x24>
jne    115e <init_daemon+0x2e>
xor    %eax,%eax
call   1030 <setsid@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
jg     115e <init_daemon+0x2e>
js     1154 <init_daemon+0x24>
pop    %rax
ret
mov    $0x1,%edi
call   1040 <exit@plt>
xor    %edi,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
define void @init_daemon() {
%1 = alloca i32
%2 = call i32 (...) @fork()
store i32 %2, i32* %1
%3 = load i32, i32* %1
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %7
br label %13
13: ; preds = %12
%14 = call i32 (...) @setsid()
%15 = call i32 (...) @fork()
store i32 %15, i32* %1
%16 = load i32, i32* %1
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %13
%21 = load i32, i32* %1
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %20
br label %26
26: ; preds = %25
ret void
}

LLVM IR (-O2):
define void @init_daemon() {
%1 = tail call i32 (...) @fork()
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @exit(i32 1)
unreachable
5: ; preds = %0
%6 = icmp eq i32 %1, 0
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %5
%10 = tail call i32 (...) @setsid()
%11 = tail call i32 (...) @fork()
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %9
%16 = icmp slt i32 %11, 0
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %15
ret void
}