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

/* Variables and functions */
int /*<<< orphan*/ SIGUSR2;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getppid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ pause();
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ wait(int *);
void S2() {
  pid_t pid;
  pid = fork();
  if (pid == (pid_t)-1) {
    fprintf(stdout, "Fork failed\n");
    exit(1);
  }
  if (pid > (pid_t)0) {
    fprintf(stdout, "P21\n");
    pause();
    kill(getppid(), SIGUSR2);
    fprintf(stdout, "P23\n");
    wait((int *)0);
  } else {
    fprintf(stdout, "P22\n");
    exit(0);
  }
  fprintf(stdout, "P24\n");
  return;
}


x86 assembly (clang, -O0):
<S2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0xffffffffffffffff,-0x8(%rbp)
jne    11ad <S2+0x3d>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x8(%rbp)
jle    120e <S2+0x9e>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x0,%al
call   1050 <pause@plt>
mov    $0x0,%al
call   1060 <getppid@plt>
mov    %eax,%edi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
jmp    122a <S2+0xba>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<S2>:
push   %rbx
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffffffffffff,%rax
je     11da <S2+0x6a>
mov    0x2e53(%rip),%rbx
mov    (%rbx),%edi
test   %rax,%rax
jle    11f9 <S2+0x89>
lea    0xe7a(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
call   1050 <pause@plt>
xor    %eax,%eax
call   1060 <getppid@plt>
mov    0x2e33(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1040 <kill@plt>
mov    (%rbx),%edi
lea    0xe53(%rip),%rsi
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1080 <wait@plt>
mov    (%rbx),%edi
lea    0xe48(%rip),%rsi
pop    %rbx
jmp    1030 <fprintf@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe17(%rip),%rsi
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [13 x i8] c"Fork failed\0A\00"
@.str.1 = [5 x i8] c"P21\0A\00"
@SIGUSR2 = global i32 0
@.str.2 = [5 x i8] c"P23\0A\00"
@.str.3 = [5 x i8] c"P22\0A\00"
@.str.4 = [5 x i8] c"P24\0A\00"
define void @S2() {
%1 = alloca i64
%2 = call i64 (...) @fork()
store i64 %2, i64* %1
%3 = load i64, i64* %1
%4 = icmp eq i64 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @stdout
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = load i64, i64* %1
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i32, i32* @stdout
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (...) @pause()
%16 = call i32 (...) @getppid()
%17 = load i32, i32* @SIGUSR2
%18 = call i32 @kill(i32 %16, i32 %17)
%19 = load i32, i32* @stdout
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @wait(i32* null)
br label %26
22: ; preds = %9
%23 = load i32, i32* @stdout
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %12
%27 = load i32, i32* @stdout
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [13 x i8] c"Fork failed\0A\00"
@.str.1 = [5 x i8] c"P21\0A\00"
@SIGUSR2 = global i32 0
@.str.2 = [5 x i8] c"P23\0A\00"
@.str.3 = [5 x i8] c"P22\0A\00"
@.str.4 = [5 x i8] c"P24\0A\00"
define void @S2() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, -1
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = load i32, i32* @stdout
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = icmp sgt i64 %1, 0
%9 = load i32, i32* @stdout
br i1 %8, label %10, label %21
10: ; preds = %7
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 (...) @pause()
%13 = tail call i32 (...) @getppid()
%14 = load i32, i32* @SIGUSR2
%15 = tail call i32 @kill(i32 %13, i32 %14)
%16 = load i32, i32* @stdout
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @wait(i32* null)
%19 = load i32, i32* @stdout
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
ret void
21: ; preds = %7
%22 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call i32 @exit(i32 0)
unreachable
}