#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_process_msg;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int kill_pid_handle(char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int process_cancel(int sockfd, char *buf) {
  int ret = 0;
  char pid_process_msg[2048];
  memset(pid_process_msg, 0, sizeof(pid_process_msg));
  ret = kill_pid_handle(pid_process_msg, buf);
  if (ret > 0) {
    if (send(sockfd, pid_process_msg, strlen(pid_process_msg), 0) == -1) {
      printf("send:%s", strerror(errno));
      return -1;
    }
  }
  if (sockfd) {
    close(sockfd);
  }
  return ret;
}


x86 assembly (clang, -O0):
<process_cancel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <kill_pid_handle@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1229 <process_cancel+0xb9>
mov    -0x8(%rbp),%eax
mov    %eax,-0x82c(%rbp)
lea    -0x820(%rbp),%rax
mov    %rax,-0x828(%rbp)
lea    -0x820(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x82c(%rbp),%edi
mov    -0x828(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
jne    1224 <process_cancel+0xb4>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xded(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <process_cancel+0xd1>
jmp    1229 <process_cancel+0xb9>
cmpl   $0x0,-0x8(%rbp)
je     123b <process_cancel+0xcb>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_cancel>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%rbp
mov    %edi,%r14d
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <kill_pid_handle@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11c3 <process_cancel+0x53>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     11d2 <process_cancel+0x62>
test   %r14d,%r14d
je     11f4 <process_cancel+0x84>
mov    %r14d,%edi
call   1070 <close@plt>
jmp    11f4 <process_cancel+0x84>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe19(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"send:%s\00"
@errno = global i32 0
define i32 @process_cancel(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [2048 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %6
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 2048)
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%11 = load i8*, i8** %5
%12 = call i32 @kill_pid_handle(i8* %10, i8* %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %27
15: ; preds = %2
%16 = load i32, i32* %4
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%18 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @send(i32 %16, i8* %17, i32 %19, i32 0)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %24)
store i32 -1, i32* %3
br label %35
26: ; preds = %15
br label %27
27: ; preds = %26, %2
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* %4
%32 = call i32 @close(i32 %31)
br label %33
33: ; preds = %30, %27
%34 = load i32, i32* %6
store i32 %34, i32* %3
br label %35
35: ; preds = %33, %22
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [8 x i8] c"send:%s\00"
@errno = global i32 0
define i32 @process_cancel(i32 %0, i8* %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 2048)
%6 = call i32 @kill_pid_handle(i8* %4, i8* %1)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %2
%9 = call i32 @strlen(i8* %4)
%10 = call i32 @send(i32 %0, i8* %4, i32 %9, i32 0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %20
16: ; preds = %8, %2
%17 = icmp eq i32 %0, 0
br i1 %17, label %20, label %18
18: ; preds = %16
%19 = call i32 @close(i32 %0)
br label %20
20: ; preds = %16, %18, %12
%21 = phi i32 [ -1, %12 ], [ %6, %18 ], [ %6, %16 ]
ret i32 %21
}