#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__ ECHILD;
scalar_t__ EINTR;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int wait(int *);
void wait_for_jobs() {
  fprintf(stderr, "Waiting for running jobs to finish\n");
  while (1) {
    int stat;
    pid_t pid;
    pid = wait(&stat);
    if (pid == -1) {
      if (errno == ECHILD) {
        break;
      }
      assert(errno == EINTR);
    }
  }
}


x86 assembly (clang, -O0):
<wait_for_jobs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
lea    0xeb8(%rip),%rsi
call   1040 <fprintf@plt>
lea    -0x4(%rbp),%rdi
call   1050 <wait@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11a3 <wait_for_jobs+0x73>
mov    0x2e6e(%rip),%rax
mov    (%rax),%rax
mov    0x2e54(%rip),%rcx
cmp    (%rcx),%rax
jne    1182 <wait_for_jobs+0x52>
jmp    11a8 <wait_for_jobs+0x78>
mov    0x2e4f(%rip),%rax
mov    (%rax),%rax
mov    0x2e3d(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
jmp    114d <wait_for_jobs+0x1d>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_for_jobs>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
lea    0xeb8(%rip),%rsi
call   1040 <fprintf@plt>
lea    0x4(%rsp),%rbx
mov    0x2e7f(%rip),%r14
mov    0x2e68(%rip),%r15
mov    0x2e69(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <wait@plt>
cmp    $0xffffffff,%eax
jne    1170 <wait_for_jobs+0x40>
mov    (%r14),%rax
cmp    (%r15),%rax
je     1196 <wait_for_jobs+0x66>
xor    %edi,%edi
cmp    (%r12),%rax
sete   %dil
call   1030 <assert@plt>
jmp    1170 <wait_for_jobs+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Waiting for running jobs to finish\0A\00"
@errno = global i64 0
@ECHILD = global i64 0
@EINTR = global i64 0
define void @wait_for_jobs() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @stderr
%4 = call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %0, %20
%6 = call i32 @wait(i32* %1)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %20
9: ; preds = %5
%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
br label %21
14: ; preds = %9
%15 = load i64, i64* @errno
%16 = load i64, i64* @EINTR
%17 = icmp eq i64 %15, %16
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
br label %20
20: ; preds = %14, %5
br label %5
21: ; preds = %13
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Waiting for running jobs to finish\0A\00"
@errno = global i64 0
@ECHILD = global i64 0
@EINTR = global i64 0
define void @wait_for_jobs() {
%1 = alloca i32
%2 = load i32, i32* @stderr
%3 = tail call i32 @fprintf(i32 %2, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%4 = bitcast i32* %1 to i8*
br label %5
5: ; preds = %17, %0
%6 = call i32 @wait(i32* %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = load i64, i64* @errno
%10 = load i64, i64* @ECHILD
%11 = icmp eq i64 %9, %10
br i1 %11, label %18, label %12
12: ; preds = %8
%13 = load i64, i64* @EINTR
%14 = icmp eq i64 %9, %13
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
br label %17
17: ; preds = %5, %12
br label %5
18: ; preds = %8
ret void
}