#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ check(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
void do_pidfile(const char *name) {
  FILE *f;
  int pid;
  f = fopen(name, "r");
  if (f) {
    if (fscanf(f, "%d", &pid) == 1)
      check(pid);
    fclose(f);
  }
}


x86 assembly (clang, -O0):
<do_pidfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1199 <do_pidfile+0x59>
mov    -0x10(%rbp),%rdi
lea    0xe8c(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1190 <do_pidfile+0x50>
mov    -0x14(%rbp),%edi
call   1060 <check@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_pidfile>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1183 <do_pidfile+0x43>
mov    %rax,%rbx
lea    0xea2(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    117b <do_pidfile+0x3b>
mov    0xc(%rsp),%edi
call   1060 <check@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\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 %19
19: ; preds = %16, %1
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
define void @do_pidfile(i8* nocapture %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 %14
14: ; preds = %12, %1
ret void
}