#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ LOG_DAEMON;
int /*<<< orphan*/ LOG_DEBUG;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ LOG_PID;
int /*<<< orphan*/ closelog();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
scalar_t__ mydaemon();
int /*<<< orphan*/ openlog(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
int main() {
  FILE *fp;
  int i;
  openlog("mydaemon", LOG_PID, LOG_DAEMON);
  if (mydaemon()) {
    exit(1);
  } else {
    syslog(LOG_INFO, "mydaemon() successed.");
  }
  fp = fopen("/tmp/out", "w");
  if (fp == NULL) {
    syslog(LOG_ERR, "fopen():%s", strerror(errno));
    exit(1);
  }
  syslog(LOG_DEBUG, "%s was opened.", "/tmp/out");
  for (i = 0;; i++) {
    fprintf(fp, "%d\n", i);
    syslog(LOG_DEBUG, "%d was printed.", i);
    sleep(1);
    fflush(fp);
  }
  fclose(fp);
  closelog();
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
lea    0xe48(%rip),%rdi
call   1080 <openlog@plt>
mov    $0x0,%al
call   1030 <mydaemon@plt>
cmp    $0x0,%rax
je     11d8 <main+0x48>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
lea    0xe29(%rip),%rdi
lea    0xe2b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1248 <main+0xb8>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%edx
lea    0xdf3(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
lea    0xdc0(%rip),%rdx
mov    $0x0,%al
call   1060 <syslog@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xdc9(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fflush@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    126d <main+0xdd>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
lea    0xe4f(%rip),%rdi
call   1080 <openlog@plt>
xor    %eax,%eax
call   1030 <mydaemon@plt>
test   %rax,%rax
jne    1264 <main+0xd4>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
xor    %eax,%eax
call   1060 <syslog@plt>
lea    0xe3b(%rip),%rdi
lea    0xe3d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     126e <main+0xde>
mov    %rax,%rbx
mov    0x2dc9(%rip),%r12
mov    (%r12),%edi
lea    0xe2b(%rip),%rsi
lea    0xe0e(%rip),%rdx
xor    %eax,%eax
call   1060 <syslog@plt>
lea    0xe25(%rip),%r14
lea    0xe22(%rip),%r15
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <fprintf@plt>
mov    (%r12),%edi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    %rbx,%rdi
call   1050 <fflush@plt>
add    $0x1,%ebp
jmp    1230 <main+0xa0>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd9e(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"mydaemon\00"
@LOG_PID = global i32 0
@LOG_DAEMON = global i32 0
@LOG_INFO = global i32 0
@.str.1 = [22 x i8] c"mydaemon() successed.\00"
@.str.2 = [9 x i8] c"/tmp/out\00"
@.str.3 = [2 x i8] c"w\00"
@LOG_ERR = global i32 0
@.str.4 = [11 x i8] c"fopen():%s\00"
@errno = global i32 0
@LOG_DEBUG = global i32 0
@.str.5 = [15 x i8] c"%s was opened.\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@.str.7 = [16 x i8] c"%d was printed.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @LOG_PID
%5 = load i32, i32* @LOG_DAEMON
%6 = call i32 @openlog(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
%7 = call i64 (...) @mydaemon()
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32, i32* @LOG_INFO
%13 = call i32 (i32, i8*, ...) @syslog(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %11
%15 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %15, i32** %2
%16 = load i32*, i32** %2
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32, i32* @LOG_ERR
%20 = load i32, i32* @errno
%21 = call i32 @strerror(i32 %20)
%22 = call i32 (i32, i8*, ...) @syslog(i32 %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %14
%25 = load i32, i32* @LOG_DEBUG
%26 = call i32 (i32, i8*, ...) @syslog(i32 %25, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %27
27: ; preds = %37, %24
%28 = load i32*, i32** %2
%29 = load i32, i32* %3
%30 = call i32 @fprintf(i32* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %29)
%31 = load i32, i32* @LOG_DEBUG
%32 = load i32, i32* %3
%33 = call i32 (i32, i8*, ...) @syslog(i32 %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i32 %32)
%34 = call i32 @sleep(i32 1)
%35 = load i32*, i32** %2
%36 = call i32 @fflush(i32* %35)
br label %37
37: ; preds = %27
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %27
}

LLVM IR (-O2):
@.str = [9 x i8] c"mydaemon\00"
@LOG_PID = global i32 0
@LOG_DAEMON = global i32 0
@LOG_INFO = global i32 0
@.str.1 = [22 x i8] c"mydaemon() successed.\00"
@.str.2 = [9 x i8] c"/tmp/out\00"
@.str.3 = [2 x i8] c"w\00"
@LOG_ERR = global i32 0
@.str.4 = [11 x i8] c"fopen():%s\00"
@errno = global i32 0
@LOG_DEBUG = global i32 0
@.str.5 = [15 x i8] c"%s was opened.\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@.str.7 = [16 x i8] c"%d was printed.\00"
define i32 @main() {
%1 = load i32, i32* @LOG_PID
%2 = load i32, i32* @LOG_DAEMON
%3 = tail call i32 @openlog(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%4 = tail call i64 (...) @mydaemon()
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = load i32, i32* @LOG_INFO
%10 = tail call i32 (i32, i8*, ...) @syslog(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = load i32, i32* @LOG_ERR
%15 = load i32, i32* @errno
%16 = tail call i32 @strerror(i32 %15)
%17 = tail call i32 (i32, i8*, ...) @syslog(i32 %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %8
%20 = load i32, i32* @LOG_DEBUG
%21 = tail call i32 (i32, i8*, ...) @syslog(i32 %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %22, %19
%23 = phi i32 [ 0, %19 ], [ %29, %22 ]
%24 = tail call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %23)
%25 = load i32, i32* @LOG_DEBUG
%26 = tail call i32 (i32, i8*, ...) @syslog(i32 %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i32 %23)
%27 = tail call i32 @sleep(i32 1)
%28 = tail call i32 @fflush(i32* %11)
%29 = add nuw nsw i32 %23, 1
br label %22
}