#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*/ SIGTERM;
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 /*<<< orphan*/ perror(char *);
int cancel_shutdown(void) {
  FILE *f = fopen("/var/run/shutdown.pid", "r");
  if (!f) {
    perror("shutdown: could not open PID file");
    return 1;
  }
  pid_t pid;
  if (fscanf(f, "%d", &pid) != 1) {
    perror("shutdown: could not read PID file");
    fclose(f);
    return 1;
  }
  fclose(f);
  if (kill(pid, SIGTERM) < 0) {
    perror("shutdown: could not signal other instance");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<cancel_shutdown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1192 <cancel_shutdown+0x42>
lea    0xe97(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1213 <cancel_shutdown+0xc3>
mov    -0x10(%rbp),%rdi
lea    0xe9d(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     11d0 <cancel_shutdown+0x80>
lea    0xe87(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1213 <cancel_shutdown+0xc3>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%edi
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
cmp    $0x0,%rax
jge    120c <cancel_shutdown+0xbc>
lea    0xe64(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1213 <cancel_shutdown+0xc3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cancel_shutdown>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b3 <cancel_shutdown+0x63>
mov    %rax,%rbx
lea    0xec3(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11bc <cancel_shutdown+0x6c>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
js     11d2 <cancel_shutdown+0x82>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe5e(%rip),%rdi
jmp    11d9 <cancel_shutdown+0x89>
lea    0xe7a(%rip),%rdi
call   1070 <perror@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11de <cancel_shutdown+0x8e>
lea    0xe86(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    11ad <cancel_shutdown+0x5d>

LLVM IR (-O0):
@.str = [22 x i8] c"/var/run/shutdown.pid\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"shutdown: could not open PID file\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [34 x i8] c"shutdown: could not read PID file\00"
@SIGTERM = global i32 0
@.str.5 = [42 x i8] c"shutdown: could not signal other instance\00"
define i32 @cancel_shutdown() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 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** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %27
9: ; preds = %0
%10 = load i32*, i32** %2
%11 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%15 = load i32*, i32** %2
%16 = call i32 @fclose(i32* %15)
store i32 1, i32* %1
br label %27
17: ; preds = %9
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
%20 = load i32, i32* %3
%21 = load i32, i32* @SIGTERM
%22 = call i64 @kill(i32 %20, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %27
26: ; preds = %17
store i32 0, i32* %1
br label %27
27: ; preds = %26, %24, %13, %7
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [22 x i8] c"/var/run/shutdown.pid\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"shutdown: could not open PID file\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [34 x i8] c"shutdown: could not read PID file\00"
@SIGTERM = global i32 0
@.str.5 = [42 x i8] c"shutdown: could not signal other instance\00"
define i32 @cancel_shutdown() {
%1 = alloca i32
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %23
6: ; preds = %0
%7 = bitcast i32* %1 to i8*
%8 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%9 = icmp eq i32 %8, 1
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%12 = call i32 @fclose(i32* %2)
br label %21
13: ; preds = %6
%14 = call i32 @fclose(i32* %2)
%15 = load i32, i32* %1
%16 = load i32, i32* @SIGTERM
%17 = call i64 @kill(i32 %15, i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
br label %21
21: ; preds = %13, %19, %10
%22 = phi i32 [ 1, %10 ], [ 1, %19 ], [ 0, %13 ]
br label %23
23: ; preds = %21, %4
%24 = phi i32 [ %22, %21 ], [ 1, %4 ]
ret i32 %24
}