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

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int waitpid(int, int *, int /*<<< orphan*/);
int lxc_wait_for_pid_status(pid_t pid) {
  int status, ret;
again:
  ret = waitpid(pid, &status, 0);
  if (ret == -1) {
    if (errno == EINTR)
      goto again;
    return -1;
  }
  if (ret != pid)
    goto again;
  return status;
}


x86 assembly (clang, -O0):
<lxc_wait_for_pid_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1030 <waitpid@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1161 <lxc_wait_for_pid_status+0x51>
mov    0x2ea3(%rip),%rax
mov    (%rax),%rax
mov    0x2e91(%rip),%rcx
cmp    (%rcx),%rax
jne    1155 <lxc_wait_for_pid_status+0x45>
jmp    111b <lxc_wait_for_pid_status+0xb>
movl   $0xffffffff,-0x4(%rbp)
jmp    1178 <lxc_wait_for_pid_status+0x68>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     1172 <lxc_wait_for_pid_status+0x62>
jmp    111b <lxc_wait_for_pid_status+0xb>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lxc_wait_for_pid_status>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x4(%rsp),%r14
mov    0x2eba(%rip),%r15
mov    0x2eab(%rip),%r12
jmp    1139 <lxc_wait_for_pid_status+0x29>
nop
mov    (%r15),%rax
cmp    (%r12),%rax
jne    1154 <lxc_wait_for_pid_status+0x44>
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <waitpid@plt>
cmp    $0xffffffff,%eax
je     1130 <lxc_wait_for_pid_status+0x20>
cmp    %ebx,%eax
jne    1139 <lxc_wait_for_pid_status+0x29>
mov    0x4(%rsp),%eax
jmp    1159 <lxc_wait_for_pid_status+0x49>
mov    $0xffffffff,%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 @lxc_wait_for_pid_status(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
br label %6
6: ; preds = %21, %15, %1
%7 = load i32, i32* %3
%8 = call i32 @waitpid(i32 %7, i32* %4, i32 0)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %17
11: ; preds = %6
%12 = load i64, i64* @errno
%13 = load i64, i64* @EINTR
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
br label %6
16: ; preds = %11
store i32 -1, i32* %2
br label %24
17: ; preds = %6
%18 = load i32, i32* %5
%19 = load i32, i32* %3
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17
br label %6
22: ; preds = %17
%23 = load i32, i32* %4
store i32 %23, i32* %2
br label %24
24: ; preds = %22, %16
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @lxc_wait_for_pid_status(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
br label %4
4: ; preds = %11, %1
%5 = call i32 @waitpid(i32 %0, i32* %2, i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = load i64, i64* @errno
%9 = load i64, i64* @EINTR
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %16
11: ; preds = %7, %12
br label %4
12: ; preds = %4
%13 = icmp eq i32 %5, %0
br i1 %13, label %14, label %11
14: ; preds = %12
%15 = load i32, i32* %2
br label %16
16: ; preds = %7, %14
%17 = phi i32 [ %15, %14 ], [ -1, %7 ]
ret i32 %17
}