#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 */
scalar_t__ ENOENT;
int /*<<< orphan*/ check(int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ fatal(char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ strerror(scalar_t__);
void do_pidfile(const char *name) {
  FILE *f;
  pid_t pid;
  f = fopen(name, "r");
  if (f) {
    if (fscanf(f, "%d", &pid) == 1)
      check(pid);
    fclose(f);
  } else if (errno != ENOENT)
    fatal("open pidfile %s: %s", name, strerror(errno));
}


x86 assembly (clang, -O0):
<do_pidfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11be <do_pidfile+0x5e>
mov    -0x10(%rbp),%rdi
lea    0xe6c(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11b0 <do_pidfile+0x50>
mov    -0x14(%rbp),%edi
call   1060 <check@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1206 <do_pidfile+0xa6>
mov    0x2e1b(%rip),%rax
mov    (%rax),%rax
mov    0x2e01(%rip),%rcx
cmp    (%rcx),%rax
je     1201 <do_pidfile+0xa1>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2df9(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe09(%rip),%rdi
call   1080 <fatal@plt>
jmp    1206 <do_pidfile+0xa6>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_pidfile>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe92(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11a7 <do_pidfile+0x47>
mov    %rax,%rbx
lea    0xe80(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    119d <do_pidfile+0x3d>
mov    0x4(%rsp),%edi
call   1060 <check@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11bd <do_pidfile+0x5d>
mov    0x2e32(%rip),%rax
mov    (%rax),%rdi
mov    0x2e18(%rip),%rax
cmp    (%rax),%rdi
jne    11c5 <do_pidfile+0x65>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
call   1070 <strerror@plt>
lea    0xe34(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <fatal@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [20 x i8] c"open pidfile %s: %s\00"
define void @do_pidfile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %19
9: ; preds = %1
%10 = load i32*, i32** %3
%11 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* %4
%15 = call i32 @check(i32 %14)
br label %16
16: ; preds = %13, %9
%17 = load i32*, i32** %3
%18 = call i32 @fclose(i32* %17)
br label %29
19: ; preds = %1
%20 = load i64, i64* @errno
%21 = load i64, i64* @ENOENT
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i8*, i8** %2
%25 = load i64, i64* @errno
%26 = call i32 @strerror(i64 %25)
%27 = call i32 @fatal(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %24, i32 %26)
br label %28
28: ; preds = %23, %19
br label %29
29: ; preds = %28, %16
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [20 x i8] c"open pidfile %s: %s\00"
define void @do_pidfile(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* %2
%11 = call i32 @check(i32 %10)
br label %12
12: ; preds = %9, %6
%13 = call i32 @fclose(i32* %4)
br label %21
14: ; preds = %1
%15 = load i64, i64* @errno
%16 = load i64, i64* @ENOENT
%17 = icmp eq i64 %15, %16
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = tail call i32 @strerror(i64 %15)
%20 = tail call i32 @fatal(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %19)
br label %21
21: ; preds = %14, %18, %12
ret void
}