#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 ENOMEM;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ remove_space(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int get_section(const char *config_file, const char *section, char *revalue) {
  FILE *fd;
  int start;
  char tmp[40] = {0};
  char row[200];
  fd = fopen(config_file, "r");
  if (fd == NULL) {
    perror("fopen():");
    return -1;
  }
  start = 0;
  snprintf(tmp, strlen(section) + 1, "[%s]", section);
  memset(row, 0, 200);
  while (fgets(row, 200, fd)) {
    remove_space(row);
    if (row[0] == '#' || row[0] == '\n') {
      continue;
    }
    if (row[0] == '[' && start) {
      break;
    }
    if (!strncmp(row, tmp, strlen(section))) {
      start = 1;
    }
    if (start) {
      if (strlen(revalue) + strlen(row) >= 4096) {
        return -ENOMEM;
      }
      strncpy(revalue + strlen(revalue), row, strlen(row) + 1);
    }
    memset(row, 0, 200);
  }
  fclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<get_section>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1080 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11fe <get_section+0x5e>
lea    0xe15(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13cf <get_section+0x22f>
movl   $0x0,-0x2c(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x138(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
mov    -0x18(%rbp),%rcx
lea    0xddb(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1080 <memset@plt>
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0xc8,%esi
call   10a0 <fgets@plt>
cmp    $0x0,%rax
je     13bf <get_section+0x21f>
lea    -0x130(%rbp),%rdi
call   1090 <remove_space@plt>
movsbl -0x130(%rbp),%eax
cmp    $0x23,%eax
je     1293 <get_section+0xf3>
movsbl -0x130(%rbp),%eax
cmp    $0xa,%eax
jne    1298 <get_section+0xf8>
jmp    1248 <get_section+0xa8>
movsbl -0x130(%rbp),%eax
cmp    $0x5b,%eax
jne    12b7 <get_section+0x117>
cmpl   $0x0,-0x2c(%rbp)
je     12b7 <get_section+0x117>
jmp    13bf <get_section+0x21f>
lea    -0x130(%rbp),%rax
mov    %rax,-0x148(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x148(%rbp),%rdi
mov    -0x140(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    12fe <get_section+0x15e>
movl   $0x1,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     13a7 <get_section+0x207>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x14c(%rbp)
lea    -0x130(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x14c(%rbp),%eax
add    %ecx,%eax
cmp    $0x1000,%eax
jl     134b <get_section+0x1ab>
xor    %eax,%eax
mov    0x2c9f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    13cf <get_section+0x22f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x168(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x160(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x158(%rbp)
lea    -0x130(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x160(%rbp),%rdi
mov    -0x158(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1080 <memset@plt>
jmp    1248 <get_section+0xa8>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_section>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movq   $0x0,0x20(%rsp)
lea    0xe2d(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     130f <get_section+0x16f>
mov    %rax,%r12
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%esi
lea    0xe15(%rip),%rdx
mov    %rsp,%rdi
mov    %r15,%rcx
call   1070 <snprintf@plt>
lea    0x30(%rsp),%rbx
xor    %r13d,%r13d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1080 <memset@plt>
mov    %rbx,%rdi
mov    $0xc8,%esi
mov    %r12,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     12f3 <get_section+0x153>
lea    0x30(%rsp),%rbx
mov    %rsp,%rbp
jmp    1269 <get_section+0xc9>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1080 <memset@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0xc8,%esi
mov    %r12,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     12f3 <get_section+0x153>
mov    %rbx,%rdi
call   1090 <remove_space@plt>
movzbl 0x30(%rsp),%eax
cmp    $0x23,%al
je     1250 <get_section+0xb0>
cmp    $0xa,%al
je     1250 <get_section+0xb0>
cmp    $0x5b,%al
jne    1287 <get_section+0xe7>
test   %r13d,%r13d
jne    12f3 <get_section+0x153>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
mov    $0x1,%eax
cmove  %eax,%r13d
test   %r13d,%r13d
je     123b <get_section+0x9b>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <strlen@plt>
add    %ebp,%eax
cmp    $0x1000,%eax
jge    1322 <get_section+0x182>
mov    %r14,%rdi
call   1060 <strlen@plt>
movslq %eax,%rbp
add    %r14,%rbp
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %rsp,%rbp
jmp    123b <get_section+0x9b>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcec(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%eax
jmp    12fd <get_section+0x15d>
mov    0x2cb7(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    12fd <get_section+0x15d>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [9 x i8] c"fopen():\00"
@.str.2 = [5 x i8] c"[%s]\00"
@ENOMEM = global i32 0
define i32 @get_section(i8* nocapture %0, i8* %1, i8* %2) {
%4 = alloca [40 x i8]
%5 = alloca [200 x i8]
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %58
12: ; preds = %3
%13 = tail call i32 @strlen(i8* %1)
%14 = add nsw i32 %13, 1
%15 = call i32 @snprintf(i8* %6, i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%16 = call i32 @memset(i8* %7, i32 0, i32 200)
%17 = call i64 @fgets(i8* %7, i32 200, i32* %8)
%18 = icmp eq i64 %17, 0
br i1 %18, label %56, label %19
19: ; preds = %12, %52
%20 = phi i32 [ %35, %52 ], [ 0, %12 ]
br label %21
21: ; preds = %19, %24
%22 = call i32 @remove_space(i8* %7)
%23 = load i8, i8* %7
switch i8 %23, label %27 [
i8 35, label %24
i8 10, label %24
]
24: ; preds = %21, %21
%25 = call i64 @fgets(i8* %7, i32 200, i32* %8)
%26 = icmp eq i64 %25, 0
br i1 %26, label %56, label %21
27: ; preds = %21
%28 = icmp eq i8 %23, 91
%29 = icmp ne i32 %20, 0
%30 = select i1 %28, i1 %29, i1 false
br i1 %30, label %56, label %31
31: ; preds = %27
%32 = call i32 @strlen(i8* %1)
%33 = call i32 @strncmp(i8* %7, i8* %6, i32 %32)
%34 = icmp eq i32 %33, 0
%35 = select i1 %34, i32 1, i32 %20
%36 = icmp eq i32 %35, 0
br i1 %36, label %52, label %37
37: ; preds = %31
%38 = call i32 @strlen(i8* %2)
%39 = call i32 @strlen(i8* %7)
%40 = add nsw i32 %39, %38
%41 = icmp sgt i32 %40, 4095
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = load i32, i32* @ENOMEM
%44 = sub nsw i32 0, %43
br label %58
45: ; preds = %37
%46 = call i32 @strlen(i8* %2)
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %2, i64 %47
%49 = call i32 @strlen(i8* %7)
%50 = add nsw i32 %49, 1
%51 = call i32 @strncpy(i8* %48, i8* %7, i32 %50)
br label %52
52: ; preds = %45, %31
%53 = call i32 @memset(i8* %7, i32 0, i32 200)
%54 = call i64 @fgets(i8* %7, i32 200, i32* %8)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %19
56: ; preds = %27, %52, %24, %12
%57 = call i32 @fclose(i32* %8)
br label %58
58: ; preds = %56, %42, %10
%59 = phi i32 [ -1, %10 ], [ 0, %56 ], [ %44, %42 ]
ret i32 %59
}