#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*/ SIGKILL;
int /*<<< orphan*/ atoi(char *);
char *get_string(int);
int kill(int /*<<< orphan*/, int /*<<< orphan*/);
int sockerror(int, char *);
int sockprint(int, char *, ...);
scalar_t__ strcmp(char *, char *);
int kill_one_proc(int client_fd) {
  int rc = 0;
  pid_t pid;
  char *entered;
  if (sockprint(client_fd, "Process id (PID, q to abort): ") == -1)
    return -1;
  entered = get_string(client_fd);
  if (!entered)
    return -1;
  if (strcmp(entered, "q") == 0)
    return 0;
  pid = atoi(entered);
  rc = sockprint(client_fd, "Killing pid %d\r\n", pid);
  if (kill(pid, SIGKILL) == -1)
    rc |= sockerror(client_fd, "kill(SIGKILL)");
  return rc;
}


x86 assembly (clang, -O0):
<kill_one_proc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1070 <sockprint@plt>
cmp    $0xffffffff,%eax
jne    1198 <kill_one_proc+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <kill_one_proc+0xd9>
mov    -0x8(%rbp),%edi
call   1030 <get_string@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bb <kill_one_proc+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <kill_one_proc+0xd9>
mov    -0x18(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11e1 <kill_one_proc+0x81>
movl   $0x0,-0x4(%rbp)
jmp    1239 <kill_one_proc+0xd9>
mov    -0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%edx
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1070 <sockprint@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
cmp    $0xffffffff,%eax
jne    1233 <kill_one_proc+0xd3>
mov    -0x8(%rbp),%edi
lea    0xe0a(%rip),%rsi
call   1080 <sockerror@plt>
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kill_one_proc>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
lea    0xe92(%rip),%rsi
xor    %eax,%eax
call   1070 <sockprint@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     11ec <kill_one_proc+0x8c>
mov    %r14d,%edi
call   1030 <get_string@plt>
test   %rax,%rax
je     11ec <kill_one_proc+0x8c>
mov    %rax,%rbx
lea    0xe89(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11ea <kill_one_proc+0x8a>
mov    %rbx,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
lea    0xe6d(%rip),%rsi
mov    %r14d,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <sockprint@plt>
mov    %eax,%ebp
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1050 <kill@plt>
cmp    $0xffffffff,%eax
jne    11ec <kill_one_proc+0x8c>
lea    0xe54(%rip),%rsi
mov    %r14d,%edi
call   1080 <sockerror@plt>
or     %eax,%ebp
jmp    11ec <kill_one_proc+0x8c>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Process id (PID, q to abort): \00"
@.str.1 = [2 x i8] c"q\00"
@.str.2 = [17 x i8] c"Killing pid %d\0D\0A\00"
@SIGKILL = global i32 0
@.str.3 = [14 x i8] c"kill(SIGKILL)\00"
define i32 @kill_one_proc(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %3
store i32 0, i32* %4
%7 = load i32, i32* %3
%8 = call i32 (i32, i8*, ...) @sockprint(i32 %7, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %39
11: ; preds = %1
%12 = load i32, i32* %3
%13 = call i8* @get_string(i32 %12)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %11
store i32 -1, i32* %2
br label %39
17: ; preds = %11
%18 = load i8*, i8** %6
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 0, i32* %2
br label %39
22: ; preds = %17
%23 = load i8*, i8** %6
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %5
%25 = load i32, i32* %3
%26 = load i32, i32* %5
%27 = call i32 (i32, i8*, ...) @sockprint(i32 %25, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %26)
store i32 %27, i32* %4
%28 = load i32, i32* %5
%29 = load i32, i32* @SIGKILL
%30 = call i32 @kill(i32 %28, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %37
32: ; preds = %22
%33 = load i32, i32* %3
%34 = call i32 @sockerror(i32 %33, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%35 = load i32, i32* %4
%36 = or i32 %35, %34
store i32 %36, i32* %4
br label %37
37: ; preds = %32, %22
%38 = load i32, i32* %4
store i32 %38, i32* %2
br label %39
39: ; preds = %37, %21, %16, %10
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@.str = [31 x i8] c"Process id (PID, q to abort): \00"
@.str.1 = [2 x i8] c"q\00"
@.str.2 = [17 x i8] c"Killing pid %d\0D\0A\00"
@SIGKILL = global i32 0
@.str.3 = [14 x i8] c"kill(SIGKILL)\00"
define i32 @kill_one_proc(i32 %0) {
%2 = tail call i32 (i32, i8*, ...) @sockprint(i32 %0, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32 %2, -1
br i1 %3, label %19, label %4
4: ; preds = %1
%5 = tail call i8* @get_string(i32 %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %19, label %7
7: ; preds = %4
%8 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %7
%11 = tail call i32 @atoi(i8* %5)
%12 = tail call i32 (i32, i8*, ...) @sockprint(i32 %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @SIGKILL
%14 = tail call i32 @kill(i32 %11, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = tail call i32 @sockerror(i32 %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%18 = or i32 %17, %12
br label %19
19: ; preds = %10, %16, %7, %4, %1
%20 = phi i32 [ -1, %1 ], [ -1, %4 ], [ 0, %7 ], [ %18, %16 ], [ %12, %10 ]
ret i32 %20
}