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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strstr(char *, char *);
int /*<<< orphan*/ trim_str(char *);
int read_ini_config(char *file_name, char *conf_zone, char *conf_name,
                    char *conf_value) {
  FILE *ini_file = fopen(file_name, "r");
  if (ini_file == NULL) {
    return -1;
  }
  char buff[256];
  int tag = 0;
  while (fgets(buff, sizeof(buff), ini_file)) {
    if (strstr(buff, "[") && strstr(buff, conf_zone)) {
      tag = 1;
      break;
    }
  }
  if (tag == 0) {
    fclose(ini_file);
    return -1;
  }
  while ((fgets(buff, sizeof(buff), ini_file))) {
    if (strstr(buff, conf_name)) {
      tag = 1;
      break;
    }
  }
  if (tag == 0) {
    fclose(ini_file);
    return -1;
  }
  char *ptr = strstr(buff, "=");
  ptr++;
  strcpy(conf_value, ptr);
  trim_str(conf_value);
  fclose(ini_file);
  return 0;
}


x86 assembly (clang, -O0):
<read_ini_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a6 <read_ini_config+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <read_ini_config+0x1a5>
movl   $0x0,-0x134(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     121a <read_ini_config+0xba>
lea    -0x130(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1215 <read_ini_config+0xb5>
lea    -0x130(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1215 <read_ini_config+0xb5>
movl   $0x1,-0x134(%rbp)
jmp    121a <read_ini_config+0xba>
jmp    11b0 <read_ini_config+0x50>
cmpl   $0x0,-0x134(%rbp)
jne    123c <read_ini_config+0xdc>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <read_ini_config+0x1a5>
jmp    1241 <read_ini_config+0xe1>
lea    -0x130(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     128e <read_ini_config+0x12e>
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1289 <read_ini_config+0x129>
movl   $0x1,-0x134(%rbp)
jmp    128e <read_ini_config+0x12e>
jmp    1241 <read_ini_config+0xe1>
cmpl   $0x0,-0x134(%rbp)
jne    12b0 <read_ini_config+0x150>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <read_ini_config+0x1a5>
lea    -0x130(%rbp),%rdi
lea    0xd46(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x140(%rbp)
mov    -0x140(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x140(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x140(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
call   1060 <trim_str@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_ini_config>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
lea    0xe6f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1263 <read_ini_config+0xf3>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    $0xffffffff,%r13d
test   %rax,%rax
je     1259 <read_ini_config+0xe9>
mov    %rsp,%rbp
jmp    11e5 <read_ini_config+0x75>
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1259 <read_ini_config+0xe9>
mov    %rbp,%rdi
mov    $0x5b,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11d0 <read_ini_config+0x60>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11d0 <read_ini_config+0x60>
mov    %rsp,%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1235 <read_ini_config+0xc5>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     1210 <read_ini_config+0xa0>
mov    %rsp,%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1070 <trim_str@plt>
xor    %r13d,%r13d
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1269 <read_ini_config+0xf9>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
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"
@.str.1 = [2 x i8] c"[\00"
@.str.2 = [2 x i8] c"=\00"
define i32 @read_ini_config(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 [256 x i8]
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%14 = load i8*, i8** %6
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %10
%16 = load i32*, i32** %10
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 -1, i32* %5
br label %73
19: ; preds = %4
store i32 0, i32* %12
br label %20
20: ; preds = %35, %19
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%22 = load i32*, i32** %10
%23 = call i64 @fgets(i8* %21, i32 256, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %36
25: ; preds = %20
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%27 = call i8* @strstr(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%31 = load i8*, i8** %7
%32 = call i8* @strstr(i8* %30, i8* %31)
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %35
34: ; preds = %29
store i32 1, i32* %12
br label %36
35: ; preds = %29, %25
br label %20
36: ; preds = %34, %20
%37 = load i32, i32* %12
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32*, i32** %10
%41 = call i32 @fclose(i32* %40)
store i32 -1, i32* %5
br label %73
42: ; preds = %36
br label %43
43: ; preds = %54, %42
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%45 = load i32*, i32** %10
%46 = call i64 @fgets(i8* %44, i32 256, i32* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %55
48: ; preds = %43
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%50 = load i8*, i8** %8
%51 = call i8* @strstr(i8* %49, i8* %50)
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %54
53: ; preds = %48
store i32 1, i32* %12
br label %55
54: ; preds = %48
br label %43
55: ; preds = %53, %43
%56 = load i32, i32* %12
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32*, i32** %10
%60 = call i32 @fclose(i32* %59)
store i32 -1, i32* %5
br label %73
61: ; preds = %55
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%63 = call i8* @strstr(i8* %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %63, i8** %13
%64 = load i8*, i8** %13
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %13
%66 = load i8*, i8** %9
%67 = load i8*, i8** %13
%68 = call i32 @strcpy(i8* %66, i8* %67)
%69 = load i8*, i8** %9
%70 = call i32 @trim_str(i8* %69)
%71 = load i32*, i32** %10
%72 = call i32 @fclose(i32* %71)
store i32 0, i32* %5
br label %73
73: ; preds = %61, %58, %39, %18
%74 = load i32, i32* %5
ret i32 %74
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @read_ini_config(i8* nocapture %0, i8* nocapture %1, i8* nocapture %2, i8* %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 %35, label %8
8: ; preds = %4
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = call i64 @fgets(i8* %9, i32 256, i32* %6)
%11 = icmp eq i64 %10, 0
br i1 %11, label %32, label %12
12: ; preds = %8, %18
%13 = call i8* @strchr(i8* %9, i32 91)
%14 = icmp eq i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = call i8* @strstr(i8* %9, i8* dereferenceable(1) %1)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %15, %12
%19 = call i64 @fgets(i8* %9, i32 256, i32* %6)
%20 = icmp eq i64 %19, 0
br i1 %20, label %32, label %12
21: ; preds = %15, %24
%22 = call i64 @fgets(i8* %9, i32 256, i32* %6)
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = call i8* @strstr(i8* %9, i8* dereferenceable(1) %2)
%26 = icmp eq i8* %25, null
br i1 %26, label %21, label %27
27: ; preds = %21, %24
%28 = call i8* @strchr(i8* %9, i32 61)
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = call i32 @strcpy(i8* %3, i8* %29)
%31 = call i32 @trim_str(i8* %3)
br label %32
32: ; preds = %18, %8, %27
%33 = phi i32 [ 0, %27 ], [ -1, %8 ], [ -1, %18 ]
%34 = call i32 @fclose(i32* %6)
br label %35
35: ; preds = %4, %32
%36 = phi i32 [ %33, %32 ], [ -1, %4 ]
ret i32 %36
}