#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 */
int ECHILD;
int ESRCH;
scalar_t__ collect_child(int, int *, int /*<<< orphan*/);
int kill_process(int);
int kill_child_and_collect(int pid) {
  int status;
  status = kill_process(pid);
  if (status != -ESRCH)
    return status;
  if (collect_child(pid, &status, 0))
    return -ECHILD;
  return status;
}


x86 assembly (clang, -O0):
<kill_child_and_collect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <kill_process@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
xor    %ecx,%ecx
mov    0x2e8e(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
je     1157 <kill_child_and_collect+0x37>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1188 <kill_child_and_collect+0x68>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1030 <collect_child@plt>
cmp    $0x0,%rax
je     1182 <kill_child_and_collect+0x62>
xor    %eax,%eax
mov    0x2e68(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1188 <kill_child_and_collect+0x68>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kill_child_and_collect>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
call   1040 <kill_process@plt>
mov    %eax,%ebx
mov    %eax,0x4(%rsp)
mov    0x2e99(%rip),%rax
mov    %ebx,%ecx
add    (%rax),%ecx
jne    1161 <kill_child_and_collect+0x41>
lea    0x4(%rsp),%rsi
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <collect_child@plt>
test   %rax,%rax
je     115d <kill_child_and_collect+0x3d>
mov    0x2e87(%rip),%rax
sub    (%rax),%ebx
jmp    1161 <kill_child_and_collect+0x41>
mov    0x4(%rsp),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@ESRCH = global i32 0
@ECHILD = global i32 0
define i32 @kill_child_and_collect(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @kill_process(i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = load i32, i32* @ESRCH
%9 = sub nsw i32 0, %8
%10 = icmp ne i32 %7, %9
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i32, i32* %4
store i32 %12, i32* %2
br label %22
13: ; preds = %1
%14 = load i32, i32* %3
%15 = call i64 @collect_child(i32 %14, i32* %4, i32 0)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* @ECHILD
%19 = sub nsw i32 0, %18
store i32 %19, i32* %2
br label %22
20: ; preds = %13
%21 = load i32, i32* %4
store i32 %21, i32* %2
br label %22
22: ; preds = %20, %17, %11
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@ESRCH = global i32 0
@ECHILD = global i32 0
define i32 @kill_child_and_collect(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 @kill_process(i32 %0)
store i32 %4, i32* %2
%5 = load i32, i32* @ESRCH
%6 = sub nsw i32 0, %5
%7 = icmp eq i32 %4, %6
br i1 %7, label %8, label %16
8: ; preds = %1
%9 = call i64 @collect_child(i32 %0, i32* %2, i32 0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* @ECHILD
%13 = sub nsw i32 0, %12
br label %16
14: ; preds = %8
%15 = load i32, i32* %2
br label %16
16: ; preds = %1, %14, %11
%17 = phi i32 [ %13, %11 ], [ %15, %14 ], [ %4, %1 ]
ret i32 %17
}