#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*/ close(int);
int creat(char *, int);
int fork();
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd;
  int pid;
  char msg1[] = "Test 1 2 3\n";
  char msg2[] = "Hello world\n";
  if ((fd = creat("testfile", 0644)) == -1) {
    return 0;
  }
  if (write(fd, msg1, strlen(msg1)) == -1) {
    return 0;
  }
  if ((pid = fork()) == -1) {
    return 0;
  }
  if (write(fd, msg2, strlen(msg2)) == -1) {
    return 0;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe93(%rip),%rax
mov    %rax,-0x24(%rbp)
mov    0xe91(%rip),%eax
mov    %eax,-0x1c(%rbp)
mov    0xe8b(%rip),%rax
mov    %rax,-0x31(%rbp)
mov    0xe89(%rip),%eax
mov    %eax,-0x29(%rbp)
mov    0xe84(%rip),%al
mov    %al,-0x25(%rbp)
lea    0xe7b(%rip),%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11c0 <main+0x70>
movl   $0x0,-0x4(%rbp)
jmp    1262 <main+0x112>
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
lea    -0x24(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x24(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11fa <main+0xaa>
movl   $0x0,-0x4(%rbp)
jmp    1262 <main+0x112>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1219 <main+0xc9>
movl   $0x0,-0x4(%rbp)
jmp    1262 <main+0x112>
mov    -0x14(%rbp),%eax
mov    %eax,-0x54(%rbp)
lea    -0x31(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x31(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1253 <main+0x103>
movl   $0x0,-0x4(%rbp)
jmp    1262 <main+0x112>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movabs $0x3220312074736554,%rax
31 20 32
mov    %rax,0x8(%rsp)
movl   $0xa3320,0x10(%rsp)
movabs $0xa646c726f7720,%rax
mov    %rax,0x1d(%rsp)
movabs $0x6f77206f6c6c6548,%rax
20 77 6f
mov    %rax,0x18(%rsp)
lea    0xe86(%rip),%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
cmp    $0xffffffff,%eax
je     11f3 <main+0xa3>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     11f3 <main+0xa3>
xor    %eax,%eax
call   1070 <fork@plt>
cmp    $0xffffffff,%eax
je     11f3 <main+0xa3>
lea    0x18(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     11f3 <main+0xa3>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.msg1 = [12 x i8] c"Test 1 2 3\0A\00"
@__const.main.msg2 = [13 x i8] c"Hello world\0A\00"
@.str = [9 x i8] c"testfile\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [12 x i8]
%9 = alloca [13 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [12 x i8]* %8 to i8*
%11 = bitcast [13 x i8]* %9 to i8*
%12 = call i32 @creat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 420)
store i32 %12, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 0, i32* %3
br label %38
15: ; preds = %2
%16 = load i32, i32* %6
%17 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 0
%18 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @write(i32 %16, i8* %17, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 0, i32* %3
br label %38
23: ; preds = %15
%24 = call i32 (...) @fork()
store i32 %24, i32* %7
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 0, i32* %3
br label %38
27: ; preds = %23
%28 = load i32, i32* %6
%29 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 0
%30 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
%32 = call i32 @write(i32 %28, i8* %29, i32 %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %35
34: ; preds = %27
store i32 0, i32* %3
br label %38
35: ; preds = %27
%36 = load i32, i32* %6
%37 = call i32 @close(i32 %36)
store i32 0, i32* %3
br label %38
38: ; preds = %35, %34, %26, %22, %14
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@__const.main.msg1 = [12 x i8] c"Test 1 2 3\0A\00"
@__const.main.msg2 = [13 x i8] c"Hello world\0A\00"
@.str = [9 x i8] c"testfile\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [12 x i8]
%4 = alloca [13 x i8]
%5 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [13 x i8], [13 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @creat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 420)
%8 = icmp eq i32 %7, -1
br i1 %8, label %22, label %9
9: ; preds = %2
%10 = call i32 @strlen(i8* %5)
%11 = call i32 @write(i32 %7, i8* %5, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %22, label %13
13: ; preds = %9
%14 = call i32 (...) @fork()
%15 = icmp eq i32 %14, -1
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = call i32 @strlen(i8* %6)
%18 = call i32 @write(i32 %7, i8* %6, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = call i32 @close(i32 %7)
br label %22
22: ; preds = %16, %13, %9, %2, %20
ret i32 0
}