#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 */
int /*<<< orphan*/ WAIT_MYPGRP;
int WNOHANG;
int WUNTRACED;
scalar_t__ printf(char *, ...);
int returnChildStatus(int /*<<< orphan*/ *, int);
int waitpid(int /*<<< orphan*/, int *, int);
void checkForBackgroundChildren() {
  pid_t w_pid;
  int status;
  0 && printf("polling for backgrounded processes\n");
  while ((w_pid = waitpid(WAIT_MYPGRP, &status, WNOHANG | WUNTRACED)) > 0) {
    0 && printf("poll, w_pid = %d\n", w_pid);
    printf("pid(%d): ", w_pid);
    status = returnChildStatus(NULL, status);
  }
}


x86 assembly (clang, -O0):
<checkForBackgroundChildren>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%edx
mov    0x2e7f(%rip),%rax
or     (%rax),%edx
lea    -0x8(%rbp),%rsi
call   1040 <waitpid@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jle    118d <checkForBackgroundChildren+0x5d>
mov    -0x4(%rbp),%esi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1050 <returnChildStatus@plt>
mov    %eax,-0x8(%rbp)
jmp    1138 <checkForBackgroundChildren+0x8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkForBackgroundChildren>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2ea4(%rip),%r15
mov    (%r15),%edi
mov    0x2e92(%rip),%r12
mov    0x2e7b(%rip),%r13
mov    0x0(%r13),%edx
or     (%r12),%edx
lea    0xc(%rsp),%rsi
call   1040 <waitpid@plt>
test   %eax,%eax
jle    11b2 <checkForBackgroundChildren+0x82>
lea    0xe8e(%rip),%r14
lea    0xc(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%esi
xor    %edi,%edi
call   1050 <returnChildStatus@plt>
mov    %eax,0xc(%rsp)
mov    (%r15),%edi
mov    0x0(%r13),%edx
or     (%r12),%edx
mov    %rbx,%rsi
call   1040 <waitpid@plt>
test   %eax,%eax
jg     1180 <checkForBackgroundChildren+0x50>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@WAIT_MYPGRP = global i32 0
@WNOHANG = global i32 0
@WUNTRACED = global i32 0
@.str = [10 x i8] c"pid(%d): \00"
define void @checkForBackgroundChildren() {
%1 = alloca i32
%2 = alloca i32
br label %3
3: ; preds = %10, %0
%4 = load i32, i32* @WAIT_MYPGRP
%5 = load i32, i32* @WNOHANG
%6 = load i32, i32* @WUNTRACED
%7 = or i32 %5, %6
%8 = call i32 @waitpid(i32 %4, i32* %2, i32 %7)
store i32 %8, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = load i32, i32* %1
%12 = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %2
%14 = call i32 @returnChildStatus(i32* null, i32 %13)
store i32 %14, i32* %2
br label %3
15: ; preds = %3
ret void
}

LLVM IR (-O2):
@WAIT_MYPGRP = global i32 0
@WNOHANG = global i32 0
@WUNTRACED = global i32 0
@.str = [10 x i8] c"pid(%d): \00"
define void @checkForBackgroundChildren() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @WAIT_MYPGRP
%4 = load i32, i32* @WNOHANG
%5 = load i32, i32* @WUNTRACED
%6 = or i32 %5, %4
%7 = call i32 @waitpid(i32 %3, i32* %1, i32 %6)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %0, %9
%10 = phi i32 [ %18, %9 ], [ %7, %0 ]
%11 = call i64 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %1
%13 = call i32 @returnChildStatus(i32* null, i32 %12)
store i32 %13, i32* %1
%14 = load i32, i32* @WAIT_MYPGRP
%15 = load i32, i32* @WNOHANG
%16 = load i32, i32* @WUNTRACED
%17 = or i32 %16, %15
%18 = call i32 @waitpid(i32 %14, i32* %1, i32 %17)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %9, label %20
20: ; preds = %9, %0
ret void
}