#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 *, long *);
int /*<<< orphan*/ strerror(scalar_t__);
void do_pidfile(const char *name) {
  FILE *f;
  long pid;
  f = fopen(name, "r");
  if (f) {
    if (fscanf(f, "%ld", &pid) == 1)
      check((pid_t)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     11c1 <do_pidfile+0x61>
mov    -0x10(%rbp),%rdi
lea    0xe6c(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11b3 <do_pidfile+0x53>
mov    -0x18(%rbp),%rax
mov    %eax,%edi
call   1060 <check@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1209 <do_pidfile+0xa9>
mov    0x2e18(%rip),%rax
mov    (%rax),%rax
mov    0x2dfe(%rip),%rcx
cmp    (%rcx),%rax
je     1204 <do_pidfile+0xa4>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2df6(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe07(%rip),%rdi
call   1080 <fatal@plt>
jmp    1209 <do_pidfile+0xa9>
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     11a4 <do_pidfile+0x44>
mov    %rax,%rbx
lea    0xe80(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    119a <do_pidfile+0x3a>
mov    (%rsp),%edi
call   1060 <check@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11ba <do_pidfile+0x5a>
mov    0x2e35(%rip),%rax
mov    (%rax),%rdi
mov    0x2e1b(%rip),%rax
cmp    (%rax),%rdi
jne    11c2 <do_pidfile+0x62>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
call   1070 <strerror@plt>
lea    0xe38(%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 = [4 x i8] c"%ld\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 i64
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 %20
9: ; preds = %1
%10 = load i32*, i32** %3
%11 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %4)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i64, i64* %4
%15 = trunc i64 %14 to i32
%16 = call i32 @check(i32 %15)
br label %17
17: ; preds = %13, %9
%18 = load i32*, i32** %3
%19 = call i32 @fclose(i32* %18)
br label %30
20: ; preds = %1
%21 = load i64, i64* @errno
%22 = load i64, i64* @ENOENT
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i8*, i8** %2
%26 = load i64, i64* @errno
%27 = call i32 @strerror(i64 %26)
%28 = call i32 @fatal(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %25, i32 %27)
br label %29
29: ; preds = %24, %20
br label %30
30: ; preds = %29, %17
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%ld\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 i64
%3 = bitcast i64* %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 %15, label %6
6: ; preds = %1
%7 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i64, i64* %2
%11 = trunc i64 %10 to i32
%12 = call i32 @check(i32 %11)
br label %13
13: ; preds = %9, %6
%14 = call i32 @fclose(i32* %4)
br label %22
15: ; preds = %1
%16 = load i64, i64* @errno
%17 = load i64, i64* @ENOENT
%18 = icmp eq i64 %16, %17
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = tail call i32 @strerror(i64 %16)
%21 = tail call i32 @fatal(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %20)
br label %22
22: ; preds = %15, %19, %13
ret void
}