#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 EOF;
int /*<<< orphan*/ F_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char const *, int *);
int get_attribute(char *path, const char *fmt, int *value) {
  FILE *fp;
  int rc;
  rc = access(path, F_OK);
  if (rc)
    return -1;
  fp = fopen(path, "r");
  if (!fp)
    return -1;
  rc = fscanf(fp, fmt, value);
  fclose(fp);
  if (rc == EOF)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<get_attribute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     117f <get_attribute+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <get_attribute+0xac>
mov    -0x10(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11aa <get_attribute+0x6a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <get_attribute+0xac>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2c(%rbp),%eax
mov    0x2e17(%rip),%rcx
cmp    (%rcx),%eax
jne    11e5 <get_attribute+0xa5>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <get_attribute+0xac>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_attribute>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
jne    11a9 <get_attribute+0x69>
lea    0xe92(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a9 <get_attribute+0x69>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2e4a(%rip),%rax
xor    %ebp,%ebp
cmp    (%rax),%r14d
sete   %bpl
neg    %ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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