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

/* Variables and functions */
int /*<<< orphan*/ SIGUSR2;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *);
scalar_t__ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int kill_with_pidfile(void) {
  FILE *fp;
  pid_t pid;
  int res = 0;
  if ((fp = fopen("/var/run/opiealarm.pid", "r"))) {
    if (fscanf(fp, "%d", &pid) == 1)
      res = (kill(pid, SIGUSR2) == 0) ? 1 : 0;
    fclose(fp);
  }
  return res;
}


x86 assembly (clang, -O0):
<kill_with_pidfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x10(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     11bb <kill_with_pidfile+0x7b>
mov    -0x8(%rbp),%rdi
lea    0xe9e(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11b2 <kill_with_pidfile+0x72>
mov    -0xc(%rbp),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kill_with_pidfile>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
lea    0xec6(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119e <kill_with_pidfile+0x5e>
mov    %rax,%rbx
lea    0xeb4(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
jne    1194 <kill_with_pidfile+0x54>
mov    0x4(%rsp),%edi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11a0 <kill_with_pidfile+0x60>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"/var/run/opiealarm.pid\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@SIGUSR2 = global i32 0
define i32 @kill_with_pidfile() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
%4 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %1
%5 = icmp ne i32* %4, null
br i1 %5, label %6, label %20
6: ; preds = %0
%7 = load i32*, i32** %1
%8 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = load i32, i32* %2
%12 = load i32, i32* @SIGUSR2
%13 = call i64 @kill(i32 %11, i32 %12)
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i64
%16 = select i1 %14, i32 1, i32 0
store i32 %16, i32* %3
br label %17
17: ; preds = %10, %6
%18 = load i32*, i32** %1
%19 = call i32 @fclose(i32* %18)
br label %20
20: ; preds = %17, %0
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [23 x i8] c"/var/run/opiealarm.pid\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@SIGUSR2 = global i32 0
define i32 @kill_with_pidfile() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %17, label %5
5: ; preds = %0
%6 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %14
8: ; preds = %5
%9 = load i32, i32* %1
%10 = load i32, i32* @SIGUSR2
%11 = call i64 @kill(i32 %9, i32 %10)
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %8, %5
%15 = phi i32 [ %13, %8 ], [ 0, %5 ]
%16 = call i32 @fclose(i32* %3)
br label %17
17: ; preds = %14, %0
%18 = phi i32 [ %15, %14 ], [ 0, %0 ]
ret i32 %18
}