#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__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ errno;
int waitpid(unsigned long, int *, int /*<<< orphan*/);
void linux_join(void) {
  extern unsigned long signal_pid;
  int status, ret;
  do {
    ret = waitpid(signal_pid, &status, 0);
    if (WIFEXITED(status) || WIFSIGNALED(status))
      break;
  } while (ret != -1 || errno != ECHILD);
}


x86 assembly (clang, -O0):
<linux_join>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%rdi
lea    -0x4(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <WIFEXITED@plt>
cmp    $0x0,%rax
jne    1174 <linux_join+0x44>
mov    -0x4(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1179 <linux_join+0x49>
jmp    11b2 <linux_join+0x82>
jmp    117e <linux_join+0x4e>
mov    $0x1,%al
cmpl   $0xffffffff,-0x8(%rbp)
mov    %al,-0x9(%rbp)
jne    11a7 <linux_join+0x77>
mov    0x2e44(%rip),%rax
mov    (%rax),%rax
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    1138 <linux_join+0x8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linux_join>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2ea5(%rip),%r14
lea    0xc(%rsp),%rbx
mov    0x2e89(%rip),%r15
mov    0x2e7a(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    (%r14),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %eax,%ebp
mov    0xc(%rsp),%edi
call   1050 <WIFEXITED@plt>
test   %rax,%rax
jne    1199 <linux_join+0x69>
mov    0xc(%rsp),%edi
call   1030 <WIFSIGNALED@plt>
test   %rax,%rax
jne    1199 <linux_join+0x69>
cmp    $0xffffffff,%ebp
jne    1160 <linux_join+0x30>
mov    (%r12),%rax
cmp    %rax,(%r15)
jne    1160 <linux_join+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@signal_pid = external global i64
@errno = global i64 0
@ECHILD = global i64 0
define void @linux_join() {
%1 = alloca i32
%2 = alloca i32
br label %3
3: ; preds = %22, %0
%4 = load i64, i64* @signal_pid
%5 = call i32 @waitpid(i64 %4, i32* %1, i32 0)
store i32 %5, i32* %2
%6 = load i32, i32* %1
%7 = call i64 @WIFEXITED(i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %3
%10 = load i32, i32* %1
%11 = call i64 @WIFSIGNALED(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9, %3
br label %24
14: ; preds = %9
br label %15
15: ; preds = %14
%16 = load i32, i32* %2
%17 = icmp ne i32 %16, -1
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i64, i64* @errno
%20 = load i64, i64* @ECHILD
%21 = icmp ne i64 %19, %20
br label %22
22: ; preds = %18, %15
%23 = phi i1 [ true, %15 ], [ %21, %18 ]
br i1 %23, label %3, label %24
24: ; preds = %22, %13
ret void
}

LLVM IR (-O2):
@signal_pid = external global i64
@errno = global i64 0
@ECHILD = global i64 0
define void @linux_join() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %13, %0
%4 = load i64, i64* @signal_pid
%5 = call i32 @waitpid(i64 %4, i32* %1, i32 0)
%6 = load i32, i32* %1
%7 = call i64 @WIFEXITED(i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %3
%10 = load i32, i32* %1
%11 = call i64 @WIFSIGNALED(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = icmp ne i32 %5, -1
%15 = load i64, i64* @errno
%16 = load i64, i64* @ECHILD
%17 = icmp ne i64 %15, %16
%18 = select i1 %14, i1 true, i1 %17
br i1 %18, label %3, label %19
19: ; preds = %3, %9, %13
ret void
}