#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 */

/* Variables and functions */
int atoi(char *);
scalar_t__ isdigit(char);
scalar_t__ readLine(char *);
int /*<<< orphan*/ rewindBuffer();
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *strrchr(char *, char);
int iniFileGetInt(char *section, char *entry, int def) {
  char buff[512];
  char *ep;
  char t_section[512];
  char value[16];
  int len = strlen(entry);
  int i;
  rewindBuffer();
  sprintf(t_section, "[%s]", section);
  do {
    if (readLine(buff) < 0) {
      return def;
    }
  } while (strcmp(buff, t_section));
  do {
    if (readLine(buff) < 0 || buff[0] == '[') {
      return def;
    }
  } while (strncmp(buff, entry, len));
  ep = strrchr(buff, '=');
  if (ep == NULL) {
    return def;
  }
  ep++;
  if (!strlen(ep)) {
    return def;
  }
  for (i = 0; isdigit(ep[i]); i++) {
    value[i] = ep[i];
  }
  value[i] = '\0';
  return atoi(value);
}


x86 assembly (clang, -O0):
<iniFileGetInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x444(%rbp)
mov    $0x0,%al
call   1050 <rewindBuffer@plt>
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe32(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x220(%rbp),%rdi
call   1090 <readLine@plt>
cmp    $0x0,%rax
jge    11f4 <iniFileGetInt+0x64>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1350 <iniFileGetInt+0x1c0>
jmp    11f9 <iniFileGetInt+0x69>
lea    -0x220(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    11d3 <iniFileGetInt+0x43>
jmp    121b <iniFileGetInt+0x8b>
lea    -0x220(%rbp),%rdi
call   1090 <readLine@plt>
cmp    $0x0,%rax
jl     1241 <iniFileGetInt+0xb1>
movsbl -0x220(%rbp),%eax
cmp    $0x5b,%eax
jne    124c <iniFileGetInt+0xbc>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1350 <iniFileGetInt+0x1c0>
jmp    1251 <iniFileGetInt+0xc1>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x444(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    121b <iniFileGetInt+0x8b>
lea    -0x220(%rbp),%rdi
mov    $0x3d,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x228(%rbp)
cmpq   $0x0,-0x228(%rbp)
jne    12a2 <iniFileGetInt+0x112>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1350 <iniFileGetInt+0x1c0>
mov    -0x228(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x228(%rbp)
mov    -0x228(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%eax
jne    12d4 <iniFileGetInt+0x144>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1350 <iniFileGetInt+0x1c0>
movl   $0x0,-0x448(%rbp)
mov    -0x228(%rbp),%rax
movslq -0x448(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     1332 <iniFileGetInt+0x1a2>
mov    -0x228(%rbp),%rax
movslq -0x448(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x448(%rbp),%rax
mov    %cl,-0x440(%rbp,%rax,1)
mov    -0x448(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x448(%rbp)
jmp    12de <iniFileGetInt+0x14e>
movslq -0x448(%rbp),%rax
movb   $0x0,-0x440(%rbp,%rax,1)
lea    -0x440(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iniFileGetInt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1060 <strlen@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1050 <rewindBuffer@plt>
lea    0xe3f(%rip),%rsi
lea    0x210(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   10b0 <sprintf@plt>
lea    0x10(%rsp),%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1090 <readLine@plt>
test   %rax,%rax
js     12b0 <iniFileGetInt+0x120>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    11e0 <iniFileGetInt+0x50>
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1090 <readLine@plt>
test   %rax,%rax
js     12b0 <iniFileGetInt+0x120>
cmpb   $0x5b,0x10(%rsp)
je     12b0 <iniFileGetInt+0x120>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1210 <iniFileGetInt+0x80>
lea    0x10(%rsp),%rdi
mov    $0x3d,%esi
call   1070 <strrchr@plt>
test   %rax,%rax
je     12b0 <iniFileGetInt+0x120>
mov    %rax,%rbx
lea    0x1(%rax),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
je     12b0 <iniFileGetInt+0x120>
movsbl 0x0(%rbp),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     129f <iniFileGetInt+0x10f>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movzbl 0x1(%rbx,%rbp,1),%eax
mov    %al,(%rsp,%rbp,1)
movsbl 0x2(%rbx,%rbp,1),%edi
add    $0x1,%rbp
call   1040 <isdigit@plt>
test   %rax,%rax
jne    1280 <iniFileGetInt+0xf0>
mov    %ebp,%eax
jmp    12a1 <iniFileGetInt+0x111>
xor    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   10a0 <atoi@plt>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"[%s]\00"
define i32 @iniFileGetInt(i8* %0, i8* %1, i32 %2) {
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
%6 = alloca [16 x i8]
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%10 = tail call i32 @strlen(i8* %1)
%11 = tail call i32 (...) @rewindBuffer()
%12 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %16, %3
%14 = call i64 @readLine(i8* %7)
%15 = icmp slt i64 %14, 0
br i1 %15, label %55, label %16
16: ; preds = %13
%17 = call i64 @strcmp(i8* %7, i8* %8)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %13
19: ; preds = %16, %25
%20 = call i64 @readLine(i8* %7)
%21 = icmp slt i64 %20, 0
%22 = load i8, i8* %7
%23 = icmp eq i8 %22, 91
%24 = select i1 %21, i1 true, i1 %23
br i1 %24, label %55, label %25
25: ; preds = %19
%26 = call i64 @strncmp(i8* %7, i8* %1, i32 %10)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %19
28: ; preds = %25
%29 = call i8* @strrchr(i8* %7, i8 signext 61)
%30 = icmp eq i8* %29, null
br i1 %30, label %55, label %31
31: ; preds = %28
%32 = getelementptr inbounds i8, i8* %29, i64 1
%33 = call i32 @strlen(i8* %32)
%34 = icmp eq i32 %33, 0
br i1 %34, label %55, label %35
35: ; preds = %31
%36 = load i8, i8* %32
%37 = call i64 @isdigit(i8 signext %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %51, label %39
39: ; preds = %35, %39
%40 = phi i64 [ %44, %39 ], [ 0, %35 ]
%41 = phi i8* [ %45, %39 ], [ %32, %35 ]
%42 = load i8, i8* %41
%43 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %40
store i8 %42, i8* %43
%44 = add nuw nsw i64 %40, 1
%45 = getelementptr inbounds i8, i8* %32, i64 %44
%46 = load i8, i8* %45
%47 = call i64 @isdigit(i8 signext %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %39
49: ; preds = %39
%50 = and i64 %44, 4294967295
br label %51
51: ; preds = %49, %35
%52 = phi i64 [ 0, %35 ], [ %50, %49 ]
%53 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %52
store i8 0, i8* %53
%54 = call i32 @atoi(i8* %9)
br label %55
55: ; preds = %13, %19, %31, %28, %51
%56 = phi i32 [ %54, %51 ], [ %2, %28 ], [ %2, %31 ], [ %2, %19 ], [ %2, %13 ]
ret i32 %56
}