#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ close(int);
int creat(char *, int /*<<< orphan*/);
int /*<<< orphan*/ executeChild();
int /*<<< orphan*/ executeParent();
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  int fd = creat("myshm", S_IRWXU);
  if (fd == -1) {
    perror("File creation failed");
    exit(1);
  }
  int pid = fork();
  if (pid < 0) {
    perror("Fork failed\n");
    return EXIT_FAILURE;
  }
  if (pid) {
    executeParent();
    printf("Parent waiting...\n");
    int status = 0;
    wait(&status);
    printf("Parent done\n");
  } else {
    executeChild();
  }
  close(fd);
  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)
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0xe4a(%rip),%rdi
call   1080 <creat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11de <main+0x4e>
lea    0xe37(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    120f <main+0x7f>
lea    0xe22(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1268 <main+0xd8>
cmpl   $0x0,-0x18(%rbp)
je     124d <main+0xbd>
mov    $0x0,%al
call   1060 <executeParent@plt>
lea    0xe01(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
call   10a0 <wait@plt>
lea    0xdf8(%rip),%rdi
call   1040 <printf@plt>
jmp    1254 <main+0xc4>
mov    $0x0,%al
call   1030 <executeChild@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
lea    0xe5b(%rip),%rdi
call   1080 <creat@plt>
cmp    $0xffffffff,%eax
je     1223 <main+0x93>
mov    %eax,%ebx
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
js     120e <main+0x7e>
je     11f1 <main+0x61>
xor    %eax,%eax
call   1060 <executeParent@plt>
lea    0xe5c(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   10a0 <wait@plt>
lea    0xe50(%rip),%rdi
call   1040 <puts@plt>
jmp    11f8 <main+0x68>
xor    %eax,%eax
call   1030 <executeChild@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe06(%rip),%rdi
call   1070 <perror@plt>
mov    0x2db7(%rip),%rax
jmp    1206 <main+0x76>
lea    0xddc(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"myshm\00"
@S_IRWXU = global i32 0
@.str.1 = [21 x i8] c"File creation failed\00"
@.str.2 = [13 x i8] c"Fork failed\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [19 x i8] c"Parent waiting...\0A\00"
@.str.4 = [13 x i8] c"Parent done\0A\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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @S_IRWXU
%10 = call i32 @creat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = call i32 (...) @fork()
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
store i32 %22, i32* %3
br label %37
23: ; preds = %16
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = call i32 (...) @executeParent()
%28 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %8
%29 = call i32 @wait(i32* %8)
%30 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %33
31: ; preds = %23
%32 = call i32 (...) @executeChild()
br label %33
33: ; preds = %31, %26
%34 = load i32, i32* %6
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* @EXIT_SUCCESS
store i32 %36, i32* %3
br label %37
37: ; preds = %33, %20
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [6 x i8] c"myshm\00"
@S_IRWXU = global i32 0
@.str.1 = [21 x i8] c"File creation failed\00"
@.str.2 = [13 x i8] c"Fork failed\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [18 x i8] c"Parent waiting...\00"
@str.5 = [12 x i8] c"Parent done\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = load i32, i32* @S_IRWXU
%5 = tail call i32 @creat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = tail call i32 (...) @fork()
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %27
15: ; preds = %10
%16 = icmp eq i32 %11, 0
br i1 %16, label %23, label %17
17: ; preds = %15
%18 = tail call i32 (...) @executeParent()
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%20 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%21 = call i32 @wait(i32* %3)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.5, i64 0, i64 0))
br label %25
23: ; preds = %15
%24 = tail call i32 (...) @executeChild()
br label %25
25: ; preds = %23, %17
%26 = call i32 @close(i32 %5)
br label %27
27: ; preds = %25, %13
%28 = phi i32* [ @EXIT_FAILURE, %13 ], [ @EXIT_SUCCESS, %25 ]
%29 = load i32, i32* %28
ret i32 %29
}