#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*/ SIGKILL;
int kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ unused(char *, int /*<<< orphan*/);
int waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int terminate_process(pid_t pid) {
  int rc = -1;
  if (kill(pid, SIGKILL) == -1) {
    do {
      unused("kill(%i) failed", pid);
    } while (0);
    goto _out;
  }
  int status;
  if (waitpid(pid, &status, 0) == -1) {
    do {
      unused("waitpid(%i) failed", pid);
    } while (0);
    goto _out;
  }
  rc = 0;
_out:
  return rc;
}


x86 assembly (clang, -O0):
<terminate_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
cmp    $0xffffffff,%eax
jne    1175 <terminate_process+0x45>
jmp    1161 <terminate_process+0x31>
mov    -0x4(%rbp),%esi
lea    0xe95(%rip),%rdi
call   1030 <unused@plt>
jmp    11ac <terminate_process+0x7c>
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    11a5 <terminate_process+0x75>
jmp    1191 <terminate_process+0x61>
mov    -0x4(%rbp),%esi
lea    0xe75(%rip),%rdi
call   1030 <unused@plt>
jmp    11ac <terminate_process+0x7c>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<terminate_process>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
cmp    $0xffffffff,%eax
je     1166 <terminate_process+0x36>
lea    0x4(%rsp),%rsi
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    1179 <terminate_process+0x49>
lea    0xeac(%rip),%rdi
jmp    116d <terminate_process+0x3d>
lea    0xe93(%rip),%rdi
mov    %ebx,%esi
call   1030 <unused@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SIGKILL = global i32 0
@.str = [16 x i8] c"kill(%i) failed\00"
@.str.1 = [19 x i8] c"waitpid(%i) failed\00"
define i32 @terminate_process(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 -1, i32* %3
%5 = load i32, i32* %2
%6 = load i32, i32* @SIGKILL
%7 = call i32 @kill(i32 %5, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %14
9: ; preds = %1
br label %10
10: ; preds = %9
%11 = load i32, i32* %2
%12 = call i32 @unused(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %10
br label %24
14: ; preds = %1
%15 = load i32, i32* %2
%16 = call i32 @waitpid(i32 %15, i32* %4, i32 0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %23
18: ; preds = %14
br label %19
19: ; preds = %18
%20 = load i32, i32* %2
%21 = call i32 @unused(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19
br label %24
23: ; preds = %14
store i32 0, i32* %3
br label %24
24: ; preds = %23, %22, %13
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@SIGKILL = global i32 0
@.str = [16 x i8] c"kill(%i) failed\00"
@.str.1 = [19 x i8] c"waitpid(%i) failed\00"
define i32 @terminate_process(i32 %0) {
%2 = alloca i32
%3 = load i32, i32* @SIGKILL
%4 = tail call i32 @kill(i32 %0, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @unused(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %13
8: ; preds = %1
%9 = call i32 @waitpid(i32 %0, i32* %2, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @unused(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %13
13: ; preds = %8, %11, %6
%14 = phi i32 [ -1, %6 ], [ -1, %11 ], [ 0, %8 ]
ret i32 %14
}