#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ system(char *);
void cleanup_locallisten() {
  int retval = access("/var/run/locallisten.pid", F_OK);
  FILE *fp = NULL;
  char tmp[16] = {0}, cmdline[256] = {0};
  if (retval != -1) {
    fp = fopen("/var/run/locallisten.pid", "r");
    if (NULL != fp) {
      fscanf(fp, "%s", tmp);
    }
    fclose(fp);
    if (strlen(tmp) > 0) {
      sprintf(cmdline, "kill -9 %s\n", tmp);
      system(cmdline);
      system("killall -9 locallisten");
    }
  }
}


x86 assembly (clang, -O0):
<cleanup_locallisten>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
lea    0xe65(%rip),%rdi
call   1080 <access@plt>
mov    %eax,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
cmpl   $0xffffffff,-0x4(%rbp)
je     125f <cleanup_locallisten+0xdf>
lea    0xe21(%rip),%rdi
lea    0xe33(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     120f <cleanup_locallisten+0x8f>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xe11(%rip),%rsi
call   1070 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    125a <cleanup_locallisten+0xda>
lea    -0x120(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xde1(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x120(%rbp),%rdi
call   1050 <system@plt>
lea    0xdd5(%rip),%rdi
call   1050 <system@plt>
jmp    125f <cleanup_locallisten+0xdf>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanup_locallisten>:
push   %rbx
sub    $0x110,%rsp
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1070 <access@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
cmp    $0xffffffff,%eax
je     1271 <cleanup_locallisten+0x101>
lea    0xdf5(%rip),%rdi
lea    0xe07(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1231 <cleanup_locallisten+0xc1>
lea    0xdf5(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1060 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %rsp,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    1271 <cleanup_locallisten+0x101>
lea    0xdd1(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1090 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
lea    0xdbe(%rip),%rdi
call   1050 <system@plt>
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/var/run/locallisten.pid\00"
@F_OK = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [12 x i8] c"kill -9 %s\0A\00"
@.str.4 = [23 x i8] c"killall -9 locallisten\00"
define void @cleanup_locallisten() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [16 x i8]
%4 = alloca [256 x i8]
%5 = load i32, i32* @F_OK
%6 = call i32 @access(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %1
store i32* null, i32** %2
%7 = bitcast [16 x i8]* %3 to i8*
%8 = bitcast [256 x i8]* %4 to i8*
%9 = load i32, i32* %1
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %33
11: ; preds = %0
%12 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %2
%13 = load i32*, i32** %2
%14 = icmp ne i32* null, %13
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i32*, i32** %2
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%18 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %15, %11
%20 = load i32*, i32** %2
%21 = call i32 @fclose(i32* %20)
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%23 = call i64 @strlen(i8* %22)
%24 = icmp sgt i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %19
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%28 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%30 = call i32 @system(i8* %29)
%31 = call i32 @system(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %25, %19
br label %33
33: ; preds = %32, %0
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"/var/run/locallisten.pid\00"
@F_OK = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [12 x i8] c"kill -9 %s\0A\00"
@.str.4 = [23 x i8] c"killall -9 locallisten\00"
define void @cleanup_locallisten() {
%1 = alloca [16 x i8]
%2 = alloca [256 x i8]
%3 = load i32, i32* @F_OK
%4 = tail call i32 @access(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%7 = icmp eq i32 %4, -1
br i1 %7, label %21, label %8
8: ; preds = %0
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
br label %13
13: ; preds = %11, %8
%14 = call i32 @fclose(i32* %9)
%15 = call i64 @strlen(i8* %5)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%19 = call i32 @system(i8* %6)
%20 = call i32 @system(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %21
21: ; preds = %13, %17, %0
ret void
}