#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 */
scalar_t__ EINTR;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
scalar_t__ errno;
scalar_t__ waitpid(int, int *, int /*<<< orphan*/);
int reexec_in_user_namespace_wait(int pid) {
  pid_t p;
  int status;
  do
    p = waitpid(pid, &status, 0);
  while (p < 0 && errno == EINTR);
  if (p < 0)
    return -1;
  if (WIFEXITED(status))
    return WEXITSTATUS(status);
  if (WIFSIGNALED(status))
    return 128 + WTERMSIG(status);
  return -1;
}


x86 assembly (clang, -O0):
<reexec_in_user_namespace_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x15(%rbp)
jge    1197 <reexec_in_user_namespace_wait+0x47>
mov    0x2e5c(%rip),%rax
mov    (%rax),%rax
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    115b <reexec_in_user_namespace_wait+0xb>
cmpq   $0x0,-0x10(%rbp)
jge    11b9 <reexec_in_user_namespace_wait+0x69>
movl   $0xffffffff,-0x4(%rbp)
jmp    1209 <reexec_in_user_namespace_wait+0xb9>
mov    -0x14(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11db <reexec_in_user_namespace_wait+0x8b>
mov    -0x14(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    1209 <reexec_in_user_namespace_wait+0xb9>
mov    -0x14(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1202 <reexec_in_user_namespace_wait+0xb2>
mov    -0x14(%rbp),%edi
call   1040 <WTERMSIG@plt>
add    $0x80,%eax
mov    %eax,-0x4(%rbp)
jmp    1209 <reexec_in_user_namespace_wait+0xb9>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reexec_in_user_namespace_wait>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x4(%rsp),%r14
mov    0x2e7a(%rip),%r15
mov    0x2e6b(%rip),%r12
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
test   %rax,%rax
jns    118a <reexec_in_user_namespace_wait+0x3a>
mov    (%r12),%rcx
cmp    %rcx,(%r15)
je     1170 <reexec_in_user_namespace_wait+0x20>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     11c7 <reexec_in_user_namespace_wait+0x77>
mov    0x4(%rsp),%edi
call   1070 <WIFEXITED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
je     11af <reexec_in_user_namespace_wait+0x5f>
call   1050 <WEXITSTATUS@plt>
mov    %eax,%ebx
jmp    11c7 <reexec_in_user_namespace_wait+0x77>
call   1030 <WIFSIGNALED@plt>
test   %rax,%rax
je     11c7 <reexec_in_user_namespace_wait+0x77>
mov    0x4(%rsp),%edi
call   1040 <WTERMSIG@plt>
mov    %eax,%ebx
sub    $0xffffff80,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define i32 @reexec_in_user_namespace_wait(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
store i32 %0, i32* %3
br label %6
6: ; preds = %16, %1
%7 = load i32, i32* %3
%8 = call i64 @waitpid(i32 %7, i32* %5, i32 0)
store i64 %8, i64* %4
br label %9
9: ; preds = %6
%10 = load i64, i64* %4
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i64, i64* @errno
%14 = load i64, i64* @EINTR
%15 = icmp eq i64 %13, %14
br label %16
16: ; preds = %12, %9
%17 = phi i1 [ false, %9 ], [ %15, %12 ]
br i1 %17, label %6, label %18
18: ; preds = %16
%19 = load i64, i64* %4
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 -1, i32* %2
br label %38
22: ; preds = %18
%23 = load i32, i32* %5
%24 = call i64 @WIFEXITED(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* %5
%28 = call i32 @WEXITSTATUS(i32 %27)
store i32 %28, i32* %2
br label %38
29: ; preds = %22
%30 = load i32, i32* %5
%31 = call i64 @WIFSIGNALED(i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* %5
%35 = call i32 @WTERMSIG(i32 %34)
%36 = add nsw i32 128, %35
store i32 %36, i32* %2
br label %38
37: ; preds = %29
store i32 -1, i32* %2
br label %38
38: ; preds = %37, %33, %26, %21
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @reexec_in_user_namespace_wait(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
br label %4
4: ; preds = %4, %1
%5 = call i64 @waitpid(i32 %0, i32* %2, i32 0)
%6 = icmp slt i64 %5, 0
%7 = load i64, i64* @errno
%8 = load i64, i64* @EINTR
%9 = icmp eq i64 %7, %8
%10 = select i1 %6, i1 %9, i1 false
br i1 %10, label %4, label %11
11: ; preds = %4
br i1 %6, label %26, label %12
12: ; preds = %11
%13 = load i32, i32* %2
%14 = call i64 @WIFEXITED(i32 %13)
%15 = icmp eq i64 %14, 0
%16 = load i32, i32* %2
br i1 %15, label %19, label %17
17: ; preds = %12
%18 = call i32 @WEXITSTATUS(i32 %16)
br label %26
19: ; preds = %12
%20 = call i64 @WIFSIGNALED(i32 %16)
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = load i32, i32* %2
%24 = call i32 @WTERMSIG(i32 %23)
%25 = add nsw i32 %24, 128
br label %26
26: ; preds = %19, %11, %22, %17
%27 = phi i32 [ %18, %17 ], [ %25, %22 ], [ -1, %11 ], [ -1, %19 ]
ret i32 %27
}