#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 /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ abort();
scalar_t__ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
void kill_wait(pid_t pid) {
  if (kill(pid, SIGUSR1)) {
    perror("Couldn't kill");
    abort();
  }
  int status;
  if (waitpid(pid, &status, 0) < 0) {
    perror("Couldn't wait");
    abort();
  }
}


x86 assembly (clang, -O0):
<kill_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
cmp    $0x0,%rax
je     1179 <kill_wait+0x39>
lea    0xe93(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0x0,%rax
jge    11a4 <kill_wait+0x64>
lea    0xe76(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kill_wait>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
test   %rax,%rax
jne    1173 <kill_wait+0x33>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
test   %rax,%rax
js     117c <kill_wait+0x3c>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe86(%rip),%rdi
jmp    1183 <kill_wait+0x43>
lea    0xe8b(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@SIGUSR1 = global i32 0
@.str = [14 x i8] c"Couldn't kill\00"
@.str.1 = [14 x i8] c"Couldn't wait\00"
define void @kill_wait(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @SIGUSR1
%6 = call i64 @kill(i32 %4, i32 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (...) @abort()
unreachable
11: ; preds = %1
%12 = load i32, i32* %2
%13 = call i64 @waitpid(i32 %12, i32* %3, i32 0)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %11
ret void
}

LLVM IR (-O2):
@SIGUSR1 = global i32 0
@.str = [14 x i8] c"Couldn't kill\00"
@.str.1 = [14 x i8] c"Couldn't wait\00"
define void @kill_wait(i32 %0) {
%2 = alloca i32
%3 = load i32, i32* @SIGUSR1
%4 = tail call i64 @kill(i32 %0, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (...) @abort()
unreachable
9: ; preds = %1
%10 = bitcast i32* %2 to i8*
%11 = call i64 @waitpid(i32 %0, i32* %2, i32 0)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %9
ret void
}