#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ SIGINT;
int kill(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char const *);
int /*<<< orphan*/ zrpc_log(char *, char const *, scalar_t__, char *);
scalar_t__ zrpc_util_get_pid_output(char const *);
void zrpc_kill_child(const char *pidfile, const char *process_name) {
  pid_t pid;
  int ret;
  pid = zrpc_util_get_pid_output(pidfile);
  if (pid) {
    ret = kill(pid, SIGINT);
    if (ret == 0)
      unlink(pidfile);
    zrpc_log("Kill %s instance (%d) %s", process_name, pid,
             ret == 0 ? "OK" : "NOK");
  }
}


x86 assembly (clang, -O0):
<zrpc_kill_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <zrpc_util_get_pid_output@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11bc <zrpc_kill_child+0x7c>
mov    -0x18(%rbp),%rdi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1190 <zrpc_kill_child+0x50>
mov    -0x8(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%edi
lea    0xe77(%rip),%rcx
lea    0xe71(%rip),%rax
cmp    $0x0,%edi
cmove  %rax,%rcx
lea    0xe49(%rip),%rdi
call   1040 <zrpc_log@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zrpc_kill_child>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1060 <zrpc_util_get_pid_output@plt>
test   %rax,%rax
je     1176 <zrpc_kill_child+0x36>
mov    %rax,%rbx
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <kill@plt>
test   %eax,%eax
je     117c <zrpc_kill_child+0x3c>
lea    0xea5(%rip),%rcx
jmp    118b <zrpc_kill_child+0x4b>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
call   1030 <unlink@plt>
lea    0xe8f(%rip),%rcx
lea    0xe6e(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <zrpc_log@plt>

LLVM IR (-O0):
@SIGINT = global i32 0
@.str = [25 x i8] c"Kill %s instance (%d) %s\00"
@.str.1 = [3 x i8] c"OK\00"
@.str.2 = [4 x i8] c"NOK\00"
define void @zrpc_kill_child(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i64 @zrpc_util_get_pid_output(i8* %7)
store i64 %8, i64* %5
%9 = load i64, i64* %5
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %2
%12 = load i64, i64* %5
%13 = load i32, i32* @SIGINT
%14 = call i32 @kill(i64 %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = call i32 @unlink(i8* %18)
br label %20
20: ; preds = %17, %11
%21 = load i8*, i8** %4
%22 = load i64, i64* %5
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 0
%25 = zext i1 %24 to i64
%26 = select i1 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%27 = call i32 @zrpc_log(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %21, i64 %22, i8* %26)
br label %28
28: ; preds = %20, %2
ret void
}

LLVM IR (-O2):
@SIGINT = global i32 0
@.str = [25 x i8] c"Kill %s instance (%d) %s\00"
@.str.1 = [3 x i8] c"OK\00"
@.str.2 = [4 x i8] c"NOK\00"
define void @zrpc_kill_child(i8* %0, i8* %1) {
%3 = tail call i64 @zrpc_util_get_pid_output(i8* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = load i32, i32* @SIGINT
%7 = tail call i32 @kill(i64 %3, i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @unlink(i8* %0)
br label %11
11: ; preds = %9, %5
%12 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %5 ]
%13 = tail call i32 @zrpc_log(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %1, i64 %3, i8* %12)
br label %14
14: ; preds = %11, %2
ret void
}