#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 wait_nohang(int *);
int wait_pid_nohang(int pid, int *wstat) {
  int w = 0;
  int r = 0;
  while (r != pid) {
    r = wait_nohang(&w);
    if (!r || (r == (int)-1))
      return r;
  }
  *wstat = w;
  return r;
}


x86 assembly (clang, -O0):
<wait_pid_nohang>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     1169 <wait_pid_nohang+0x59>
lea    -0x14(%rbp),%rdi
call   1030 <wait_nohang@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1159 <wait_pid_nohang+0x49>
cmpl   $0xffffffff,-0x18(%rbp)
jne    1164 <wait_pid_nohang+0x54>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1178 <wait_pid_nohang+0x68>
jmp    112d <wait_pid_nohang+0x1d>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_pid_nohang>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
movl   $0x0,0xc(%rsp)
xor    %eax,%eax
lea    0xc(%rsp),%r15
nopl   (%rax)
cmp    %ebx,%eax
je     1148 <wait_pid_nohang+0x38>
mov    %r15,%rdi
call   1030 <wait_nohang@plt>
mov    %eax,%ecx
add    $0x1,%ecx
cmp    $0x2,%ecx
jae    1130 <wait_pid_nohang+0x20>
jmp    1151 <wait_pid_nohang+0x41>
mov    0xc(%rsp),%eax
mov    %eax,(%r14)
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @wait_pid_nohang(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %21, %2
%9 = load i32, i32* %7
%10 = load i32, i32* %4
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = call i32 @wait_nohang(i32* %6)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %16, %12
%20 = load i32, i32* %7
store i32 %20, i32* %3
br label %26
21: ; preds = %16
br label %8
22: ; preds = %8
%23 = load i32, i32* %6
%24 = load i32*, i32** %5
store i32 %23, i32* %24
%25 = load i32, i32* %7
store i32 %25, i32* %3
br label %26
26: ; preds = %22, %19
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @wait_pid_nohang(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
br label %5
5: ; preds = %8, %2
%6 = phi i32 [ 0, %2 ], [ %9, %8 ]
%7 = icmp eq i32 %6, %0
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = call i32 @wait_nohang(i32* %3)
%10 = add i32 %9, 1
%11 = icmp ult i32 %10, 2
br i1 %11, label %14, label %5
12: ; preds = %5
%13 = load i32, i32* %3
store i32 %13, i32* %1
br label %14
14: ; preds = %8, %12
%15 = phi i32 [ %0, %12 ], [ %9, %8 ]
ret i32 %15
}