#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 scalar_t__ pid_t;

/* Variables and functions */
int EXIT_SUCCESS;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
scalar_t__ fork();
int open(char *, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int i = 0;
  int fd = open("temp.txt", O_WRONLY | O_CREAT | O_TRUNC);
  pid_t pid = fork();
  if (fork()) {
    for (i = 0; i < 10000; i++)
      write(fd, "F", 1);
    close(fd);
  }
  if (fork()) {
    for (i = 0; i < 10000; i++)
      write(fd, "P", 1);
    close(fd);
  }
  wait(0);
  wait(0);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    0x2e7b(%rip),%rax
or     (%rax),%esi
mov    0x2e6a(%rip),%rax
or     (%rax),%esi
lea    0xe71(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     11f1 <main+0xa1>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2710,-0x14(%rbp)
jge    11e9 <main+0x99>
mov    -0x18(%rbp),%edi
lea    0xe38(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ba <main+0x6a>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     1240 <main+0xf0>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2710,-0x14(%rbp)
jge    1238 <main+0xe8>
mov    -0x18(%rbp),%edi
lea    0xdeb(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1209 <main+0xb9>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %edi,%edi
call   1060 <wait@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e65(%rip),%rax
mov    0x2e96(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e83(%rip),%rax
or     (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <fork@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     11bb <main+0x6b>
mov    $0x2710,%ebp
lea    0xe6d(%rip),%r14
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebp
jne    11a0 <main+0x50>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     11fb <main+0xab>
mov    $0x2710,%ebp
lea    0xe38(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebp
jne    11e0 <main+0x90>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %edi,%edi
call   1060 <wait@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"temp.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [2 x i8] c"F\00"
@.str.2 = [2 x i8] c"P\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = load i32, i32* @O_WRONLY
%10 = load i32, i32* @O_CREAT
%11 = or i32 %9, %10
%12 = load i32, i32* @O_TRUNC
%13 = or i32 %11, %12
%14 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %7
%15 = call i64 (...) @fork()
store i64 %15, i64* %8
%16 = call i64 (...) @fork()
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %2
store i32 0, i32* %6
br label %19
19: ; preds = %25, %18
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 10000
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i32, i32* %7
%24 = call i32 @write(i32 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %25
25: ; preds = %22
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %19
28: ; preds = %19
%29 = load i32, i32* %7
%30 = call i32 @close(i32 %29)
br label %31
31: ; preds = %28, %2
%32 = call i64 (...) @fork()
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %47
34: ; preds = %31
store i32 0, i32* %6
br label %35
35: ; preds = %41, %34
%36 = load i32, i32* %6
%37 = icmp slt i32 %36, 10000
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = load i32, i32* %7
%40 = call i32 @write(i32 %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %41
41: ; preds = %38
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %35
44: ; preds = %35
%45 = load i32, i32* %7
%46 = call i32 @close(i32 %45)
br label %47
47: ; preds = %44, %31
%48 = call i32 @wait(i32 0)
%49 = call i32 @wait(i32 0)
%50 = load i32, i32* @EXIT_SUCCESS
ret i32 %50
}

LLVM IR (-O2):
@.str = [9 x i8] c"temp.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [2 x i8] c"F\00"
@.str.2 = [2 x i8] c"P\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %5, %6
%8 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i64 (...) @fork()
%10 = tail call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %2, %12
%13 = phi i32 [ %15, %12 ], [ 0, %2 ]
%14 = tail call i32 @write(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%15 = add nuw nsw i32 %13, 1
%16 = icmp eq i32 %15, 10000
br i1 %16, label %17, label %12
17: ; preds = %12
%18 = tail call i32 @close(i32 %8)
br label %19
19: ; preds = %17, %2
%20 = tail call i64 (...) @fork()
%21 = icmp eq i64 %20, 0
br i1 %21, label %29, label %22
22: ; preds = %19, %22
%23 = phi i32 [ %25, %22 ], [ 0, %19 ]
%24 = tail call i32 @write(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%25 = add nuw nsw i32 %23, 1
%26 = icmp eq i32 %25, 10000
br i1 %26, label %27, label %22
27: ; preds = %22
%28 = tail call i32 @close(i32 %8)
br label %29
29: ; preds = %27, %19
%30 = tail call i32 @wait(i32 0)
%31 = tail call i32 @wait(i32 0)
%32 = load i32, i32* @EXIT_SUCCESS
ret i32 %32
}