#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
scalar_t__ strncmp(char *, char const *, int);
void getProperty(const char *propertiesFilename, const char *propertyName,
                 char *propertyValue, int maxValueLength) {
  FILE *propertiesFile = fopen(propertiesFilename, "r");
  if (propertiesFile == NULL) {
    *propertyValue = (char)0;
    return;
  }
  char line[256];
  while (fgets(line, sizeof(line), propertiesFile) != NULL) {
    if ('\n' != line[strlen(line) - 1]) {
      errno = EINVAL;
      return;
    }
    if (line[0] == '#' || line[0] == '\n')
      continue;
    int l = strlen(propertyName);
    if (strncmp(line, propertyName, l) == 0 && line[l] == '=') {
      l++;
      char *value = &line[l], *nl = strchr(value, '\n');
      if (nl != NULL)
        *nl = (char)0;
      if (maxValueLength < 1 + strlen(value)) {
        errno = EINVAL;
        return;
      }
      strcpy(propertyValue, value);
      return;
    }
  }
  *propertyValue = (char)0;
  errno = EINVAL;
}


x86 assembly (clang, -O0):
<getProperty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a5 <getProperty+0x45>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    133b <getProperty+0x1db>
jmp    11aa <getProperty+0x4a>
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x100,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1322 <getProperty+0x1c2>
lea    -0x130(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x130(%rbp,%rax,1),%ecx
ff
mov    $0xa,%eax
cmp    %ecx,%eax
je     1206 <getProperty+0xa6>
mov    0x2de2(%rip),%rax
mov    (%rax),%ecx
mov    0x2de1(%rip),%rax
mov    %ecx,(%rax)
jmp    133b <getProperty+0x1db>
movsbl -0x130(%rbp),%eax
cmp    $0x23,%eax
je     1226 <getProperty+0xc6>
movsbl -0x130(%rbp),%eax
cmp    $0xa,%eax
jne    122b <getProperty+0xcb>
jmp    11aa <getProperty+0x4a>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x134(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x134(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    131d <getProperty+0x1bd>
movslq -0x134(%rbp),%rax
movsbl -0x130(%rbp,%rax,1),%eax
ff
cmp    $0x3d,%eax
jne    131d <getProperty+0x1bd>
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
movslq -0x134(%rbp),%rcx
lea    -0x130(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x140(%rbp)
mov    -0x140(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x148(%rbp)
cmpq   $0x0,-0x148(%rbp)
je     12c9 <getProperty+0x169>
mov    -0x148(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14c(%rbp)
mov    -0x140(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x14c(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1308 <getProperty+0x1a8>
mov    0x2ce0(%rip),%rax
mov    (%rax),%ecx
mov    0x2cdf(%rip),%rax
mov    %ecx,(%rax)
jmp    133b <getProperty+0x1db>
mov    -0x18(%rbp),%rdi
mov    -0x140(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    133b <getProperty+0x1db>
jmp    11aa <getProperty+0x4a>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    0x2ca8(%rip),%rax
mov    (%rax),%ecx
mov    0x2ca7(%rip),%rax
mov    %ecx,(%rax)
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getProperty>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r12
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1246 <getProperty+0xe6>
mov    %rax,%r13
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     122e <getProperty+0xce>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbp,1)
jne    1232 <getProperty+0xd2>
movzbl (%rsp),%eax
cmp    $0x23,%al
je     11a0 <getProperty+0x40>
cmp    $0xa,%al
je     11a0 <getProperty+0x40>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11a0 <getProperty+0x40>
movslq %ebx,%rax
cmpb   $0x3d,(%rsp,%rax,1)
jne    11a0 <getProperty+0x40>
lea    (%rax,%rbp,1),%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1214 <getProperty+0xb4>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    %r14d,%eax
jge    1232 <getProperty+0xd2>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
jmp    124a <getProperty+0xea>
movb   $0x0,(%r15)
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    0x2d9e(%rip),%rcx
mov    %eax,(%rcx)
jmp    124a <getProperty+0xea>
movb   $0x0,(%r15)
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EINVAL = global i32 0
@errno = global i32 0
define void @getProperty(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca [256 x i8]
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %9
%16 = load i32*, i32** %9
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = load i8*, i8** %7
store i8 0, i8* %19
br label %91
20: ; preds = %4
br label %21
21: ; preds = %87, %47, %20
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%23 = load i32*, i32** %9
%24 = call i32* @fgets(i8* %22, i32 256, i32* %23)
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %88
26: ; preds = %21
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 10, %33
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = load i32, i32* @EINVAL
store i32 %36, i32* @errno
br label %91
37: ; preds = %26
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 35
br i1 %41, label %47, label %42
42: ; preds = %37
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 10
br i1 %46, label %47, label %48
47: ; preds = %42, %37
br label %21
48: ; preds = %42
%49 = load i8*, i8** %6
%50 = call i32 @strlen(i8* %49)
store i32 %50, i32* %11
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%52 = load i8*, i8** %6
%53 = load i32, i32* %11
%54 = call i64 @strncmp(i8* %51, i8* %52, i32 %53)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %87
56: ; preds = %48
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 61
br i1 %62, label %63, label %87
63: ; preds = %56
%64 = load i32, i32* %11
%65 = add nsw i32 %64, 1
store i32 %65, i32* %11
%66 = load i32, i32* %11
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %67
store i8* %68, i8** %12
%69 = load i8*, i8** %12
%70 = call i8* @strchr(i8* %69, i8 signext 10)
store i8* %70, i8** %13
%71 = load i8*, i8** %13
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %75
73: ; preds = %63
%74 = load i8*, i8** %13
store i8 0, i8* %74
br label %75
75: ; preds = %73, %63
%76 = load i32, i32* %8
%77 = load i8*, i8** %12
%78 = call i32 @strlen(i8* %77)
%79 = add nsw i32 1, %78
%80 = icmp slt i32 %76, %79
br i1 %80, label %81, label %83
81: ; preds = %75
%82 = load i32, i32* @EINVAL
store i32 %82, i32* @errno
br label %91
83: ; preds = %75
%84 = load i8*, i8** %7
%85 = load i8*, i8** %12
%86 = call i32 @strcpy(i8* %84, i8* %85)
br label %91
87: ; preds = %56, %48
br label %21
88: ; preds = %21
%89 = load i8*, i8** %7
store i8 0, i8* %89
%90 = load i32, i32* @EINVAL
store i32 %90, i32* @errno
br label %91
91: ; preds = %88, %83, %81, %35, %18
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EINVAL = global i32 0
@errno = global i32 0
define void @getProperty(i8* nocapture %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [256 x i8]
%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 %8, label %9
8: ; preds = %4
store i8 0, i8* %2
br label %53
9: ; preds = %4
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%11 = call i32* @fgets(i8* %10, i32 256, i32* %6)
%12 = icmp eq i32* %11, null
br i1 %12, label %50, label %13
13: ; preds = %9, %24
%14 = call i32 @strlen(i8* %10)
%15 = add nsw i32 %14, -1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 10
br i1 %19, label %22, label %20
20: ; preds = %13
%21 = load i32, i32* @EINVAL
store i32 %21, i32* @errno
br label %52
22: ; preds = %13
%23 = load i8, i8* %10
switch i8 %23, label %27 [
i8 35, label %24
i8 10, label %24
]
24: ; preds = %31, %27, %22, %22
%25 = call i32* @fgets(i8* %10, i32 256, i32* %6)
%26 = icmp eq i32* %25, null
br i1 %26, label %50, label %13
27: ; preds = %22
%28 = call i32 @strlen(i8* %1)
%29 = call i64 @strncmp(i8* %10, i8* %1, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %24
31: ; preds = %27
%32 = sext i32 %28 to i64
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 61
br i1 %35, label %36, label %24
36: ; preds = %31
%37 = add nsw i32 %28, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %38
%40 = call i8* @strchr(i8* %39, i8 signext 10)
%41 = icmp eq i8* %40, null
br i1 %41, label %43, label %42
42: ; preds = %36
store i8 0, i8* %40
br label %43
43: ; preds = %42, %36
%44 = call i32 @strlen(i8* %39)
%45 = icmp slt i32 %44, %3
br i1 %45, label %48, label %46
46: ; preds = %43
%47 = load i32, i32* @EINVAL
store i32 %47, i32* @errno
br label %52
48: ; preds = %43
%49 = call i32 @strcpy(i8* %2, i8* %39)
br label %52
50: ; preds = %24, %9
store i8 0, i8* %2
%51 = load i32, i32* @EINVAL
store i32 %51, i32* @errno
br label %52
52: ; preds = %46, %48, %50, %20
br label %53
53: ; preds = %52, %8
ret void
}