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

/* Variables and functions */
int /*<<< orphan*/ SIGTERM;
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int kill_pidfile(char *pidfile) {
  FILE *fp = fopen(pidfile, "r");
  char buf[256];
  if (fp && fgets(buf, sizeof(buf), fp)) {
    pid_t pid = strtoul(buf, NULL, 0);
    fclose(fp);
    return kill(pid, SIGTERM);
  } else
    return errno;
}


x86 assembly (clang, -O0):
<kill_pidfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11da <kill_pidfile+0x8a>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11da <kill_pidfile+0x8a>
lea    -0x120(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %eax,-0x124(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x124(%rbp),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    %eax,-0x4(%rbp)
jmp    11e6 <kill_pidfile+0x96>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kill_pidfile>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
lea    0xea0(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11aa <kill_pidfile+0x5a>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11aa <kill_pidfile+0x5a>
mov    %rsp,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1050 <kill@plt>
jmp    11b3 <kill_pidfile+0x63>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SIGTERM = global i32 0
@errno = global i32 0
define i32 @kill_pidfile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [256 x i8]
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %4
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %24
11: ; preds = %1
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%13 = load i32*, i32** %4
%14 = call i64 @fgets(i8* %12, i32 256, i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%18 = call i32 @strtoul(i8* %17, i32* null, i32 0)
store i32 %18, i32* %6
%19 = load i32*, i32** %4
%20 = call i32 @fclose(i32* %19)
%21 = load i32, i32* %6
%22 = load i32, i32* @SIGTERM
%23 = call i32 @kill(i32 %21, i32 %22)
store i32 %23, i32* %2
br label %26
24: ; preds = %11, %1
%25 = load i32, i32* @errno
store i32 %25, i32* %2
br label %26
26: ; preds = %24, %16
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SIGTERM = global i32 0
@errno = global i32 0
define i32 @kill_pidfile(i8* nocapture %0) {
%2 = alloca [256 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = icmp eq i32* %3, null
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = call i64 @fgets(i8* %4, i32 256, i32* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %6
%10 = call i32 @strtoul(i8* nocapture %4, i32* null, i32 0)
%11 = call i32 @fclose(i32* %3)
%12 = load i32, i32* @SIGTERM
%13 = call i32 @kill(i32 %10, i32 %12)
br label %16
14: ; preds = %6, %1
%15 = load i32, i32* @errno
br label %16
16: ; preds = %14, %9
%17 = phi i32 [ %13, %9 ], [ %15, %14 ]
ret i32 %17
}