#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*/ alarm(int);
int /*<<< orphan*/ daemon_main();
int fork();
int setsid();
int /*<<< orphan*/ sleep(int);
int main() {
  pid_t child;
  alarm(60);
  child = fork();
  if (child == -1)
    return 1;
  else if (child != 0)
    return 0;
  else {
    pid_t session = setsid();
    if (session == -1)
      return 1;
    child = fork();
    if (child == -1)
      return 1;
    else if (child != 0)
      return 0;
    daemon_main();
    while (1)
      sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3c,%edi
call   1030 <alarm@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1189 <main+0x39>
movl   $0x1,-0x4(%rbp)
jmp    1210 <main+0xc0>
cmpl   $0x0,-0x8(%rbp)
je     119f <main+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    1210 <main+0xc0>
mov    $0x0,%al
call   1040 <setsid@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11bf <main+0x6f>
movl   $0x1,-0x4(%rbp)
jmp    1210 <main+0xc0>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11df <main+0x8f>
movl   $0x1,-0x4(%rbp)
jmp    1210 <main+0xc0>
cmpl   $0x0,-0x8(%rbp)
je     11f5 <main+0xa5>
movl   $0x0,-0x4(%rbp)
jmp    1210 <main+0xc0>
jmp    11fa <main+0xaa>
mov    $0x0,%al
call   1050 <daemon_main@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    1201 <main+0xb1>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x3c,%edi
call   1030 <alarm@plt>
xor    %eax,%eax
call   1070 <fork@plt>
mov    $0x1,%ebx
cmp    $0xffffffff,%eax
je     11ae <main+0x5e>
test   %eax,%eax
jne    11ac <main+0x5c>
xor    %eax,%eax
call   1040 <setsid@plt>
cmp    $0xffffffff,%eax
je     11ae <main+0x5e>
xor    %eax,%eax
call   1070 <fork@plt>
cmp    $0xffffffff,%eax
je     11ae <main+0x5e>
test   %eax,%eax
jne    11ac <main+0x5c>
xor    %eax,%eax
call   1050 <daemon_main@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    11a0 <main+0x50>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @alarm(i32 60)
%5 = call i32 (...) @fork()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 1, i32* %1
br label %32
9: ; preds = %0
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 0, i32* %1
br label %32
13: ; preds = %9
%14 = call i32 (...) @setsid()
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 1, i32* %1
br label %32
18: ; preds = %13
%19 = call i32 (...) @fork()
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 1, i32* %1
br label %32
23: ; preds = %18
%24 = load i32, i32* %2
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 0, i32* %1
br label %32
27: ; preds = %23
br label %28
28: ; preds = %27
%29 = call i32 (...) @daemon_main()
br label %30
30: ; preds = %28, %30
%31 = call i32 @sleep(i32 1)
br label %30
32: ; preds = %26, %22, %17, %12, %8
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32 @alarm(i32 60)
%2 = tail call i32 (...) @fork()
switch i32 %2, label %3 [
i32 -1, label %14
i32 0, label %4
]
3: ; preds = %0
br label %14
4: ; preds = %0
%5 = tail call i32 (...) @setsid()
%6 = icmp eq i32 %5, -1
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = tail call i32 (...) @fork()
switch i32 %8, label %9 [
i32 -1, label %14
i32 0, label %10
]
9: ; preds = %7
br label %14
10: ; preds = %7
%11 = tail call i32 (...) @daemon_main()
br label %12
12: ; preds = %12, %10
%13 = tail call i32 @sleep(i32 1)
br label %12
14: ; preds = %9, %4, %7, %0, %3
%15 = phi i32 [ 0, %3 ], [ 1, %0 ], [ 0, %9 ], [ 1, %4 ], [ 1, %7 ]
ret i32 %15
}