#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*/ SIGKILL;
int /*<<< orphan*/ SIGTERM;
int already_running(char const *);
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sleep(int);
int kill_daemon(const char *pidfile) {
  int pid = already_running(pidfile);
  if (pid) {
    printf("Signalling process with pid %d\n", pid);
    kill(pid, SIGTERM);
    sleep(1);
    kill(pid, SIGKILL);
  } else
    puts("No daemon running");
  return 0;
}


x86 assembly (clang, -O0):
<kill_daemon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <already_running@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11b2 <kill_daemon+0x62>
mov    -0xc(%rbp),%esi
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    -0xc(%rbp),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
jmp    11be <kill_daemon+0x6e>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kill_daemon>:
push   %rbx
call   1050 <already_running@plt>
test   %eax,%eax
je     1196 <kill_daemon+0x46>
mov    %eax,%ebx
lea    0xe9d(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1060 <kill@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1060 <kill@plt>
jmp    11a2 <kill_daemon+0x52>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Signalling process with pid %d\0A\00"
@SIGTERM = global i32 0
@SIGKILL = global i32 0
@.str.1 = [18 x i8] c"No daemon running\00"
define i32 @kill_daemon(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @already_running(i8* %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %1
%9 = load i32, i32* %3
%10 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %3
%12 = load i32, i32* @SIGTERM
%13 = call i32 @kill(i32 %11, i32 %12)
%14 = call i32 @sleep(i32 1)
%15 = load i32, i32* %3
%16 = load i32, i32* @SIGKILL
%17 = call i32 @kill(i32 %15, i32 %16)
br label %20
18: ; preds = %1
%19 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %8
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"Signalling process with pid %d\0A\00"
@SIGTERM = global i32 0
@SIGKILL = global i32 0
@.str.1 = [18 x i8] c"No daemon running\00"
define i32 @kill_daemon(i8* %0) {
%2 = tail call i32 @already_running(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %2)
%6 = load i32, i32* @SIGTERM
%7 = tail call i32 @kill(i32 %2, i32 %6)
%8 = tail call i32 @sleep(i32 1)
%9 = load i32, i32* @SIGKILL
%10 = tail call i32 @kill(i32 %2, i32 %9)
br label %13
11: ; preds = %1
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %4
ret i32 0
}