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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ UINT_MAX;
int /*<<< orphan*/ cli_file_close(int);
int /*<<< orphan*/ cli_file_open(char *, int /*<<< orphan*/, int *);
int /*<<< orphan*/ cli_file_read(int, char **, size_t *);
int /*<<< orphan*/ cli_strtonum(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fatal(char *, ...);
int kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void cli_reload(int argc, char **argv) {
  int fd;
  size_t len;
  pid_t pid;
  char *buf;
  cli_file_open("kore.pid", O_RDONLY, &fd);
  cli_file_read(fd, &buf, &len);
  cli_file_close(fd);
  if (len == 0)
    fatal("reload: pid file is empty");
  buf[len - 1] = '\0';
  pid = cli_strtonum(buf, 0, UINT_MAX);
  if (kill(pid, SIGHUP) == -1)
    fatal("failed to reload: %s", strerror(errno));
  printf("reloaded application\n");
}


x86 assembly (clang, -O0):
<cli_reload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
lea    -0x14(%rbp),%rdx
call   1070 <cli_file_open@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1030 <cli_file_read@plt>
mov    -0x14(%rbp),%edi
call   1050 <cli_file_close@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11d9 <cli_reload+0x59>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   10a0 <fatal@plt>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <cli_strtonum@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
call   1080 <kill@plt>
cmp    $0xffffffff,%eax
jne    1238 <cli_reload+0xb8>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   10a0 <fatal@plt>
lea    0xdf9(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cli_reload>:
sub    $0x18,%rsp
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
lea    0xe6c(%rip),%rdi
lea    0x4(%rsp),%rdx
call   1070 <cli_file_open@plt>
mov    0x4(%rsp),%edi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1030 <cli_file_read@plt>
mov    0x4(%rsp),%edi
call   1050 <cli_file_close@plt>
mov    0x10(%rsp),%rax
test   %rax,%rax
jne    11d7 <cli_reload+0x57>
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   10a0 <fatal@plt>
mov    0x10(%rsp),%rax
mov    0x8(%rsp),%rcx
movb   $0x0,-0x1(%rax,%rcx,1)
mov    0x8(%rsp),%rdi
mov    0x2deb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <cli_strtonum@plt>
mov    0x2df3(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1080 <kill@plt>
cmp    $0xffffffff,%eax
jne    1229 <cli_reload+0xa9>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe03(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <fatal@plt>
lea    0xe08(%rip),%rdi
call   1040 <puts@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"kore.pid\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"reload: pid file is empty\00"
@UINT_MAX = global i32 0
@SIGHUP = global i32 0
@.str.2 = [21 x i8] c"failed to reload: %s\00"
@errno = global i32 0
@.str.3 = [22 x i8] c"reloaded application\0A\00"
define void @cli_reload(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @cli_file_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9, i32* %5)
%11 = load i32, i32* %5
%12 = call i32 @cli_file_read(i32 %11, i8** %8, i64* %6)
%13 = load i32, i32* %5
%14 = call i32 @cli_file_close(i32 %13)
%15 = load i64, i64* %6
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = load i8*, i8** %8
%21 = load i64, i64* %6
%22 = sub i64 %21, 1
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 0, i8* %23
%24 = load i8*, i8** %8
%25 = load i32, i32* @UINT_MAX
%26 = call i32 @cli_strtonum(i8* %24, i32 0, i32 %25)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = load i32, i32* @SIGHUP
%29 = call i32 @kill(i32 %27, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %19
%32 = load i32, i32* @errno
%33 = call i32 @strerror(i32 %32)
%34 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %31, %19
%36 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"kore.pid\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"reload: pid file is empty\00"
@UINT_MAX = global i32 0
@SIGHUP = global i32 0
@.str.2 = [21 x i8] c"failed to reload: %s\00"
@errno = global i32 0
@str = [21 x i8] c"reloaded application\00"
define void @cli_reload(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = bitcast i32* %3 to i8*
%7 = bitcast i64* %4 to i8*
%8 = bitcast i8** %5 to i8*
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @cli_file_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9, i32* %3)
%11 = load i32, i32* %3
%12 = call i32 @cli_file_read(i32 %11, i8** %5, i64* %4)
%13 = load i32, i32* %3
%14 = call i32 @cli_file_close(i32 %13)
%15 = load i64, i64* %4
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%19 = load i64, i64* %4
br label %20
20: ; preds = %17, %2
%21 = phi i64 [ %19, %17 ], [ %15, %2 ]
%22 = load i8*, i8** %5
%23 = add i64 %21, -1
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8 0, i8* %24
%25 = load i8*, i8** %5
%26 = load i32, i32* @UINT_MAX
%27 = call i32 @cli_strtonum(i8* %25, i32 0, i32 %26)
%28 = load i32, i32* @SIGHUP
%29 = call i32 @kill(i32 %27, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %20
%32 = load i32, i32* @errno
%33 = call i32 @strerror(i32 %32)
%34 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %31, %20
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
ret void
}