#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 */

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int STDOUT_FILENO;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ close(int);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int out_fd = open("dummy_out.txt", O_CREAT | O_WRONLY, S_IRWXU);
  while (1) {
    sleep(1);
    {
      char *str = "stdout: Still alive!\n";
      write(STDOUT_FILENO, str, strlen(str));
    }
    {
      char *str = "outfile: Still alive!\n";
      write(out_fd, str, strlen(str));
    }
  }
  close(out_fd);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    0x2e5a(%rip),%rax
or     (%rax),%esi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
lea    0xe88(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1,%edi
call   1060 <sleep@plt>
lea    0xe7d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xe5d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    1180 <main+0x40>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2ea9(%rip),%rax
mov    0x2e6a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
lea    0xe96(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%r14d
mov    0x2e6f(%rip),%r12
lea    0xe8e(%rip),%r15
lea    0xe9d(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%r12),%ebx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    1190 <main+0x50>

LLVM IR (-O0):
@.str = [14 x i8] c"dummy_out.txt\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [22 x i8] c"stdout: Still alive!\0A\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [23 x i8] c"outfile: Still alive!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @O_CREAT
%10 = load i32, i32* @O_WRONLY
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IRWXU
%13 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
store i32 %13, i32* %6
br label %14
14: ; preds = %2, %14
%15 = call i32 @sleep(i32 1)
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8** %7
%16 = load i32, i32* @STDOUT_FILENO
%17 = load i8*, i8** %7
%18 = load i8*, i8** %7
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @write(i32 %16, i8* %17, i32 %19)
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8** %8
%21 = load i32, i32* %6
%22 = load i8*, i8** %8
%23 = load i8*, i8** %8
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @write(i32 %21, i8* %22, i32 %24)
br label %14
}

LLVM IR (-O2):
@.str = [14 x i8] c"dummy_out.txt\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [22 x i8] c"stdout: Still alive!\0A\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [23 x i8] c"outfile: Still alive!\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_WRONLY
%5 = or i32 %4, %3
%6 = load i32, i32* @S_IRWXU
%7 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
br label %8
8: ; preds = %8, %2
%9 = tail call i32 @sleep(i32 1)
%10 = load i32, i32* @STDOUT_FILENO
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @write(i32 %10, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = tail call i32 @strlen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 @write(i32 %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %8
}