#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*/ _SC_OPEN_MAX;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ setsid();
int sysconf(int /*<<< orphan*/);
void skeleton_daemon() {
  int pid;
  if (pid = fork())
    exit(0);
  else if (pid < 0)
    exit(1);
  setsid();
  int x;
  for (x = sysconf(_SC_OPEN_MAX); x > 0; x--) {
    close(x);
  }
}


x86 assembly (clang, -O0):
<skeleton_daemon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
je     1172 <skeleton_daemon+0x22>
xor    %edi,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x4(%rbp)
jge    1186 <skeleton_daemon+0x36>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    118b <skeleton_daemon+0x3b>
mov    $0x0,%al
call   1040 <setsid@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11c3 <skeleton_daemon+0x73>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    11a3 <skeleton_daemon+0x53>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skeleton_daemon>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jne    1193 <skeleton_daemon+0x43>
xor    %eax,%eax
call   1040 <setsid@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
test   %eax,%eax
jle    1191 <skeleton_daemon+0x41>
mov    %eax,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1030 <close@plt>
lea    -0x1(%rbx),%eax
cmp    $0x1,%ebx
mov    %eax,%ebx
ja     1180 <skeleton_daemon+0x30>
pop    %rbx
ret
xor    %edi,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@_SC_OPEN_MAX = global i32 0
define void @skeleton_daemon() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %1, 0
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = tail call i32 @exit(i32 0)
unreachable
5: ; preds = %0
%6 = tail call i32 (...) @setsid()
%7 = load i32, i32* @_SC_OPEN_MAX
%8 = tail call i32 @sysconf(i32 %7)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %5, %10
%11 = phi i32 [ %13, %10 ], [ %8, %5 ]
%12 = tail call i32 @close(i32 %11)
%13 = add nsw i32 %11, -1
%14 = icmp ugt i32 %11, 1
br i1 %14, label %10, label %15
15: ; preds = %10, %5
ret void
}