#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 *, char *);
char *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *trim(char *, char *);
int get_value(char *strFileName, char *strSec, char *strKey, char *strValue) {
  FILE *fp = NULL;
  char strBuf[4096 + 1] = "\0";
  char strTmpSec[4096] = "\0";
  char strTmpBuf[4096] = "\0";
  char *p, *pEq;
  int iFound = -1;
  fp = fopen(strFileName, "rb");
  if (NULL == fp) {
    return -1;
  }
  while (0 != iFound && NULL != fgets(strBuf, 4096, fp)) {
    p = strchr(strBuf, '\n');
    if (NULL != p) {
      *p = '\0';
    }
    p = strchr(strBuf, '#');
    if (NULL != p) {
      *p = '\0';
    }
    p = trim(strBuf, strTmpBuf);
    if ('[' == *p && ']' == *(p + strlen(p) - 1)) {
      *(p + strlen(p) - 1) = '\0';
      strcpy(strTmpSec, p + 1);
      continue;
    }
    pEq = strchr(p, '=');
    if (NULL != pEq) {
      *pEq = '\0';
      trim(p, strTmpBuf);
      if (strcmp(strKey, strTmpBuf) == 0 && strcmp(strSec, strTmpSec) == 0) {
        trim(pEq + 1, strTmpBuf);
        strcpy(strValue, strTmpBuf);
        iFound = 0;
      }
    }
  }
  fclose(fp);
  return iFound;
}


x86 assembly (clang, -O0):
<get_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3070,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    -0x1040(%rbp),%rdi
xor    %esi,%esi
mov    $0x1001,%edx
call   1080 <memset@plt>
lea    -0x2040(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1080 <memset@plt>
lea    -0x3040(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1080 <memset@plt>
movl   $0xffffffff,-0x3054(%rbp)
ff ff ff
mov    -0x10(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    1222 <get_value+0x92>
movl   $0xffffffff,-0x4(%rbp)
jmp    144d <get_value+0x2bd>
jmp    1227 <get_value+0x97>
xor    %eax,%eax
xor    %ecx,%ecx
cmp    -0x3054(%rbp),%ecx
mov    %al,-0x3055(%rbp)
je     1263 <get_value+0xd3>
lea    -0x1040(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x1000,%esi
call   1090 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
setne  %al
mov    %al,-0x3055(%rbp)
mov    -0x3055(%rbp),%al
test   $0x1,%al
jne    1276 <get_value+0xe6>
jmp    143b <get_value+0x2ab>
lea    -0x1040(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x3048(%rbp)
xor    %eax,%eax
cmp    -0x3048(%rbp),%rax
je     12a7 <get_value+0x117>
mov    -0x3048(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x1040(%rbp),%rdi
mov    $0x23,%esi
call   1060 <strchr@plt>
mov    %rax,-0x3048(%rbp)
xor    %eax,%eax
cmp    -0x3048(%rbp),%rax
je     12d8 <get_value+0x148>
mov    -0x3048(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x1040(%rbp),%rdi
lea    -0x3040(%rbp),%rsi
call   1070 <trim@plt>
mov    %rax,-0x3048(%rbp)
mov    -0x3048(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x5b,%eax
cmp    %ecx,%eax
jne    1388 <get_value+0x1f8>
mov    -0x3048(%rbp),%rax
mov    %rax,-0x3060(%rbp)
mov    -0x3048(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x3060(%rbp),%rax
movslq %ecx,%rcx
movsbl -0x1(%rax,%rcx,1),%ecx
mov    $0x5d,%eax
cmp    %ecx,%eax
jne    1388 <get_value+0x1f8>
mov    -0x3048(%rbp),%rax
mov    %rax,-0x3068(%rbp)
mov    -0x3048(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x3068(%rbp),%rax
movslq %ecx,%rcx
movb   $0x0,-0x1(%rax,%rcx,1)
lea    -0x2040(%rbp),%rdi
mov    -0x3048(%rbp),%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
jmp    1227 <get_value+0x97>
mov    -0x3048(%rbp),%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
mov    %rax,-0x3050(%rbp)
xor    %eax,%eax
cmp    -0x3050(%rbp),%rax
je     1436 <get_value+0x2a6>
mov    -0x3050(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x3048(%rbp),%rdi
lea    -0x3040(%rbp),%rsi
call   1070 <trim@plt>
mov    -0x20(%rbp),%rdi
lea    -0x3040(%rbp),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1431 <get_value+0x2a1>
mov    -0x18(%rbp),%rdi
lea    -0x2040(%rbp),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1431 <get_value+0x2a1>
mov    -0x3050(%rbp),%rdi
add    $0x1,%rdi
lea    -0x3040(%rbp),%rsi
call   1070 <trim@plt>
mov    -0x28(%rbp),%rdi
lea    -0x3040(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x3054(%rbp)
jmp    1436 <get_value+0x2a6>
jmp    1227 <get_value+0x97>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x3054(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x3070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_value>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3018,%rsp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,0x8(%rsp)
mov    %rdi,%rbx
lea    0x2010(%rsp),%rdi
mov    $0x1001,%edx
xor    %esi,%esi
call   1080 <memset@plt>
lea    0x1010(%rsp),%rdi
mov    $0x1000,%edx
xor    %esi,%esi
call   1080 <memset@plt>
lea    0x10(%rsp),%rdi
mov    $0x1000,%edx
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xe11(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1346 <get_value+0x1b6>
mov    %rax,%rbx
lea    0x2010(%rsp),%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1352 <get_value+0x1c2>
mov    %r14,(%rsp)
lea    0x2010(%rsp),%rbp
lea    0x10(%rsp),%r14
jmp    127d <get_value+0xed>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%r15,%rax,1)
add    $0x1,%r15
lea    0x1010(%rsp),%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     134d <get_value+0x1bd>
mov    %rbp,%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1292 <get_value+0x102>
movb   $0x0,(%rax)
mov    %rbp,%rdi
mov    $0x23,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     12a7 <get_value+0x117>
movb   $0x0,(%rax)
mov    %rbp,%rdi
mov    %r14,%rsi
call   1070 <trim@plt>
mov    %rax,%r15
cmpb   $0x5b,(%rax)
jne    12d0 <get_value+0x140>
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0x5d,-0x1(%r15,%rax,1)
je     1240 <get_value+0xb0>
mov    %r15,%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1264 <get_value+0xd4>
mov    %rax,%r13
movb   $0x0,(%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <trim@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    1264 <get_value+0xd4>
mov    0x8(%rsp),%rdi
lea    0x1010(%rsp),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    1264 <get_value+0xd4>
add    $0x1,%r13
lea    0x10(%rsp),%rbp
mov    %r13,%rdi
mov    %rbp,%rsi
call   1070 <trim@plt>
mov    (%rsp),%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
xor    %ebp,%ebp
jmp    1352 <get_value+0x1c2>
mov    $0xffffffff,%ebp
jmp    135a <get_value+0x1ca>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x3018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i32 @get_value(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca [4097 x i8]
%12 = alloca [4096 x i8]
%13 = alloca [4096 x i8]
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32* null, i32** %10
%17 = bitcast [4097 x i8]* %11 to i8*
%18 = bitcast [4096 x i8]* %12 to i8*
%19 = bitcast [4096 x i8]* %13 to i8*
store i32 -1, i32* %16
%20 = load i8*, i8** %6
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %10
%22 = load i32*, i32** %10
%23 = icmp eq i32* null, %22
br i1 %23, label %24, label %25
24: ; preds = %4
store i32 -1, i32* %5
br label %112
25: ; preds = %4
br label %26
26: ; preds = %107, %68, %25
%27 = load i32, i32* %16
%28 = icmp ne i32 0, %27
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = getelementptr inbounds [4097 x i8], [4097 x i8]* %11, i64 0, i64 0
%31 = load i32*, i32** %10
%32 = call i32* @fgets(i8* %30, i32 4096, i32* %31)
%33 = icmp ne i32* null, %32
br label %34
34: ; preds = %29, %26
%35 = phi i1 [ false, %26 ], [ %33, %29 ]
br i1 %35, label %36, label %108
36: ; preds = %34
%37 = getelementptr inbounds [4097 x i8], [4097 x i8]* %11, i64 0, i64 0
%38 = call i8* @strchr(i8* %37, i8 signext 10)
store i8* %38, i8** %14
%39 = load i8*, i8** %14
%40 = icmp ne i8* null, %39
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = load i8*, i8** %14
store i8 0, i8* %42
br label %43
43: ; preds = %41, %36
%44 = getelementptr inbounds [4097 x i8], [4097 x i8]* %11, i64 0, i64 0
%45 = call i8* @strchr(i8* %44, i8 signext 35)
store i8* %45, i8** %14
%46 = load i8*, i8** %14
%47 = icmp ne i8* null, %46
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = load i8*, i8** %14
store i8 0, i8* %49
br label %50
50: ; preds = %48, %43
%51 = getelementptr inbounds [4097 x i8], [4097 x i8]* %11, i64 0, i64 0
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%53 = call i8* @trim(i8* %51, i8* %52)
store i8* %53, i8** %14
%54 = load i8*, i8** %14
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 91, %56
br i1 %57, label %58, label %79
58: ; preds = %50
%59 = load i8*, i8** %14
%60 = load i8*, i8** %14
%61 = call i32 @strlen(i8* %60)
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %59, i64 %62
%64 = getelementptr inbounds i8, i8* %63, i64 -1
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp eq i32 93, %66
br i1 %67, label %68, label %79
68: ; preds = %58
%69 = load i8*, i8** %14
%70 = load i8*, i8** %14
%71 = call i32 @strlen(i8* %70)
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %69, i64 %72
%74 = getelementptr inbounds i8, i8* %73, i64 -1
store i8 0, i8* %74
%75 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%76 = load i8*, i8** %14
%77 = getelementptr inbounds i8, i8* %76, i64 1
%78 = call i32 @strcpy(i8* %75, i8* %77)
br label %26
79: ; preds = %58, %50
%80 = load i8*, i8** %14
%81 = call i8* @strchr(i8* %80, i8 signext 61)
store i8* %81, i8** %15
%82 = load i8*, i8** %15
%83 = icmp ne i8* null, %82
br i1 %83, label %84, label %107
84: ; preds = %79
%85 = load i8*, i8** %15
store i8 0, i8* %85
%86 = load i8*, i8** %14
%87 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%88 = call i8* @trim(i8* %86, i8* %87)
%89 = load i8*, i8** %8
%90 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%91 = call i64 @strcmp(i8* %89, i8* %90)
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %106
93: ; preds = %84
%94 = load i8*, i8** %7
%95 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%96 = call i64 @strcmp(i8* %94, i8* %95)
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %106
98: ; preds = %93
%99 = load i8*, i8** %15
%100 = getelementptr inbounds i8, i8* %99, i64 1
%101 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%102 = call i8* @trim(i8* %100, i8* %101)
%103 = load i8*, i8** %9
%104 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%105 = call i32 @strcpy(i8* %103, i8* %104)
store i32 0, i32* %16
br label %106
106: ; preds = %98, %93, %84
br label %107
107: ; preds = %106, %79
br label %26
108: ; preds = %34
%109 = load i32*, i32** %10
%110 = call i32 @fclose(i32* %109)
%111 = load i32, i32* %16
store i32 %111, i32* %5
br label %112
112: ; preds = %108, %24
%113 = load i32, i32* %5
ret i32 %113
}

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