#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 LOG_CONS;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ LOG_LOCAL1;
int LOG_NDELAY;
int LOG_PID;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
scalar_t__ chdir(char *);
int /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ closelog();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ openlog(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
scalar_t__ setsid();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int /*<<< orphan*/ test_cplusplus_11();
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int main(void) {
  pid_t pid, sid;
  test_cplusplus_11();
  pid = fork();
  if (pid < 0) {
    exit(EXIT_FAILURE);
  }
  if (pid > 0) {
    exit(EXIT_SUCCESS);
  }
  printf("Child is running!\n");
  umask(0);
  sid = setsid();
  if (sid < 0) {
    exit(EXIT_FAILURE);
  }
  if ((chdir("/tmp")) < 0) {
    exit(EXIT_FAILURE);
  }
  printf("Start syslog...\n");
  close(STDIN_FILENO);
  close(STDOUT_FILENO);
  close(STDERR_FILENO);
  while (1) {
    openlog("helloworldlog", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
    syslog(LOG_INFO, "Hello world from hellod");
    closelog();
    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   10b0 <test_cplusplus_11@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11fa <main+0x3a>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jle    1213 <main+0x53>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xde6(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <umask@plt>
mov    $0x0,%al
call   1070 <setsid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    124a <main+0x8a>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xdc2(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
jge    126e <main+0xae>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xda3(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   1060 <close@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
call   1060 <close@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
call   1060 <close@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%esi
mov    0x2d24(%rip),%rax
or     (%rax),%esi
mov    %esi,-0x20(%rbp)
mov    0x2cd0(%rip),%rax
or     (%rax),%esi
mov    %esi,-0x1c(%rbp)
mov    0x2cec(%rip),%rax
mov    (%rax),%edx
lea    0xd54(%rip),%rdi
call   10a0 <openlog@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
lea    0xd4d(%rip),%rsi
call   1090 <syslog@plt>
mov    $0x0,%al
call   1030 <closelog@plt>
mov    $0x1e,%edi
call   10d0 <sleep@plt>
jmp    12a4 <main+0xe4>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   10b0 <test_cplusplus_11@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
js     12ba <main+0xfa>
jne    12c8 <main+0x108>
lea    0xe3c(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1080 <umask@plt>
xor    %eax,%eax
call   1070 <setsid@plt>
test   %rax,%rax
js     12ba <main+0xfa>
lea    0xdee(%rip),%rdi
call   1050 <chdir@plt>
test   %rax,%rax
js     12ba <main+0xfa>
lea    0xe16(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
call   1060 <close@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   1060 <close@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   1060 <close@plt>
mov    0x2d7b(%rip),%r12
mov    0x2d2c(%rip),%r13
mov    0x2d4d(%rip),%rbp
lea    0xd93(%rip),%r14
mov    0x2d2f(%rip),%r15
lea    0xd93(%rip),%rbx
mov    (%r12),%esi
mov    0x2d45(%rip),%rax
or     (%rax),%esi
or     0x0(%r13),%esi
mov    0x0(%rbp),%edx
mov    %r14,%rdi
call   10a0 <openlog@plt>
mov    (%r15),%edi
mov    %rbx,%rsi
call   1090 <syslog@plt>
xor    %eax,%eax
call   1030 <closelog@plt>
mov    $0x1e,%edi
call   10d0 <sleep@plt>
jmp    1280 <main+0xc0>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@.str = [19 x i8] c"Child is running!\0A\00"
@.str.1 = [5 x i8] c"/tmp\00"
@.str.2 = [17 x i8] c"Start syslog...\0A\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.3 = [14 x i8] c"helloworldlog\00"
@LOG_CONS = global i32 0
@LOG_PID = global i32 0
@LOG_NDELAY = global i32 0
@LOG_LOCAL1 = global i32 0
@LOG_INFO = global i32 0
@.str.4 = [24 x i8] c"Hello world from hellod\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
store i32 0, i32* %1
%4 = call i32 (...) @test_cplusplus_11()
%5 = call i64 (...) @fork()
store i64 %5, i64* %2
%6 = load i64, i64* %2
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = load i64, i64* %2
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* @EXIT_SUCCESS
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %11
%18 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @umask(i32 0)
%20 = call i64 (...) @setsid()
store i64 %20, i64* %3
%21 = load i64, i64* %3
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %17
%27 = call i64 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %26
%33 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* @STDIN_FILENO
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* @STDOUT_FILENO
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* @STDERR_FILENO
%39 = call i32 @close(i32 %38)
br label %40
40: ; preds = %32, %40
%41 = load i32, i32* @LOG_CONS
%42 = load i32, i32* @LOG_PID
%43 = or i32 %41, %42
%44 = load i32, i32* @LOG_NDELAY
%45 = or i32 %43, %44
%46 = load i32, i32* @LOG_LOCAL1
%47 = call i32 @openlog(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %45, i32 %46)
%48 = load i32, i32* @LOG_INFO
%49 = call i32 @syslog(i32 %48, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%50 = call i32 (...) @closelog()
%51 = call i32 @sleep(i32 30)
br label %40
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.1 = [5 x i8] c"/tmp\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.3 = [14 x i8] c"helloworldlog\00"
@LOG_CONS = global i32 0
@LOG_PID = global i32 0
@LOG_NDELAY = global i32 0
@LOG_LOCAL1 = global i32 0
@LOG_INFO = global i32 0
@.str.4 = [24 x i8] c"Hello world from hellod\00"
@str = [18 x i8] c"Child is running!\00"
@str.5 = [16 x i8] c"Start syslog...\00"
define i32 @main() {
%1 = tail call i32 (...) @test_cplusplus_11()
%2 = tail call i64 (...) @fork()
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = load i32, i32* @EXIT_FAILURE
%6 = tail call i32 @exit(i32 %5)
unreachable
7: ; preds = %0
%8 = icmp eq i64 %2, 0
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = load i32, i32* @EXIT_SUCCESS
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @umask(i32 0)
%15 = tail call i64 (...) @setsid()
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %12
%21 = tail call i64 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %20
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.5, i64 0, i64 0))
%28 = load i32, i32* @STDIN_FILENO
%29 = tail call i32 @close(i32 %28)
%30 = load i32, i32* @STDOUT_FILENO
%31 = tail call i32 @close(i32 %30)
%32 = load i32, i32* @STDERR_FILENO
%33 = tail call i32 @close(i32 %32)
br label %34
34: ; preds = %34, %26
%35 = load i32, i32* @LOG_CONS
%36 = load i32, i32* @LOG_PID
%37 = or i32 %36, %35
%38 = load i32, i32* @LOG_NDELAY
%39 = or i32 %37, %38
%40 = load i32, i32* @LOG_LOCAL1
%41 = tail call i32 @openlog(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %39, i32 %40)
%42 = load i32, i32* @LOG_INFO
%43 = tail call i32 @syslog(i32 %42, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%44 = tail call i32 (...) @closelog()
%45 = tail call i32 @sleep(i32 30)
br label %34
}