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

/* Variables and functions */
int /*<<< orphan*/ Daemon(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int getpid();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int main() {
  char log_file_name[255] = {0};
  snprintf(log_file_name, sizeof(log_file_name), "/tmp/daemon_%d.log",
           getpid());
  FILE *pf_log = fopen(log_file_name, "a+");
  Daemon(0, 0);
  int i = 10;
  while (--i) {
    fprintf(pf_log, "program(%d) is running\n", getpid());
    fflush(pf_log);
    sleep(2);
  }
  fclose(pf_log);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1060 <memset@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x128(%rbp),%rdi
mov    %eax,%ecx
mov    $0xff,%esi
lea    0xe21(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x118(%rbp)
xor    %esi,%esi
mov    %esi,%edi
call   1090 <Daemon@plt>
movl   $0xa,-0x11c(%rbp)
mov    -0x11c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x11c(%rbp)
cmp    $0x0,%eax
je     126e <main+0xde>
mov    -0x118(%rbp),%rax
mov    %rax,-0x130(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x130(%rbp),%rdi
mov    %eax,%edx
lea    0xdc8(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x118(%rbp),%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10b0 <sleep@plt>
jmp    1211 <main+0x81>
mov    -0x118(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x108,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0xef(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xdfe(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %eax,%ecx
call   1050 <snprintf@plt>
lea    0xdf8(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
xor    %esi,%esi
call   1080 <Daemon@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xdd9(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/tmp/daemon_%d.log\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [24 x i8] c"program(%d) is running\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [255 x i8]
%3 = alloca i32*
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [255 x i8]* %2 to i8*
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%7 = call i32 (...) @getpid()
%8 = call i32 @snprintf(i8* %6, i32 255, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %3
%11 = call i32 @Daemon(i32 0, i32 0)
store i32 10, i32* %4
br label %12
12: ; preds = %16, %0
%13 = load i32, i32* %4
%14 = add nsw i32 %13, -1
store i32 %14, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i32*, i32** %3
%18 = call i32 (...) @getpid()
%19 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %3
%21 = call i32 @fflush(i32* %20)
%22 = call i32 @sleep(i32 2)
br label %12
23: ; preds = %12
%24 = load i32*, i32** %3
%25 = call i32 @fclose(i32* %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"/tmp/daemon_%d.log\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [24 x i8] c"program(%d) is running\0A\00"
define i32 @main() {
%1 = alloca [255 x i8]
%2 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @getpid()
%4 = call i32 @snprintf(i8* %2, i32 255, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @Daemon(i32 0, i32 0)
%7 = call i32 (...) @getpid()
%8 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = call i32 @fflush(i32* %5)
%10 = call i32 @sleep(i32 2)
%11 = call i32 (...) @getpid()
%12 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = call i32 @fflush(i32* %5)
%14 = call i32 @sleep(i32 2)
%15 = call i32 (...) @getpid()
%16 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = call i32 @fflush(i32* %5)
%18 = call i32 @sleep(i32 2)
%19 = call i32 (...) @getpid()
%20 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = call i32 @fflush(i32* %5)
%22 = call i32 @sleep(i32 2)
%23 = call i32 (...) @getpid()
%24 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = call i32 @fflush(i32* %5)
%26 = call i32 @sleep(i32 2)
%27 = call i32 (...) @getpid()
%28 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = call i32 @fflush(i32* %5)
%30 = call i32 @sleep(i32 2)
%31 = call i32 (...) @getpid()
%32 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = call i32 @fflush(i32* %5)
%34 = call i32 @sleep(i32 2)
%35 = call i32 (...) @getpid()
%36 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = call i32 @fflush(i32* %5)
%38 = call i32 @sleep(i32 2)
%39 = call i32 (...) @getpid()
%40 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = call i32 @fflush(i32* %5)
%42 = call i32 @sleep(i32 2)
%43 = call i32 @fclose(i32* %5)
ret i32 0
}