#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 *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
int iniGetKey(char *ini, char *key, char *destBuffer) {
  FILE *fp;
  char read[255];
  char search[255];
  char *found;
  int returnValue = 1;
  strcpy(destBuffer, "");
  if (strlen(key) > 250)
    return 2;
  if ((fp = fopen(ini, "rt")) == NULL)
    return 3;
  strcpy(search, key);
  strcat(search, "=");
  while (fgets(read, 255, fp) != NULL) {
    if ((found = strstr(read, search)) != NULL && found == read) {
      sprintf(destBuffer, "%s", strchr(found, '=') + 1);
      destBuffer[strlen(destBuffer) - 1] = '\0';
      returnValue = 0;
      break;
    }
  }
  fclose(fp);
  return returnValue;
}


x86 assembly (clang, -O0):
<iniGetKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x1,-0x23c(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0xfa,%eax
jle    11e1 <iniGetKey+0x51>
movl   $0x2,-0x4(%rbp)
jmp    130b <iniGetKey+0x17b>
mov    -0x10(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    120b <iniGetKey+0x7b>
movl   $0x3,-0x4(%rbp)
jmp    130b <iniGetKey+0x17b>
lea    -0x230(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x230(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0xff,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12f9 <iniGetKey+0x169>
lea    -0x130(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   10b0 <strstr@plt>
mov    %rax,-0x238(%rbp)
cmp    $0x0,%rax
je     12f4 <iniGetKey+0x164>
mov    -0x238(%rbp),%rax
lea    -0x130(%rbp),%rcx
cmp    %rcx,%rax
jne    12f4 <iniGetKey+0x164>
mov    -0x20(%rbp),%rax
mov    %rax,-0x250(%rbp)
mov    -0x238(%rbp),%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
mov    -0x250(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xd4c(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x248(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x248(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x23c(%rbp)
jmp    12f9 <iniGetKey+0x169>
jmp    122e <iniGetKey+0x9e>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x23c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iniGetKey>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
lea    0xe64(%rip),%rsi
mov    %rdx,%rdi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    $0x2,%ebx
cmp    $0xfa,%eax
jg     126b <iniGetKey+0xeb>
lea    0xe39(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1257 <iniGetKey+0xd7>
mov    %rax,%r13
lea    0x100(%rsp),%r15
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
lea    0xe0e(%rip),%rsi
mov    %r15,%rdi
call   1090 <strcat@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     125e <iniGetKey+0xde>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     1200 <iniGetKey+0x80>
cmp    %rbx,%rax
jne    1200 <iniGetKey+0x80>
mov    %rsp,%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
xor    %ebx,%ebx
jmp    1263 <iniGetKey+0xe3>
mov    $0x3,%ebx
jmp    126b <iniGetKey+0xeb>
mov    $0x1,%ebx
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [2 x i8] c"=\00"
define i32 @iniGetKey(i8* nocapture %0, i8* %1, i8* %2) {
%4 = alloca [255 x i8]
%5 = alloca [255 x i8]
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%8 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @strlen(i8* %1)
%10 = icmp sgt i32 %9, 250
br i1 %10, label %36, label %11
11: ; preds = %3
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %36, label %14
14: ; preds = %11
%15 = call i32 @strcpy(i8* %7, i8* %1)
%16 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %20, %14
%18 = call i32* @fgets(i8* %6, i32 255, i32* %12)
%19 = icmp eq i32* %18, null
br i1 %19, label %33, label %20
20: ; preds = %17
%21 = call i8* @strstr(i8* %6, i8* %7)
%22 = icmp ne i8* %21, null
%23 = icmp eq i8* %21, %6
%24 = and i1 %22, %23
br i1 %24, label %25, label %17
25: ; preds = %20
%26 = call i8* @strchr(i8* %6, i8 signext 61)
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = call i8* bitcast (i32 (i8*, i8*)* @strcpy to i8* (i8*, i8*)*)(i8* %2, i8* %27)
%29 = call i32 @strlen(i8* %2)
%30 = add nsw i32 %29, -1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %2, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %17, %25
%34 = phi i32 [ 0, %25 ], [ 1, %17 ]
%35 = call i32 @fclose(i32* %12)
br label %36
36: ; preds = %11, %3, %33
%37 = phi i32 [ %34, %33 ], [ 2, %3 ], [ 3, %11 ]
ret i32 %37
}