#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 /*<<< orphan*/ free(int *);
scalar_t__ kill(int, int /*<<< orphan*/);
int *pidof(char *);
int /*<<< orphan*/ usleep(int);
char kill_process(char *process_name) {
  char resx = 0;
  int *listx;
  listx = pidof(process_name);
  if (listx && (listx[0] != -1)) {
    if (kill(listx[0], SIGTERM) != 0) {
      usleep(100000);
      resx = kill(listx[0], SIGKILL) == 0;
    }
  }
  free(listx);
  return resx;
}


x86 assembly (clang, -O0):
<kill_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <pidof@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c5 <kill_process+0x85>
mov    -0x18(%rbp),%rax
cmpl   $0xffffffff,(%rax)
je     11c5 <kill_process+0x85>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
cmp    $0x0,%rax
je     11c0 <kill_process+0x80>
mov    $0x186a0,%edi
call   1060 <usleep@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0x9(%rbp)
jmp    11c5 <kill_process+0x85>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movsbl -0x9(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kill_process>:
push   %rbp
push   %rbx
push   %rax
call   1040 <pidof@plt>
mov    %rax,%rbx
test   %rax,%rax
je     118d <kill_process+0x4d>
mov    (%rbx),%edi
cmp    $0xffffffff,%edi
je     118d <kill_process+0x4d>
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
test   %rax,%rax
je     118d <kill_process+0x4d>
mov    $0x186a0,%edi
call   1060 <usleep@plt>
mov    (%rbx),%edi
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
test   %rax,%rax
sete   %bpl
jmp    118f <kill_process+0x4f>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SIGTERM = global i32 0
@SIGKILL = global i32 0
define signext i8 @kill_process(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32*
store i8* %0, i8** %2
store i8 0, i8* %3
%5 = load i8*, i8** %2
%6 = call i32* @pidof(i8* %5)
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %32
9: ; preds = %1
%10 = load i32*, i32** %4
%11 = getelementptr inbounds i32, i32* %10, i64 0
%12 = load i32, i32* %11
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %32
14: ; preds = %9
%15 = load i32*, i32** %4
%16 = getelementptr inbounds i32, i32* %15, i64 0
%17 = load i32, i32* %16
%18 = load i32, i32* @SIGTERM
%19 = call i64 @kill(i32 %17, i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %14
%22 = call i32 @usleep(i32 100000)
%23 = load i32*, i32** %4
%24 = getelementptr inbounds i32, i32* %23, i64 0
%25 = load i32, i32* %24
%26 = load i32, i32* @SIGKILL
%27 = call i64 @kill(i32 %25, i32 %26)
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
%30 = trunc i32 %29 to i8
store i8 %30, i8* %3
br label %31
31: ; preds = %21, %14
br label %32
32: ; preds = %31, %9, %1
%33 = load i32*, i32** %4
%34 = call i32 @free(i32* %33)
%35 = load i8, i8* %3
ret i8 %35
}

LLVM IR (-O2):
@SIGTERM = global i32 0
@SIGKILL = global i32 0
define signext i8 @kill_process(i8* %0) {
%2 = tail call i32* @pidof(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %18, label %4
4: ; preds = %1
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, -1
br i1 %6, label %18, label %7
7: ; preds = %4
%8 = load i32, i32* @SIGTERM
%9 = tail call i64 @kill(i32 %5, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %7
%12 = tail call i32 @usleep(i32 100000)
%13 = load i32, i32* %2
%14 = load i32, i32* @SIGKILL
%15 = tail call i64 @kill(i32 %13, i32 %14)
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i8
br label %18
18: ; preds = %7, %11, %4, %1
%19 = phi i8 [ %17, %11 ], [ 0, %7 ], [ 0, %4 ], [ 0, %1 ]
%20 = tail call i32 @free(i32* %2)
ret i8 %19
}