#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*/ SIGTERM;
int /*<<< orphan*/ check_pid_file_exists(char const *, int *,
                                         int /*<<< orphan*/ *);
int /*<<< orphan*/ check_process_running(int /*<<< orphan*/, char const *,
                                         int *);
scalar_t__ kill(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ unlink(char const *);
int stop_program(const char *program_name, const char *pid_file) {
  int exists;
  int running;
  pid_t existing_pid;
  if (!check_pid_file_exists(pid_file, &exists, &existing_pid))
    return 0;
  if (!exists)
    return 1;
  if (!check_process_running(existing_pid, program_name, &running))
    return 0;
  if (!running)
    return 1;
  if (kill(existing_pid, SIGTERM) != 0)
    return 0;
  if (unlink(pid_file) != 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<stop_program>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <check_pid_file_exists@plt>
cmp    $0x0,%eax
jne    1176 <stop_program+0x36>
movl   $0x0,-0x4(%rbp)
jmp    1214 <stop_program+0xd4>
cmpl   $0x0,-0x1c(%rbp)
jne    118c <stop_program+0x4c>
movl   $0x1,-0x4(%rbp)
jmp    1214 <stop_program+0xd4>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <check_process_running@plt>
cmp    $0x0,%eax
jne    11b1 <stop_program+0x71>
movl   $0x0,-0x4(%rbp)
jmp    1214 <stop_program+0xd4>
cmpl   $0x0,-0x20(%rbp)
jne    11c7 <stop_program+0x87>
movl   $0x1,-0x4(%rbp)
jmp    1214 <stop_program+0xd4>
mov    -0x24(%rbp),%edi
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
cmp    $0x0,%rax
je     11ee <stop_program+0xae>
movl   $0x0,-0x4(%rbp)
jmp    1214 <stop_program+0xd4>
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     120d <stop_program+0xcd>
movl   $0x0,-0x4(%rbp)
jmp    1214 <stop_program+0xd4>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stop_program>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xc(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
call   1040 <check_pid_file_exists@plt>
test   %eax,%eax
je     11bb <stop_program+0x7b>
mov    $0x1,%ebp
cmpl   $0x0,0xc(%rsp)
je     11bd <stop_program+0x7d>
mov    0x4(%rsp),%edi
lea    0x8(%rsp),%rdx
mov    %rbx,%rsi
call   1050 <check_process_running@plt>
test   %eax,%eax
je     11bb <stop_program+0x7b>
cmpl   $0x0,0x8(%rsp)
je     11bd <stop_program+0x7d>
mov    0x4(%rsp),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
mov    $0x0,%ebp
test   %rax,%rax
jne    11bd <stop_program+0x7d>
mov    %r14,%rdi
call   1030 <unlink@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
jmp    11bd <stop_program+0x7d>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SIGTERM = global i32 0
define i32 @stop_program(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @check_pid_file_exists(i8* %9, i32* %6, i32* %8)
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 0, i32* %3
br label %39
13: ; preds = %2
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %13
store i32 1, i32* %3
br label %39
17: ; preds = %13
%18 = load i32, i32* %8
%19 = load i8*, i8** %4
%20 = call i32 @check_process_running(i32 %18, i8* %19, i32* %7)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %17
store i32 0, i32* %3
br label %39
23: ; preds = %17
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %23
store i32 1, i32* %3
br label %39
27: ; preds = %23
%28 = load i32, i32* %8
%29 = load i32, i32* @SIGTERM
%30 = call i64 @kill(i32 %28, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 0, i32* %3
br label %39
33: ; preds = %27
%34 = load i8*, i8** %5
%35 = call i64 @unlink(i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 0, i32* %3
br label %39
38: ; preds = %33
store i32 1, i32* %3
br label %39
39: ; preds = %38, %37, %32, %26, %22, %16, %12
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@SIGTERM = global i32 0
define i32 @stop_program(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = call i32 @check_pid_file_exists(i8* %1, i32* %3, i32* %5)
%10 = icmp eq i32 %9, 0
br i1 %10, label %30, label %11
11: ; preds = %2
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %30, label %14
14: ; preds = %11
%15 = load i32, i32* %5
%16 = call i32 @check_process_running(i32 %15, i8* %0, i32* %4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %30, label %18
18: ; preds = %14
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %18
%22 = load i32, i32* %5
%23 = load i32, i32* @SIGTERM
%24 = call i64 @kill(i32 %22, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = call i64 @unlink(i8* %1)
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
br label %30
30: ; preds = %26, %21, %18, %14, %11, %2
%31 = phi i32 [ 0, %2 ], [ 1, %11 ], [ 0, %14 ], [ 1, %18 ], [ 0, %21 ], [ %29, %26 ]
ret i32 %31
}