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

/* Variables and functions */
int /*<<< orphan*/ SIGUSR1;
scalar_t__ atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int kill(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int main() {
  FILE *f;
  char buf[65];
  pid_t pid;
  memset(buf, 0, 65);
  f = fopen("/var/run/smsd.pid", "r");
  if (f == NULL) {
    return 2;
  }
  fread(buf, 1, 64, f);
  fclose(f);
  pid = atoi(buf);
  if (pid <= 0) {
    return 3;
  }
  return -kill(pid, SIGUSR1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1050 <memset@plt>
lea    0xe7a(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ad <main+0x4d>
movl   $0x2,-0x4(%rbp)
jmp    120c <main+0xac>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x40,%edx
call   1030 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x60(%rbp),%rdi
call   1080 <atoi@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jg     11f1 <main+0x91>
movl   $0x3,-0x4(%rbp)
jmp    120c <main+0xac>
mov    -0x68(%rbp),%rdi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1050 <memset@plt>
lea    0xe83(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d3 <main+0x73>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x40,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1080 <atoi@plt>
test   %rax,%rax
jle    11da <main+0x7a>
mov    0x2e23(%rip),%rcx
mov    (%rcx),%esi
mov    %rax,%rdi
call   1060 <kill@plt>
neg    %eax
jmp    11df <main+0x7f>
mov    $0x2,%eax
jmp    11df <main+0x7f>
mov    $0x3,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/var/run/smsd.pid\00"
@.str.1 = [2 x i8] c"r\00"
@SIGUSR1 = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [65 x i8]
%4 = alloca i64
store i32 0, i32* %1
%5 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 65)
%7 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 2, i32* %1
br label %27
11: ; preds = %0
%12 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 0
%13 = load i32*, i32** %2
%14 = call i32 @fread(i8* %12, i32 1, i32 64, i32* %13)
%15 = load i32*, i32** %2
%16 = call i32 @fclose(i32* %15)
%17 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 0
%18 = call i64 @atoi(i8* %17)
store i64 %18, i64* %4
%19 = load i64, i64* %4
%20 = icmp sle i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %11
store i32 3, i32* %1
br label %27
22: ; preds = %11
%23 = load i64, i64* %4
%24 = load i32, i32* @SIGUSR1
%25 = call i32 @kill(i64 %23, i32 %24)
%26 = sub nsw i32 0, %25
store i32 %26, i32* %1
br label %27
27: ; preds = %22, %21, %10
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [18 x i8] c"/var/run/smsd.pid\00"
@.str.1 = [2 x i8] c"r\00"
@SIGUSR1 = global i32 0
define i32 @main() {
%1 = alloca [65 x i8]
%2 = getelementptr inbounds [65 x i8], [65 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 0, i32 65)
%4 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %15, label %6
6: ; preds = %0
%7 = call i32 @fread(i8* %2, i32 1, i32 64, i32* %4)
%8 = call i32 @fclose(i32* %4)
%9 = call i64 @atoi(i8* %2)
%10 = icmp slt i64 %9, 1
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = load i32, i32* @SIGUSR1
%13 = call i32 @kill(i64 %9, i32 %12)
%14 = sub nsw i32 0, %13
br label %15
15: ; preds = %6, %0, %11
%16 = phi i32 [ %14, %11 ], [ 2, %0 ], [ 3, %6 ]
ret i32 %16
}