#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, ...);
int getpgrp();
int getpid();
int getppid();
int getsid(int /*<<< orphan*/);
int /*<<< orphan*/ my_daemon();
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  my_daemon();
  int t = 0;
  FILE *fp = fopen("/root/tmp.txt", "a");
  fprintf(fp, "ppid = %d, pid = %d, sid = %d, pgrp = %d\n", getppid(), getpid(),
          getsid(0), getpgrp());
  fflush(fp);
  do {
    fprintf(fp, "%d\n", t);
    fflush(fp);
    sleep(2);
    t += 2;
  } while (t < 30);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <my_daemon@plt>
movl   $0x0,-0x14(%rbp)
lea    0xe35(%rip),%rdi
lea    0xe3c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   10b0 <getppid@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x28(%rbp)
xor    %edi,%edi
call   1050 <getsid@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1090 <getpgrp@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    %eax,%r9d
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1080 <fflush@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1e,-0x14(%rbp)
jl     1230 <main+0x90>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <my_daemon@plt>
lea    0xe4b(%rip),%rdi
lea    0xe52(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10b0 <getppid@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r15d
xor    %edi,%edi
call   1050 <getsid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1090 <getpgrp@plt>
lea    0xe21(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    %ebp,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
lea    0xe22(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xc,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xe,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x12,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x14,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x16,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x18,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1a,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1c,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/root/tmp.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [42 x i8] c"ppid = %d, pid = %d, sid = %d, pgrp = %d\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @my_daemon()
store i32 0, i32* %6
%9 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = call i32 (...) @getppid()
%12 = call i32 (...) @getpid()
%13 = call i32 @getsid(i32 0)
%14 = call i32 (...) @getpgrp()
%15 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %12, i32 %13, i32 %14)
%16 = load i32*, i32** %7
%17 = call i32 @fflush(i32* %16)
br label %18
18: ; preds = %27, %2
%19 = load i32*, i32** %7
%20 = load i32, i32* %6
%21 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = load i32*, i32** %7
%23 = call i32 @fflush(i32* %22)
%24 = call i32 @sleep(i32 2)
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 2
store i32 %26, i32* %6
br label %27
27: ; preds = %18
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 30
br i1 %29, label %18, label %30
30: ; preds = %27
%31 = load i32*, i32** %7
%32 = call i32 @fclose(i32* %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/root/tmp.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [42 x i8] c"ppid = %d, pid = %d, sid = %d, pgrp = %d\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @my_daemon()
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 (...) @getppid()
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 @getsid(i32 0)
%8 = tail call i32 (...) @getpgrp()
%9 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %5, i32 %6, i32 %7, i32 %8)
%10 = tail call i32 @fflush(i32* %4)
%11 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%12 = tail call i32 @fflush(i32* %4)
%13 = tail call i32 @sleep(i32 2)
%14 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 2)
%15 = tail call i32 @fflush(i32* %4)
%16 = tail call i32 @sleep(i32 2)
%17 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 4)
%18 = tail call i32 @fflush(i32* %4)
%19 = tail call i32 @sleep(i32 2)
%20 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 6)
%21 = tail call i32 @fflush(i32* %4)
%22 = tail call i32 @sleep(i32 2)
%23 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 8)
%24 = tail call i32 @fflush(i32* %4)
%25 = tail call i32 @sleep(i32 2)
%26 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 10)
%27 = tail call i32 @fflush(i32* %4)
%28 = tail call i32 @sleep(i32 2)
%29 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 12)
%30 = tail call i32 @fflush(i32* %4)
%31 = tail call i32 @sleep(i32 2)
%32 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 14)
%33 = tail call i32 @fflush(i32* %4)
%34 = tail call i32 @sleep(i32 2)
%35 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 16)
%36 = tail call i32 @fflush(i32* %4)
%37 = tail call i32 @sleep(i32 2)
%38 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 18)
%39 = tail call i32 @fflush(i32* %4)
%40 = tail call i32 @sleep(i32 2)
%41 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 20)
%42 = tail call i32 @fflush(i32* %4)
%43 = tail call i32 @sleep(i32 2)
%44 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 22)
%45 = tail call i32 @fflush(i32* %4)
%46 = tail call i32 @sleep(i32 2)
%47 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 24)
%48 = tail call i32 @fflush(i32* %4)
%49 = tail call i32 @sleep(i32 2)
%50 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 26)
%51 = tail call i32 @fflush(i32* %4)
%52 = tail call i32 @sleep(i32 2)
%53 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 28)
%54 = tail call i32 @fflush(i32* %4)
%55 = tail call i32 @sleep(i32 2)
%56 = tail call i32 @fclose(i32* %4)
ret i32 0
}