#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__ ECHILD;
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  for (;;) {
    if (wait(NULL) == -1) {
      if (errno == ECHILD)
        return 0;
      if (errno == EINTR)
        continue;
      fprintf(stderr, "%s: wait: %s\n", *argv, strerror(errno));
      return 2;
    }
  }
  (void)argc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <wait@plt>
cmp    $0xffffffff,%eax
jne    11e5 <main+0xb5>
mov    0x2e79(%rip),%rax
mov    (%rax),%rax
mov    0x2e5f(%rip),%rcx
cmp    (%rcx),%rax
jne    117e <main+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    11ea <main+0xba>
mov    0x2e53(%rip),%rax
mov    (%rax),%rax
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%rax
jne    119d <main+0x6d>
jmp    1146 <main+0x16>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%rdi
call   1040 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xe2c(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11ea <main+0xba>
jmp    1146 <main+0x16>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e97(%rip),%r15
mov    0x2e80(%rip),%rbx
mov    0x2e81(%rip),%rbp
nop
xor    %edi,%edi
call   1050 <wait@plt>
cmp    $0xffffffff,%eax
jne    1150 <main+0x20>
mov    (%r15),%rdi
cmp    (%rbx),%rdi
je     1196 <main+0x66>
cmp    0x0(%rbp),%rdi
je     1150 <main+0x20>
mov    0x2e6f(%rip),%rax
mov    (%rax),%ebp
mov    (%r14),%rbx
call   1040 <strerror@plt>
lea    0xe7e(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    $0x2,%eax
jmp    1198 <main+0x68>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@ECHILD = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str = [14 x i8] c"%s: wait: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %6
6: ; preds = %26, %18, %2
%7 = call i32 @wait(i32* null)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %26
9: ; preds = %6
%10 = load i64, i64* @errno
%11 = load i64, i64* @ECHILD
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 0, i32* %3
br label %27
14: ; preds = %9
%15 = load i64, i64* @errno
%16 = load i64, i64* @EINTR
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14
br label %6
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = load i8*, i8** %21
%23 = load i64, i64* @errno
%24 = call i8* @strerror(i64 %23)
%25 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %24)
store i32 2, i32* %3
br label %27
26: ; preds = %6
br label %6
27: ; preds = %19, %13
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@errno = global i64 0
@ECHILD = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str = [14 x i8] c"%s: wait: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
br label %3
3: ; preds = %13, %2
%4 = tail call i32 @wait(i32* null)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = load i64, i64* @errno
%8 = load i64, i64* @ECHILD
%9 = icmp eq i64 %7, %8
br i1 %9, label %19, label %10
10: ; preds = %6
%11 = load i64, i64* @EINTR
%12 = icmp eq i64 %7, %11
br i1 %12, label %13, label %14
13: ; preds = %10, %3
br label %3
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i8* @strerror(i64 %7)
%18 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %17)
br label %19
19: ; preds = %6, %14
%20 = phi i32 [ 2, %14 ], [ 0, %6 ]
ret i32 %20
}