#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 /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ configure_signals(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ reap();
scalar_t__ sigwait(int /*<<< orphan*/ *, int *);
char *strerror(int /*<<< orphan*/);
int main(void) {
  sigset_t set;
  int sig;
  if (!configure_signals(&set))
    return 1;
  while (true) {
    if (sigwait(&set, &sig) != 0) {
      printf("failed to wait for signals: %s\n", strerror(errno));
      return 1;
    }
    if (!reap())
      return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1040 <configure_signals@plt>
cmp    $0x0,%eax
jne    117d <main+0x2d>
movl   $0x1,-0x4(%rbp)
jmp    11e3 <main+0x93>
jmp    1182 <main+0x32>
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <sigwait@plt>
cmp    $0x0,%rax
je     11c2 <main+0x72>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e3 <main+0x93>
mov    $0x0,%al
call   1050 <reap@plt>
cmp    $0x0,%eax
jne    11de <main+0x8e>
movl   $0x1,-0x4(%rbp)
jmp    11e3 <main+0x93>
jmp    1182 <main+0x32>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rdi
call   1040 <configure_signals@plt>
test   %eax,%eax
je     11aa <main+0x5a>
mov    %rsp,%r14
lea    0x4(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <sigwait@plt>
test   %rax,%rax
jne    118d <main+0x3d>
xor    %eax,%eax
call   1050 <reap@plt>
test   %eax,%eax
jne    1170 <main+0x20>
jmp    11aa <main+0x5a>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe5e(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [32 x i8] c"failed to wait for signals: %s\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @configure_signals(i32* %2)
%5 = icmp ne i32 %4, 0
br i1 %5, label %7, label %6
6: ; preds = %0
store i32 1, i32* %1
br label %20
7: ; preds = %0
br label %8
8: ; preds = %7, %19
%9 = call i64 @sigwait(i32* %2, i32* %3)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 1, i32* %1
br label %20
15: ; preds = %8
%16 = call i32 (...) @reap()
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %15
store i32 1, i32* %1
br label %20
19: ; preds = %15
br label %8
20: ; preds = %18, %11, %6
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [32 x i8] c"failed to wait for signals: %s\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @configure_signals(i32* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %0, %14
%8 = call i64 @sigwait(i32* %1, i32* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %17
14: ; preds = %7
%15 = call i32 (...) @reap()
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %7
17: ; preds = %14, %0, %10
ret i32 1
}