#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int check_instance(const char *pidfile) {
  FILE *f;
  int pid;
  if (!pidfile)
    return 0;
  if ((f = fopen(pidfile, "r")) == NULL)
    return 0;
  if (!fscanf(f, "%d", &pid))
    pid = 0;
  fclose(f);
  return pid;
}


x86 assembly (clang, -O0):
<check_instance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <check_instance+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <check_instance+0x80>
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    117d <check_instance+0x4d>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <check_instance+0x80>
mov    -0x18(%rbp),%rdi
lea    0xe7a(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x0,%eax
jne    11a1 <check_instance+0x71>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_instance>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     117a <check_instance+0x4a>
lea    0xebf(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     117a <check_instance+0x4a>
mov    %rax,%rbx
lea    0xead(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
test   %eax,%eax
jne    116e <check_instance+0x3e>
movl   $0x0,0x4(%rsp)
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x4(%rsp),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @check_instance(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %15, label %8
8: ; preds = %5
%9 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %8
store i32 0, i32* %2
br label %12
12: ; preds = %11, %8
%13 = call i32 @fclose(i32* %6)
%14 = load i32, i32* %2
br label %15
15: ; preds = %5, %1, %12
%16 = phi i32 [ %14, %12 ], [ 0, %1 ], [ 0, %5 ]
ret i32 %16
}