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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *strstr(char *, char *);
int get_conf_value(char *file_path, char *key_name, char *value) {
  FILE *fp = NULL;
  char *line = NULL, *substr = NULL;
  size_t len = 0, tlen = 0;
  ssize_t read = 0;
  if (file_path == NULL || key_name == NULL || value == NULL) {
    printf("paramer is invaild!\n");
    return -1;
  }
  fp = fopen(file_path, "r");
  if (fp == NULL) {
    printf("open config file is error!\n");
    return -1;
  }
  while ((read = getline(&line, &len, fp)) != -1) {
    substr = strstr(line, key_name);
    if (substr == NULL) {
      continue;
    } else {
      tlen = strlen(key_name);
      if (line[tlen] == '=') {
        strncpy(value, &line[tlen + 1], len - tlen + 1);
        printf("config file format is invaild tlen is %d len is %d\n", tlen,
               len);
        tlen = strlen(value);
        printf("get value is %s tlen is %d\n", value, tlen);
        *(value + tlen - 1) = '\0';
        break;
      } else {
        printf("config file format is invaild tlen is %d len is %d\n", tlen,
               len);
        fclose(fp);
        return -2;
      }
    }
  }
  if (substr == NULL) {
    printf("key: %s is not in config file!\n", key_name);
    fclose(fp);
    return -1;
  }
  free(line);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<get_conf_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e4 <get_conf_value+0x64>
cmpq   $0x0,-0x18(%rbp)
je     11e4 <get_conf_value+0x64>
cmpq   $0x0,-0x20(%rbp)
jne    11fe <get_conf_value+0x7e>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1381 <get_conf_value+0x201>
mov    -0x10(%rbp),%rdi
lea    0xe0c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1237 <get_conf_value+0xb7>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1381 <get_conf_value+0x201>
jmp    123c <get_conf_value+0xbc>
mov    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0xffffffff,%eax
je     1336 <get_conf_value+0x1b6>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    127a <get_conf_value+0xfa>
jmp    123c <get_conf_value+0xbc>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x48(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    130b <get_conf_value+0x18b>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x48(%rbp),%rax
add    $0x1,%rax
add    %rax,%rsi
mov    -0x40(%rbp),%rdx
sub    -0x48(%rbp),%rdx
add    $0x1,%rdx
call   1040 <strncpy@plt>
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdx
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x48(%rbp),%rdx
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rax
mov    -0x48(%rbp),%rcx
movb   $0x0,-0x1(%rax,%rcx,1)
jmp    1336 <get_conf_value+0x1b6>
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdx
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1381 <get_conf_value+0x201>
cmpq   $0x0,-0x38(%rbp)
jne    1368 <get_conf_value+0x1e8>
mov    -0x18(%rbp),%rsi
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1381 <get_conf_value+0x201>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_conf_value>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
test   %rdi,%rdi
je     12af <get_conf_value+0x11f>
mov    %rsi,%rbx
test   %rsi,%rsi
je     12af <get_conf_value+0x11f>
mov    %rdx,%r14
test   %rdx,%rdx
je     12af <get_conf_value+0x11f>
lea    0xe28(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12b8 <get_conf_value+0x128>
mov    %rax,%r15
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   10a0 <getline@plt>
cmp    $0xffffffff,%eax
je     12da <get_conf_value+0x14a>
mov    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     1200 <get_conf_value+0x70>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rax,%r12
cmpb   $0x3d,0x0(%rbp,%rax,1)
jne    12f5 <get_conf_value+0x165>
lea    (%r12,%rbp,1),%rsi
add    $0x1,%rsi
mov    0x8(%rsp),%rdx
sub    %r12,%rdx
add    $0x1,%rdx
mov    %r14,%rdi
call   1040 <strncpy@plt>
mov    0x8(%rsp),%rdx
lea    0xd98(%rip),%rdi
xor    %ebx,%ebx
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %rax,%rbp
lea    0xdae(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
movb   $0x0,-0x1(%r14,%rbp,1)
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
jmp    12c9 <get_conf_value+0x139>
lea    0xdd7(%rip),%rdi
jmp    12bf <get_conf_value+0x12f>
lea    0xdb3(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd71(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
jmp    12c4 <get_conf_value+0x134>
mov    0x8(%rsp),%rdx
lea    0xd01(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    $0xfffffffe,%ebx
jmp    12c9 <get_conf_value+0x139>

LLVM IR (-O0):
@.str = [21 x i8] c"paramer is invaild!\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"open config file is error!\0A\00"
@.str.3 = [52 x i8] c"config file format is invaild tlen is %d len is %d\0A\00"
@.str.4 = [28 x i8] c"get value is %s tlen is %d\0A\00"
@.str.5 = [32 x i8] c"key: %s is not in config file!\0A\00"
define i32 @get_conf_value(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32* null, i32** %8
store i8* null, i8** %9
store i8* null, i8** %10
store i64 0, i64* %11
store i64 0, i64* %12
store i32 0, i32* %13
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %22, label %16
16: ; preds = %3
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i8*, i8** %7
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19, %16, %3
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %94
24: ; preds = %19
%25 = load i8*, i8** %5
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %8
%27 = load i32*, i32** %8
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %94
31: ; preds = %24
br label %32
32: ; preds = %42, %31
%33 = load i32*, i32** %8
%34 = call i32 @getline(i8** %9, i64* %11, i32* %33)
store i32 %34, i32* %13
%35 = icmp ne i32 %34, -1
br i1 %35, label %36, label %81
36: ; preds = %32
%37 = load i8*, i8** %9
%38 = load i8*, i8** %6
%39 = call i8* @strstr(i8* %37, i8* %38)
store i8* %39, i8** %10
%40 = load i8*, i8** %10
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %43
42: ; preds = %36
br label %32
43: ; preds = %36
%44 = load i8*, i8** %6
%45 = call i64 @strlen(i8* %44)
store i64 %45, i64* %12
%46 = load i8*, i8** %9
%47 = load i64, i64* %12
%48 = getelementptr inbounds i8, i8* %46, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 61
br i1 %51, label %52, label %75
52: ; preds = %43
%53 = load i8*, i8** %7
%54 = load i8*, i8** %9
%55 = load i64, i64* %12
%56 = add i64 %55, 1
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i64, i64* %11
%59 = load i64, i64* %12
%60 = sub i64 %58, %59
%61 = add i64 %60, 1
%62 = call i32 @strncpy(i8* %53, i8* %57, i64 %61)
%63 = load i64, i64* %12
%64 = load i64, i64* %11
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i64 %63, i64 %64)
%66 = load i8*, i8** %7
%67 = call i64 @strlen(i8* %66)
store i64 %67, i64* %12
%68 = load i8*, i8** %7
%69 = load i64, i64* %12
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %68, i64 %69)
%71 = load i8*, i8** %7
%72 = load i64, i64* %12
%73 = getelementptr inbounds i8, i8* %71, i64 %72
%74 = getelementptr inbounds i8, i8* %73, i64 -1
store i8 0, i8* %74
br label %81
75: ; preds = %43
%76 = load i64, i64* %12
%77 = load i64, i64* %11
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i64 %76, i64 %77)
%79 = load i32*, i32** %8
%80 = call i32 @fclose(i32* %79)
store i32 -2, i32* %4
br label %94
81: ; preds = %52, %32
%82 = load i8*, i8** %10
%83 = icmp eq i8* %82, null
br i1 %83, label %84, label %89
84: ; preds = %81
%85 = load i8*, i8** %6
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %85)
%87 = load i32*, i32** %8
%88 = call i32 @fclose(i32* %87)
store i32 -1, i32* %4
br label %94
89: ; preds = %81
%90 = load i8*, i8** %9
%91 = call i32 @free(i8* %90)
%92 = load i32*, i32** %8
%93 = call i32 @fclose(i32* %92)
store i32 0, i32* %4
br label %94
94: ; preds = %89, %84, %75, %29, %22
%95 = load i32, i32* %4
ret i32 %95
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [52 x i8] c"config file format is invaild tlen is %d len is %d\0A\00"
@.str.4 = [28 x i8] c"get value is %s tlen is %d\0A\00"
@.str.5 = [32 x i8] c"key: %s is not in config file!\0A\00"
@str = [27 x i8] c"open config file is error!\00"
@str.6 = [20 x i8] c"paramer is invaild!\00"
define i32 @get_conf_value(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%8 = icmp eq i8* %0, null
%9 = icmp eq i8* %1, null
%10 = or i1 %8, %9
%11 = icmp eq i8* %2, null
%12 = or i1 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.6, i64 0, i64 0))
br label %55
15: ; preds = %3
%16 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %55
20: ; preds = %15, %23
%21 = call i32 @getline(i8** %4, i64* %5, i32* %16)
%22 = icmp eq i32 %21, -1
br i1 %22, label %36, label %23
23: ; preds = %20
%24 = load i8*, i8** %4
%25 = call i8* @strstr(i8* dereferenceable(1) %24, i8* dereferenceable(1) %1)
%26 = icmp eq i8* %25, null
br i1 %26, label %20, label %27
27: ; preds = %23
%28 = call i64 @strlen(i8* dereferenceable(1) %1)
%29 = getelementptr inbounds i8, i8* %24, i64 %28
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 61
br i1 %31, label %39, label %32
32: ; preds = %27
%33 = load i64, i64* %5
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i64 %28, i64 %33)
%35 = call i32 @fclose(i32* %16)
br label %55
36: ; preds = %20
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %1)
%38 = call i32 @fclose(i32* %16)
br label %55
39: ; preds = %27
%40 = add i64 %28, 1
%41 = getelementptr inbounds i8, i8* %24, i64 %40
%42 = load i64, i64* %5
%43 = sub i64 1, %28
%44 = add i64 %43, %42
%45 = call i32 @strncpy(i8* %2, i8* %41, i64 %44)
%46 = load i64, i64* %5
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i64 %28, i64 %46)
%48 = call i64 @strlen(i8* dereferenceable(1) %2)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %2, i64 %48)
%50 = getelementptr inbounds i8, i8* %2, i64 %48
%51 = getelementptr inbounds i8, i8* %50, i64 -1
store i8 0, i8* %51
%52 = load i8*, i8** %4
%53 = call i32 @free(i8* %52)
%54 = call i32 @fclose(i32* %16)
br label %55
55: ; preds = %39, %36, %32, %18, %13
%56 = phi i32 [ -1, %13 ], [ -1, %18 ], [ -1, %36 ], [ 0, %39 ], [ -2, %32 ]
ret i32 %56
}