#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*/ kill_converting_process(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
int kill_pid_handle(char *dst, char *msg) {
  char *temp_pid = NULL;
  char *p = (char *)msg;
  p += strlen("pid=");
  temp_pid = p;
  while (*p != '\n' && *p != '\r') {
    p++;
  }
  *p = 0;
  p = temp_pid;
  kill_converting_process(p);
  printf("\t KILLPID: pid = %s", p);
  sprintf(dst, "killed pid=%s", p);
  if (strlen(dst) > strlen("killed pid=")) {
    return strlen(dst) - 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<kill_pid_handle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xec2(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x29(%rbp)
je     11a9 <kill_pid_handle+0x69>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11b9 <kill_pid_handle+0x79>
jmp    11ca <kill_pid_handle+0x8a>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1184 <kill_pid_handle+0x44>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <kill_converting_process@plt>
mov    -0x28(%rbp),%rsi
lea    0xe13(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe13(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x30(%rbp)
lea    0xe09(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jle    123f <kill_pid_handle+0xff>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1246 <kill_pid_handle+0x106>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kill_pid_handle>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xed7(%rip),%rdi
call   1040 <strlen@plt>
movslq %eax,%rbx
add    %r15,%rbx
mov    %rbx,%rax
movzbl (%rax),%ecx
cmp    $0xa,%cl
je     1173 <kill_pid_handle+0x33>
cmp    $0xd,%cl
je     1173 <kill_pid_handle+0x33>
add    $0x1,%rax
jmp    1160 <kill_pid_handle+0x20>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1030 <kill_converting_process@plt>
lea    0xe7b(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
lea    0xe80(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1060 <sprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xe72(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%ebx
jle    11c8 <kill_pid_handle+0x88>
mov    %r14,%rdi
call   1040 <strlen@plt>
add    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"pid=\00"
@.str.1 = [20 x i8] c"\09 KILLPID: pid = %s\00"
@.str.2 = [14 x i8] c"killed pid=%s\00"
@.str.3 = [12 x i8] c"killed pid=\00"
define i32 @kill_pid_handle(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
%8 = load i8*, i8** %5
store i8* %8, i8** %7
%9 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = load i8*, i8** %7
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds i8, i8* %10, i64 %11
store i8* %12, i8** %7
%13 = load i8*, i8** %7
store i8* %13, i8** %6
br label %14
14: ; preds = %26, %2
%15 = load i8*, i8** %7
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 10
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i8*, i8** %7
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 13
br label %24
24: ; preds = %19, %14
%25 = phi i1 [ false, %14 ], [ %23, %19 ]
br i1 %25, label %26, label %29
26: ; preds = %24
%27 = load i8*, i8** %7
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %7
br label %14
29: ; preds = %24
%30 = load i8*, i8** %7
store i8 0, i8* %30
%31 = load i8*, i8** %6
store i8* %31, i8** %7
%32 = load i8*, i8** %7
%33 = call i32 @kill_converting_process(i8* %32)
%34 = load i8*, i8** %7
%35 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %4
%37 = load i8*, i8** %7
%38 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = load i8*, i8** %4
%40 = call i32 @strlen(i8* %39)
%41 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp sgt i32 %40, %41
br i1 %42, label %43, label %47
43: ; preds = %29
%44 = load i8*, i8** %4
%45 = call i32 @strlen(i8* %44)
%46 = sub nsw i32 %45, 1
store i32 %46, i32* %3
br label %48
47: ; preds = %29
store i32 0, i32* %3
br label %48
48: ; preds = %47, %43
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [5 x i8] c"pid=\00"
@.str.1 = [20 x i8] c"\09 KILLPID: pid = %s\00"
@.str.2 = [14 x i8] c"killed pid=%s\00"
@.str.3 = [12 x i8] c"killed pid=\00"
define i32 @kill_pid_handle(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %1, i64 %4
br label %6
6: ; preds = %9, %2
%7 = phi i8* [ %5, %2 ], [ %10, %9 ]
%8 = load i8, i8* %7
switch i8 %8, label %9 [
i8 10, label %11
i8 13, label %11
]
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %7, i64 1
br label %6
11: ; preds = %6, %6
store i8 0, i8* %7
%12 = tail call i32 @kill_converting_process(i8* %5)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%15 = tail call i32 @strlen(i8* %0)
%16 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp sgt i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = tail call i32 @strlen(i8* %0)
%20 = add nsw i32 %19, -1
br label %21
21: ; preds = %11, %18
%22 = phi i32 [ %20, %18 ], [ 0, %11 ]
ret i32 %22
}