#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
char *strchr(char *, char);
scalar_t__ strcmp(char const *, char *);
char *strdup(char *);
char *strtok(char *, char *);
char *get_property_value(const char *propfile, const char *key) {
  FILE *f = fopen(propfile, "r");
  char buf[1024];
  char *mkey, *value;
  if (!f)
    return NULL;
  while (fgets(buf, 1024, f) != NULL) {
    if (strchr(buf, '\r'))
      *(strchr(buf, '\r')) = '\0';
    if (strchr(buf, '\n'))
      *(strchr(buf, '\n')) = '\0';
    mkey = strtok(buf, "=");
    if (!mkey)
      continue;
    value = strtok(NULL, "=");
    if (!value)
      continue;
    if (strcmp(key, mkey) == 0) {
      fclose(f);
      return strdup(value);
    }
  }
  fclose(f);
  return NULL;
}


x86 assembly (clang, -O0):
<get_property_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11af <get_property_value+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    12d6 <get_property_value+0x166>
jmp    11b4 <get_property_value+0x44>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12c5 <get_property_value+0x155>
lea    -0x420(%rbp),%rdi
mov    $0xd,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1202 <get_property_value+0x92>
lea    -0x420(%rbp),%rdi
mov    $0xd,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
lea    -0x420(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1231 <get_property_value+0xc1>
lea    -0x420(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
lea    -0x420(%rbp),%rdi
lea    0xdc3(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    125e <get_property_value+0xee>
jmp    11b4 <get_property_value+0x44>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd99(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
jne    1288 <get_property_value+0x118>
jmp    11b4 <get_property_value+0x44>
mov    -0x18(%rbp),%rdi
mov    -0x428(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12c0 <get_property_value+0x150>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x430(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    12d6 <get_property_value+0x166>
jmp    11b4 <get_property_value+0x44>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_property_value>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     125e <get_property_value+0xee>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1256 <get_property_value+0xe6>
mov    %rsp,%r13
lea    0xe43(%rip),%r12
jmp    11e5 <get_property_value+0x75>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1256 <get_property_value+0xe6>
mov    %r13,%rdi
mov    $0xd,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11fa <get_property_value+0x8a>
movb   $0x0,(%rax)
mov    %r13,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     120f <get_property_value+0x9f>
movb   $0x0,(%rax)
mov    %r13,%rdi
mov    %r12,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     11d0 <get_property_value+0x60>
mov    %rax,%rbp
xor    %edi,%edi
mov    %r12,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     11d0 <get_property_value+0x60>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rbp,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11d0 <get_property_value+0x60>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1090 <strdup@plt>
jmp    1260 <get_property_value+0xf0>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"=\00"
define i8* @get_property_value(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i8* null, i8** %3
br label %60
15: ; preds = %2
br label %16
16: ; preds = %56, %45, %40, %15
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%18 = load i32*, i32** %6
%19 = call i32* @fgets(i8* %17, i32 1024, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %57
21: ; preds = %16
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%23 = call i8* @strchr(i8* %22, i8 signext 13)
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%27 = call i8* @strchr(i8* %26, i8 signext 13)
store i8 0, i8* %27
br label %28
28: ; preds = %25, %21
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%30 = call i8* @strchr(i8* %29, i8 signext 10)
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%34 = call i8* @strchr(i8* %33, i8 signext 10)
store i8 0, i8* %34
br label %35
35: ; preds = %32, %28
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%37 = call i8* @strtok(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %37, i8** %8
%38 = load i8*, i8** %8
%39 = icmp ne i8* %38, null
br i1 %39, label %41, label %40
40: ; preds = %35
br label %16
41: ; preds = %35
%42 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %42, i8** %9
%43 = load i8*, i8** %9
%44 = icmp ne i8* %43, null
br i1 %44, label %46, label %45
45: ; preds = %41
br label %16
46: ; preds = %41
%47 = load i8*, i8** %5
%48 = load i8*, i8** %8
%49 = call i64 @strcmp(i8* %47, i8* %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %46
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
%54 = load i8*, i8** %9
%55 = call i8* @strdup(i8* %54)
store i8* %55, i8** %3
br label %60
56: ; preds = %46
br label %16
57: ; preds = %16
%58 = load i32*, i32** %6
%59 = call i32 @fclose(i32* %58)
store i8* null, i8** %3
br label %60
60: ; preds = %57, %51, %14
%61 = load i8*, i8** %3
ret i8* %61
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"=\00"
define noalias i8* @get_property_value(i8* nocapture %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = icmp eq i32* %4, null
br i1 %6, label %35, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %5, i32 1024, i32* %4)
%9 = icmp eq i32* %8, null
br i1 %9, label %33, label %10
10: ; preds = %7, %21
%11 = call i8* @strchr(i8* %5, i8 signext 13)
%12 = icmp eq i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10
store i8 0, i8* %11
br label %14
14: ; preds = %13, %10
%15 = call i8* @strchr(i8* %5, i8 signext 10)
%16 = icmp eq i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %14
store i8 0, i8* %15
br label %18
18: ; preds = %17, %14
%19 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18, %24, %27
%22 = call i32* @fgets(i8* %5, i32 1024, i32* %4)
%23 = icmp eq i32* %22, null
br i1 %23, label %33, label %10
24: ; preds = %18
%25 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %21, label %27
27: ; preds = %24
%28 = call i64 @strcmp(i8* %1, i8* %19)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %21
30: ; preds = %27
%31 = call i32 @fclose(i32* %4)
%32 = call i8* @strdup(i8* %25)
br label %35
33: ; preds = %21, %7
%34 = call i32 @fclose(i32* %4)
br label %35
35: ; preds = %2, %33, %30
%36 = phi i8* [ %32, %30 ], [ null, %33 ], [ null, %2 ]
ret i8* %36
}