#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 /*<<< orphan*/ fclose(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
void waitpager(pid_t pid) {
  fclose(stdout);
  fclose(stderr);
  while (1) {
    pid_t ret = waitpid(pid, NULL, 0);
    if (ret == -1 && errno == EINTR)
      continue;
    break;
  }
}


x86 assembly (clang, -O0):
<waitpager>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1181 <waitpager+0x61>
mov    0x2e6f(%rip),%rax
mov    (%rax),%rax
mov    0x2e5d(%rip),%rcx
cmp    (%rcx),%rax
jne    1181 <waitpager+0x61>
jmp    1147 <waitpager+0x27>
jmp    1186 <waitpager+0x66>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitpager>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
mov    0x2e8e(%rip),%r14
mov    0x2e7f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    1178 <waitpager+0x58>
mov    (%r14),%rax
cmp    (%r15),%rax
je     1160 <waitpager+0x40>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdout = global i32 0
@stderr = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define void @waitpager(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* @stdout
%5 = call i32 @fclose(i32 %4)
%6 = load i32, i32* @stderr
%7 = call i32 @fclose(i32 %6)
br label %8
8: ; preds = %1, %17
%9 = load i32, i32* %2
%10 = call i32 @waitpid(i32 %9, i32* null, i32 0)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %13
br label %8
18: ; preds = %13, %8
br label %19
19: ; preds = %18
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@stderr = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define void @waitpager(i32 %0) {
%2 = load i32, i32* @stdout
%3 = tail call i32 @fclose(i32 %2)
%4 = load i32, i32* @stderr
%5 = tail call i32 @fclose(i32 %4)
br label %6
6: ; preds = %9, %1
%7 = tail call i32 @waitpid(i32 %0, i32* null, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i64, i64* @errno
%11 = load i64, i64* @EINTR
%12 = icmp eq i64 %10, %11
br i1 %12, label %6, label %13
13: ; preds = %6, %9
ret void
}