#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 */
struct rusage {
  int dummy;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int Read(int /*<<< orphan*/ *, int, struct rusage *);
scalar_t__ SIGKILL;
int /*<<< orphan*/ WIFSIGNALED(int);
scalar_t__ WTERMSIG(int);
scalar_t__ wait4(int /*<<< orphan*/, int *, int /*<<< orphan*/,
                 struct rusage *);
int Wait(pid_t *pif, int *si, int i) {
  struct rusage ru;
  if (wait4(*pif, si, 0, &ru) == 0)
    return 0;
  if (!WIFSIGNALED(*si) || WTERMSIG(*si) != SIGKILL)
    return Read(pif, i, &ru);
  return 0;
}


x86 assembly (clang, -O0):
<Wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
lea    -0x20(%rbp),%rcx
call   1060 <wait4@plt>
cmp    $0x0,%rax
jne    117e <Wait+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11cc <Wait+0x8c>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%eax
je     11ad <Wait+0x6d>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <WTERMSIG@plt>
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%rax
je     11c5 <Wait+0x85>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1030 <Read@plt>
mov    %eax,-0x4(%rbp)
jmp    11cc <Wait+0x8c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Wait>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    (%rdi),%edi
xor    %r15d,%r15d
mov    %rsp,%rcx
xor    %edx,%edx
call   1060 <wait4@plt>
test   %rax,%rax
je     1195 <Wait+0x55>
mov    0x0(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
test   %eax,%eax
je     1184 <Wait+0x44>
mov    0x0(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%rax
je     1195 <Wait+0x55>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <Read@plt>
mov    %eax,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.rusage = type { i32 }
@SIGKILL = global i64 0
define i32 @Wait(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca %struct.rusage
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
%11 = load i32*, i32** %6
%12 = call i64 @wait4(i32 %10, i32* %11, i32 0, %struct.rusage* %8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %4
br label %31
15: ; preds = %3
%16 = load i32*, i32** %6
%17 = load i32, i32* %16
%18 = call i32 @WIFSIGNALED(i32 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = load i32*, i32** %6
%22 = load i32, i32* %21
%23 = call i64 @WTERMSIG(i32 %22)
%24 = load i64, i64* @SIGKILL
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %30
26: ; preds = %20, %15
%27 = load i32*, i32** %5
%28 = load i32, i32* %7
%29 = call i32 @Read(i32* %27, i32 %28, %struct.rusage* %8)
store i32 %29, i32* %4
br label %31
30: ; preds = %20
store i32 0, i32* %4
br label %31
31: ; preds = %30, %26, %14
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
%struct.rusage = type { i32 }
@SIGKILL = global i64 0
define i32 @Wait(i32* %0, i32* %1, i32 %2) {
%4 = alloca %struct.rusage
%5 = bitcast %struct.rusage* %4 to i8*
%6 = load i32, i32* %0
%7 = call i64 @wait4(i32 %6, i32* %1, i32 0, %struct.rusage* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %20, label %9
9: ; preds = %3
%10 = load i32, i32* %1
%11 = call i32 @WIFSIGNALED(i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = load i32, i32* %1
%15 = call i64 @WTERMSIG(i32 %14)
%16 = load i64, i64* @SIGKILL
%17 = icmp eq i64 %15, %16
br i1 %17, label %20, label %18
18: ; preds = %13, %9
%19 = call i32 @Read(i32* %0, i32 %2, %struct.rusage* %4)
br label %20
20: ; preds = %13, %3, %18
%21 = phi i32 [ %19, %18 ], [ 0, %3 ], [ 0, %13 ]
ret i32 %21
}