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

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *);
int wait(int *);
void p32() {
  pid_t pid;
  if ((pid = fork()) == -1)
    printf("can't fork");
  if (pid > 0) {
    printf("p2\n");
    while (wait((int *)0) != pid)
      ;
  } else {
    printf("p3\n");
    exit(0);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<p32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    1167 <p32+0x27>
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0x4(%rbp)
jle    1199 <p32+0x59>
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <wait@plt>
cmp    -0x4(%rbp),%eax
je     1194 <p32+0x54>
jmp    117d <p32+0x3d>
jmp    11ac <p32+0x6c>
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <exit@plt>
xor    %edi,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<p32>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
cmp    $0xffffffff,%eax
jne    116b <p32+0x1b>
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
jmp    1192 <p32+0x42>
mov    %eax,%ebx
test   %eax,%eax
jle    1192 <p32+0x42>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
nopl   (%rax)
xor    %edi,%edi
call   1060 <wait@plt>
cmp    %ebx,%eax
jne    1180 <p32+0x30>
xor    %edi,%edi
call   1050 <exit@plt>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"can't fork\00"
@.str.1 = [4 x i8] c"p2\0A\00"
@.str.2 = [4 x i8] c"p3\0A\00"
define void @p32() {
%1 = alloca i32
%2 = call i32 (...) @fork()
store i32 %2, i32* %1
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %15, %9
%12 = call i32 @wait(i32* null)
%13 = load i32, i32* %1
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
br label %11
16: ; preds = %11
br label %20
17: ; preds = %6
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %16
%21 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"can't fork\00"
@str = [3 x i8] c"p3\00"
@str.3 = [3 x i8] c"p2\00"
define void @p32() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %12
5: ; preds = %0
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %12
7: ; preds = %5
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.3, i64 0, i64 0))
br label %9
9: ; preds = %9, %7
%10 = tail call i32 @wait(i32* null)
%11 = icmp eq i32 %10, %1
br i1 %11, label %15, label %9
12: ; preds = %3, %5
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %9
%16 = tail call i32 @exit(i32 0)
unreachable
}