#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 /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ kill(int, int /*<<< orphan*/);
int read_lock();
int /*<<< orphan*/ stderr;
int kill_daemon() {
  int pid = read_lock();
  if (pid < 0) {
    fprintf(stderr, "Failed to acquire pid for %s\n", "home-rf433");
    return -1;
  }
  if (kill(pid, SIGTERM) < 0) {
    fprintf(stderr, "Failed to kill process [%d] %s\n", pid, "home-rf433");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<kill_daemon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <read_lock@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1176 <kill_daemon+0x46>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
lea    0xebb(%rip),%rdx
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <kill_daemon+0x95>
mov    -0x8(%rbp),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
cmp    $0x0,%rax
jge    11be <kill_daemon+0x8e>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe85(%rip),%rsi
lea    0xe73(%rip),%rcx
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <kill_daemon+0x95>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kill_daemon>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <read_lock@plt>
test   %eax,%eax
js     1179 <kill_daemon+0x49>
mov    %eax,%ebp
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1040 <kill@plt>
test   %rax,%rax
jns    119c <kill_daemon+0x6c>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xec2(%rip),%rsi
lea    0xeb0(%rip),%rcx
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1197 <kill_daemon+0x67>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
lea    0xe8e(%rip),%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Failed to acquire pid for %s\0A\00"
@.str.1 = [11 x i8] c"home-rf433\00"
@SIGTERM = global i32 0
@.str.2 = [32 x i8] c"Failed to kill process [%d] %s\0A\00"
define i32 @kill_daemon() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @read_lock()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %19
9: ; preds = %0
%10 = load i32, i32* %2
%11 = load i32, i32* @SIGTERM
%12 = call i64 @kill(i32 %10, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i32, i32* %2
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %19
18: ; preds = %9
store i32 0, i32* %1
br label %19
19: ; preds = %18, %14, %6
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Failed to acquire pid for %s\0A\00"
@.str.1 = [11 x i8] c"home-rf433\00"
@SIGTERM = global i32 0
@.str.2 = [32 x i8] c"Failed to kill process [%d] %s\0A\00"
define i32 @kill_daemon() {
%1 = tail call i32 (...) @read_lock()
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %13
6: ; preds = %0
%7 = load i32, i32* @SIGTERM
%8 = tail call i64 @kill(i32 %1, i32 %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %6, %10, %3
%14 = phi i32 [ -1, %3 ], [ -1, %10 ], [ 0, %6 ]
ret i32 %14
}