#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 */
scalar_t__ EINTR;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ errno;
int waitpid(int, int *, int /*<<< orphan*/);
int do_waitpid(int pid) {
  int ret, status;
  do {
    ret = waitpid(pid, &status, 0);
  } while ((ret == -1) && (errno == EINTR));
  ;
  if (ret < 0) {
    return 0x7ffffffd;
  }
  if (WIFEXITED(status)) {
    return WEXITSTATUS(status);
  } else if (WIFSIGNALED(status)) {
    return 0x7ffffffe;
  }
  return 0x7ffffffd;
}


x86 assembly (clang, -O0):
<do_waitpid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0xc(%rbp)
mov    %al,-0x11(%rbp)
jne    1185 <do_waitpid+0x45>
mov    0x2e6e(%rip),%rax
mov    (%rax),%rax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    114b <do_waitpid+0xb>
cmpl   $0x0,-0xc(%rbp)
jge    11a6 <do_waitpid+0x66>
movl   $0x7ffffffd,-0x4(%rbp)
jmp    11f2 <do_waitpid+0xb2>
mov    -0x10(%rbp),%edi
call   1060 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11c8 <do_waitpid+0x88>
mov    -0x10(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    11f2 <do_waitpid+0xb2>
mov    -0x10(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     11e6 <do_waitpid+0xa6>
movl   $0x7ffffffe,-0x4(%rbp)
jmp    11f2 <do_waitpid+0xb2>
jmp    11eb <do_waitpid+0xab>
movl   $0x7ffffffd,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_waitpid>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x4(%rsp),%r14
mov    0x2e8a(%rip),%r15
mov    0x2e7b(%rip),%r12
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    117a <do_waitpid+0x3a>
mov    (%r12),%rcx
cmp    %rcx,(%r15)
je     1160 <do_waitpid+0x20>
test   %eax,%eax
js     1197 <do_waitpid+0x57>
mov    0x4(%rsp),%edi
call   1060 <WIFEXITED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
je     119e <do_waitpid+0x5e>
call   1040 <WEXITSTATUS@plt>
jmp    11af <do_waitpid+0x6f>
mov    $0x7ffffffd,%eax
jmp    11af <do_waitpid+0x6f>
call   1030 <WIFSIGNALED@plt>
cmp    $0x1,%rax
mov    $0x7ffffffe,%eax
sbb    $0x0,%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 @do_waitpid(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
br label %6
6: ; preds = %16, %1
%7 = load i32, i32* %3
%8 = call i32 @waitpid(i32 %7, i32* %5, i32 0)
store i32 %8, i32* %4
br label %9
9: ; preds = %6
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, -1
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 i32, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 2147483645, i32* %2
br label %36
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 %36
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 %34
33: ; preds = %29
store i32 2147483646, i32* %2
br label %36
34: ; preds = %29
br label %35
35: ; preds = %34
store i32 2147483645, i32* %2
br label %36
36: ; preds = %35, %33, %26, %21
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @do_waitpid(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
br label %4
4: ; preds = %4, %1
%5 = call i32 @waitpid(i32 %0, i32* %2, i32 0)
%6 = icmp eq i32 %5, -1
%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
%12 = icmp slt i32 %5, 0
br i1 %12, label %24, label %13
13: ; preds = %11
%14 = load i32, i32* %2
%15 = call i64 @WIFEXITED(i32 %14)
%16 = icmp eq i64 %15, 0
%17 = load i32, i32* %2
br i1 %16, label %20, label %18
18: ; preds = %13
%19 = call i32 @WEXITSTATUS(i32 %17)
br label %24
20: ; preds = %13
%21 = call i64 @WIFSIGNALED(i32 %17)
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, i32 2147483645, i32 2147483646
br label %24
24: ; preds = %20, %11, %18
%25 = phi i32 [ %19, %18 ], [ 2147483645, %11 ], [ %23, %20 ]
ret i32 %25
}