#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*/ LOG_ERR;
int /*<<< orphan*/ alarm(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ hubo_rt_set_fork_signals();
int /*<<< orphan*/ pause();
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
pid_t hubo_rt_daemon_fork() {
  pid_t child = fork();
  hubo_rt_set_fork_signals();
  if (child < 0) {
    syslog(LOG_ERR, "Unable to fork daemon, code=%d (%s)", errno,
           strerror(errno));
    exit(1);
  }
  if (child > 0) {
    alarm(2);
    pause();
    exit(1);
  }
  return child;
}


x86 assembly (clang, -O0):
<hubo_rt_daemon_fork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <hubo_rt_set_fork_signals@plt>
cmpq   $0x0,-0x8(%rbp)
jge    11d9 <hubo_rt_daemon_fork+0x69>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%edx
mov    %eax,%ecx
lea    0xe36(%rip),%rsi
call   1060 <syslog@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x8(%rbp)
jle    11ff <hubo_rt_daemon_fork+0x8f>
mov    $0x2,%edi
call   1030 <alarm@plt>
mov    $0x0,%al
call   1050 <pause@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hubo_rt_daemon_fork>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1090 <fork@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <hubo_rt_set_fork_signals@plt>
test   %rbx,%rbx
js     1194 <hubo_rt_daemon_fork+0x24>
jne    11c9 <hubo_rt_daemon_fork+0x59>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e35(%rip),%rax
mov    (%rax),%ebx
mov    0x2e3c(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xe4c(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %eax,%ecx
call   1060 <syslog@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x2,%edi
call   1030 <alarm@plt>
xor    %eax,%eax
call   1050 <pause@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [36 x i8] c"Unable to fork daemon, code=%d (%s)\00"
@errno = global i32 0
define i64 @hubo_rt_daemon_fork() {
%1 = alloca i64
%2 = call i64 (...) @fork()
store i64 %2, i64* %1
%3 = call i32 (...) @hubo_rt_set_fork_signals()
%4 = load i64, i64* %1
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %0
%7 = load i32, i32* @LOG_ERR
%8 = load i32, i32* @errno
%9 = load i32, i32* @errno
%10 = call i32 @strerror(i32 %9)
%11 = call i32 @syslog(i32 %7, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = load i64, i64* %1
%15 = icmp sgt i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = call i32 @alarm(i32 2)
%18 = call i32 (...) @pause()
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %13
%21 = load i64, i64* %1
ret i64 %21
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [36 x i8] c"Unable to fork daemon, code=%d (%s)\00"
@errno = global i32 0
define i64 @hubo_rt_daemon_fork() {
%1 = tail call i64 (...) @fork()
%2 = tail call i32 (...) @hubo_rt_set_fork_signals()
%3 = icmp slt i64 %1, 0
br i1 %3, label %4, label %10
4: ; preds = %0
%5 = load i32, i32* @LOG_ERR
%6 = load i32, i32* @errno
%7 = tail call i32 @strerror(i32 %6)
%8 = tail call i32 @syslog(i32 %5, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = icmp eq i64 %1, 0
br i1 %11, label %16, label %12
12: ; preds = %10
%13 = tail call i32 @alarm(i32 2)
%14 = tail call i32 (...) @pause()
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %10
ret i64 0
}