#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
scalar_t__ fork();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  if (fork()) {
    int fd = open("stu.dat", O_RDWR);
    write(fd, "killer", 5);
    close(fd);
  } else {
    int fd = open("stu.dat", O_RDWR);
    write(fd, "clinton", 5);
    close(fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
je     1199 <main+0x59>
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
lea    0xe90(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe86(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
jmp    11cd <main+0x8d>
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
lea    0xe57(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    0xe54(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
mov    %rax,%rbx
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
lea    0xea3(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebp
test   %rbx,%rbx
lea    0xea1(%rip),%rax
lea    0xe93(%rip),%rsi
cmove  %rax,%rsi
mov    %ebp,%edi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"stu.dat\00"
@O_RDWR = global i32 0
@.str.1 = [7 x i8] c"killer\00"
@.str.2 = [8 x i8] c"clinton\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 (...) @fork()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %0
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = call i32 @write(i32 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 5)
%11 = load i32, i32* %2
%12 = call i32 @close(i32 %11)
br label %20
13: ; preds = %0
%14 = load i32, i32* @O_RDWR
%15 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = call i32 @write(i32 %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 5)
%18 = load i32, i32* %3
%19 = call i32 @close(i32 %18)
br label %20
20: ; preds = %13, %6
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"stu.dat\00"
@O_RDWR = global i32 0
@.str.1 = [7 x i8] c"killer\00"
@.str.2 = [8 x i8] c"clinton\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = select i1 %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0)
%6 = tail call i32 @write(i32 %4, i8* %5, i32 5)
%7 = tail call i32 @close(i32 %4)
ret i32 0
}