#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*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int strtol(char *, char **, int);
int iProperty(char *file, char *name, int *val, int _default) {
  char buff[256];
  *val = _default;
  char *next;
  int lname = strlen(name);
  char *endptr;
  FILE *fp = fopen(file, "r");
  if (fp == NULL) {
    return -1;
  }
  while (1) {
    next = fgets(buff, 256, fp);
    if (next == NULL)
      break;
    if (!strncmp(buff, name, lname)) {
      *val = strtol(next + lname, &endptr, 10);
      break;
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<iProperty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x13c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x150(%rbp)
cmpq   $0x0,-0x150(%rbp)
jne    11c3 <iProperty+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    1260 <iProperty+0x100>
jmp    11c8 <iProperty+0x68>
lea    -0x130(%rbp),%rdi
mov    -0x150(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
mov    %rax,-0x138(%rbp)
cmpq   $0x0,-0x138(%rbp)
jne    11fa <iProperty+0x9a>
jmp    124d <iProperty+0xed>
lea    -0x130(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x13c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1248 <iProperty+0xe8>
mov    -0x138(%rbp),%rdi
movslq -0x13c(%rbp),%rax
add    %rax,%rdi
lea    -0x148(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    124d <iProperty+0xed>
jmp    11c8 <iProperty+0x68>
mov    -0x150(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iProperty>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %ecx,(%rdx)
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
lea    0xe72(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1201 <iProperty+0xa1>
mov    %rax,%r13
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11f5 <iProperty+0x95>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11b0 <iProperty+0x50>
movslq %r12d,%rax
add    %rax,%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,(%r14)
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1206 <iProperty+0xa6>
mov    $0xffffffff,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @iProperty(i8* %0, i8* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca [256 x i8]
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%15 = load i32, i32* %9
%16 = load i32*, i32** %8
store i32 %15, i32* %16
%17 = load i8*, i8** %7
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %12
%19 = load i8*, i8** %6
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %14
%21 = load i32*, i32** %14
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %24
23: ; preds = %4
store i32 -1, i32* %5
br label %49
24: ; preds = %4
br label %25
25: ; preds = %24, %45
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%27 = load i32*, i32** %14
%28 = call i8* @fgets(i8* %26, i32 256, i32* %27)
store i8* %28, i8** %11
%29 = load i8*, i8** %11
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %32
31: ; preds = %25
br label %46
32: ; preds = %25
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%34 = load i8*, i8** %7
%35 = load i32, i32* %12
%36 = call i32 @strncmp(i8* %33, i8* %34, i32 %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %45, label %38
38: ; preds = %32
%39 = load i8*, i8** %11
%40 = load i32, i32* %12
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = call i32 @strtol(i8* %42, i8** %13, i32 10)
%44 = load i32*, i32** %8
store i32 %43, i32* %44
br label %46
45: ; preds = %32
br label %25
46: ; preds = %38, %31
%47 = load i32*, i32** %14
%48 = call i32 @fclose(i32* %47)
store i32 0, i32* %5
br label %49
49: ; preds = %46, %23
%50 = load i32, i32* %5
ret i32 %50
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @iProperty(i8* nocapture %0, i8* %1, i32* nocapture writeonly %2, i32 %3) {
%5 = alloca [256 x i8]
%6 = alloca i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
store i32 %3, i32* %2
%8 = tail call i32 @strlen(i8* %1)
%9 = bitcast i8** %6 to i8*
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %24, label %12
12: ; preds = %4, %15
%13 = call i8* @fgets(i8* %7, i32 256, i32* %10)
%14 = icmp eq i8* %13, null
br i1 %14, label %22, label %15
15: ; preds = %12
%16 = call i32 @strncmp(i8* %7, i8* %1, i32 %8)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %12
18: ; preds = %15
%19 = sext i32 %8 to i64
%20 = getelementptr inbounds i8, i8* %13, i64 %19
%21 = call i32 @strtol(i8* %20, i8** %6, i32 10)
store i32 %21, i32* %2
br label %22
22: ; preds = %12, %18
%23 = call i32 @fclose(i32* %10)
br label %24
24: ; preds = %4, %22
%25 = phi i32 [ 0, %22 ], [ -1, %4 ]
ret i32 %25
}