#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_SUCCESS;
int /*<<< orphan*/ executeChild();
int /*<<< orphan*/ executeParent();
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int shm_unlink(char *);
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  int pid = fork();
  if (pid) {
    if (fork()) {
      executeParent();
      printf("Parent waiting...\n");
      int status = 0;
      wait(&status);
      if (shm_unlink("/semvanz") == -1) {
        perror("sem unlink failed");
        exit(1);
      }
      if (shm_unlink("/vanz") == -1) {
        perror("shm unlink failed");
        exit(1);
      }
      printf("Parent done\n");
    } else {
      executeChild();
    }
  } else {
    executeChild();
  }
  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    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1250 <main+0xd0>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%eax
je     1244 <main+0xc4>
mov    $0x0,%al
call   1050 <executeParent@plt>
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1090 <wait@plt>
lea    0xe2f(%rip),%rdi
call   1080 <shm_unlink@plt>
cmp    $0xffffffff,%eax
jne    1208 <main+0x88>
lea    0xe23(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe1f(%rip),%rdi
call   1080 <shm_unlink@plt>
cmp    $0xffffffff,%eax
jne    1233 <main+0xb3>
lea    0xe10(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe0c(%rip),%rdi
call   1040 <printf@plt>
jmp    124b <main+0xcb>
mov    $0x0,%al
call   1030 <executeChild@plt>
jmp    1257 <main+0xd7>
mov    $0x0,%al
call   1030 <executeChild@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11ec <main+0x6c>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11ec <main+0x6c>
xor    %eax,%eax
call   1050 <executeParent@plt>
lea    0xe8e(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1090 <wait@plt>
lea    0xe3d(%rip),%rdi
call   1080 <shm_unlink@plt>
cmp    $0xffffffff,%eax
je     11fe <main+0x7e>
lea    0xe47(%rip),%rdi
call   1080 <shm_unlink@plt>
cmp    $0xffffffff,%eax
je     1207 <main+0x87>
lea    0xe60(%rip),%rdi
call   1040 <puts@plt>
jmp    11f3 <main+0x73>
xor    %eax,%eax
call   1030 <executeChild@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
lea    0xe04(%rip),%rdi
jmp    120e <main+0x8e>
lea    0xe13(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

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

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