#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 MAP_ANONYMOUS;
int MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ fork();
void *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ wait(int *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main() {
  void *mem = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
                   MAP_SHARED | MAP_ANONYMOUS, -1, 0);
  if (!fork()) {
    char *baz = mem;
    strcpy(baz, "Hello world!\n");
    write(1, baz, strlen(baz));
  } else {
    int status;
    wait(&status);
    char *quux = mem;
    write(1, quux, strlen(quux));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
mov    0x2e49(%rip),%rax
or     (%rax),%edx
mov    0x2e60(%rip),%rax
mov    (%rax),%ecx
mov    0x2e47(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%eax
jne    11fc <main+0x9c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1040 <write@plt>
jmp    122e <main+0xce>
lea    -0x1c(%rbp),%rdi
call   1070 <wait@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1040 <write@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    0x2e55(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e6a(%rip),%rax
mov    0x2e53(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11b8 <main+0x58>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
jmp    11c7 <main+0x67>
lea    0xe41(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str = [14 x i8] c"Hello world!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = load i32, i32* @PROT_READ
%7 = load i32, i32* @PROT_WRITE
%8 = or i32 %6, %7
%9 = load i32, i32* @MAP_SHARED
%10 = load i32, i32* @MAP_ANONYMOUS
%11 = or i32 %9, %10
%12 = call i8* @mmap(i32* null, i32 4096, i32 %8, i32 %11, i32 -1, i32 0)
store i8* %12, i8** %2
%13 = call i32 (...) @fork()
%14 = icmp ne i32 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %0
%16 = load i8*, i8** %2
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %3
%20 = load i8*, i8** %3
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @write(i32 1, i8* %19, i32 %21)
br label %30
23: ; preds = %0
%24 = call i32 @wait(i32* %4)
%25 = load i8*, i8** %2
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @write(i32 1, i8* %26, i32 %28)
br label %30
30: ; preds = %23, %15
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str = [14 x i8] c"Hello world!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = load i32, i32* @PROT_READ
%3 = load i32, i32* @PROT_WRITE
%4 = or i32 %3, %2
%5 = load i32, i32* @MAP_SHARED
%6 = load i32, i32* @MAP_ANONYMOUS
%7 = or i32 %6, %5
%8 = tail call i8* @mmap(i32* null, i32 4096, i32 %4, i32 %7, i32 -1, i32 0)
%9 = tail call i32 (...) @fork()
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = tail call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @strlen(i8* %8)
%14 = tail call i32 @write(i32 1, i8* %8, i32 %13)
br label %20
15: ; preds = %0
%16 = bitcast i32* %1 to i8*
%17 = call i32 @wait(i32* %1)
%18 = call i32 @strlen(i8* %8)
%19 = call i32 @write(i32 1, i8* %8, i32 %18)
br label %20
20: ; preds = %15, %11
ret i32 0
}