#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 /*<<< orphan*/ ActualFileClose(int);
int ActualFileOpenForRead(char *);
int /*<<< orphan*/ INIAddInExt(char *, int);
int INIFindKeyword(int, char const *, char *);
int INIFindSection(int, char const *);
int INIRemoveExt(char const *, char *);
int INILoadString(const char *file, const char *section, const char *keyword,
                  char *buffer) {
  char inname[255 + 1];
  int filepos;
  int infile;
  int retval;
  if (file == NULL)
    return (-1);
  if (section == NULL)
    return (-1);
  if (keyword == NULL)
    return (-1);
  if (buffer == NULL)
    return (-1);
  filepos = INIRemoveExt(file, inname);
  INIAddInExt(inname, filepos);
  filepos = 0;
  infile = ActualFileOpenForRead(inname);
  if (infile == -1)
    return (-1);
  retval = INIFindSection(infile, section);
  if (retval < 0) {
    ActualFileClose(infile);
    infile = -1;
    return (-1);
  }
  retval = INIFindKeyword(infile, keyword, buffer);
  if (retval < 0) {
    ActualFileClose(infile);
    infile = -1;
    return (-1);
  }
  ActualFileClose(infile);
  infile = -1;
  return (0);
}


x86 assembly (clang, -O0):
<INILoadString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1192 <INILoadString+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    12da <INILoadString+0x17a>
cmpq   $0x0,-0x18(%rbp)
jne    11a9 <INILoadString+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    12da <INILoadString+0x17a>
cmpq   $0x0,-0x20(%rbp)
jne    11c0 <INILoadString+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    12da <INILoadString+0x17a>
cmpq   $0x0,-0x28(%rbp)
jne    11d7 <INILoadString+0x77>
movl   $0xffffffff,-0x4(%rbp)
jmp    12da <INILoadString+0x17a>
mov    -0x10(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1040 <INIRemoveExt@plt>
mov    %eax,-0x134(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x134(%rbp),%esi
call   1080 <INIAddInExt@plt>
movl   $0x0,-0x134(%rbp)
lea    -0x130(%rbp),%rdi
call   1050 <ActualFileOpenForRead@plt>
mov    %eax,-0x138(%rbp)
cmpl   $0xffffffff,-0x138(%rbp)
jne    1234 <INILoadString+0xd4>
movl   $0xffffffff,-0x4(%rbp)
jmp    12da <INILoadString+0x17a>
mov    -0x138(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1070 <INIFindSection@plt>
mov    %eax,-0x13c(%rbp)
cmpl   $0x0,-0x13c(%rbp)
jge    1277 <INILoadString+0x117>
mov    -0x138(%rbp),%edi
call   1030 <ActualFileClose@plt>
movl   $0xffffffff,-0x138(%rbp)
ff ff ff
movl   $0xffffffff,-0x4(%rbp)
jmp    12da <INILoadString+0x17a>
mov    -0x138(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <INIFindKeyword@plt>
mov    %eax,-0x13c(%rbp)
cmpl   $0x0,-0x13c(%rbp)
jge    12be <INILoadString+0x15e>
mov    -0x138(%rbp),%edi
call   1030 <ActualFileClose@plt>
movl   $0xffffffff,-0x138(%rbp)
ff ff ff
movl   $0xffffffff,-0x4(%rbp)
jmp    12da <INILoadString+0x17a>
mov    -0x138(%rbp),%edi
call   1030 <ActualFileClose@plt>
movl   $0xffffffff,-0x138(%rbp)
ff ff ff
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<INILoadString>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    $0xffffffff,%r15d
test   %rdi,%rdi
je     11e8 <INILoadString+0x88>
mov    %rsi,%rbp
test   %rsi,%rsi
je     11e8 <INILoadString+0x88>
mov    %rdx,%r12
test   %rdx,%rdx
je     11e8 <INILoadString+0x88>
mov    %rcx,%r14
test   %rcx,%rcx
je     11e8 <INILoadString+0x88>
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1040 <INIRemoveExt@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1080 <INIAddInExt@plt>
mov    %rbx,%rdi
call   1050 <ActualFileOpenForRead@plt>
cmp    $0xffffffff,%eax
je     11e8 <INILoadString+0x88>
mov    %eax,%ebx
mov    %eax,%edi
mov    %rbp,%rsi
call   1070 <INIFindSection@plt>
test   %eax,%eax
js     11e1 <INILoadString+0x81>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   1060 <INIFindKeyword@plt>
mov    %eax,%r15d
mov    %ebx,%edi
call   1030 <ActualFileClose@plt>
sar    $0x1f,%r15d
jmp    11e8 <INILoadString+0x88>
mov    %ebx,%edi
call   1030 <ActualFileClose@plt>
mov    %r15d,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @INILoadString(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 [256 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
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 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -1, i32* %5
br label %63
17: ; preds = %4
%18 = load i8*, i8** %7
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 -1, i32* %5
br label %63
21: ; preds = %17
%22 = load i8*, i8** %8
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 -1, i32* %5
br label %63
25: ; preds = %21
%26 = load i8*, i8** %9
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 -1, i32* %5
br label %63
29: ; preds = %25
%30 = load i8*, i8** %6
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%32 = call i32 @INIRemoveExt(i8* %30, i8* %31)
store i32 %32, i32* %11
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%34 = load i32, i32* %11
%35 = call i32 @INIAddInExt(i8* %33, i32 %34)
store i32 0, i32* %11
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%37 = call i32 @ActualFileOpenForRead(i8* %36)
store i32 %37, i32* %12
%38 = load i32, i32* %12
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %41
40: ; preds = %29
store i32 -1, i32* %5
br label %63
41: ; preds = %29
%42 = load i32, i32* %12
%43 = load i8*, i8** %7
%44 = call i32 @INIFindSection(i32 %42, i8* %43)
store i32 %44, i32* %13
%45 = load i32, i32* %13
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %41
%48 = load i32, i32* %12
%49 = call i32 @ActualFileClose(i32 %48)
store i32 -1, i32* %12
store i32 -1, i32* %5
br label %63
50: ; preds = %41
%51 = load i32, i32* %12
%52 = load i8*, i8** %8
%53 = load i8*, i8** %9
%54 = call i32 @INIFindKeyword(i32 %51, i8* %52, i8* %53)
store i32 %54, i32* %13
%55 = load i32, i32* %13
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %50
%58 = load i32, i32* %12
%59 = call i32 @ActualFileClose(i32 %58)
store i32 -1, i32* %12
store i32 -1, i32* %5
br label %63
60: ; preds = %50
%61 = load i32, i32* %12
%62 = call i32 @ActualFileClose(i32 %61)
store i32 -1, i32* %12
store i32 0, i32* %5
br label %63
63: ; preds = %60, %57, %47, %40, %28, %24, %20, %16
%64 = load i32, i32* %5
ret i32 %64
}

LLVM IR (-O2):
define i32 @INILoadString(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = icmp eq i8* %0, null
%8 = icmp eq i8* %1, null
%9 = or i1 %7, %8
%10 = icmp eq i8* %2, null
%11 = or i1 %9, %10
%12 = icmp eq i8* %3, null
%13 = or i1 %11, %12
br i1 %13, label %28, label %14
14: ; preds = %4
%15 = call i32 @INIRemoveExt(i8* %0, i8* %6)
%16 = call i32 @INIAddInExt(i8* %6, i32 %15)
%17 = call i32 @ActualFileOpenForRead(i8* %6)
%18 = icmp eq i32 %17, -1
br i1 %18, label %28, label %19
19: ; preds = %14
%20 = call i32 @INIFindSection(i32 %17, i8* %1)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @ActualFileClose(i32 %17)
br label %28
24: ; preds = %19
%25 = call i32 @INIFindKeyword(i32 %17, i8* %2, i8* %3)
%26 = call i32 @ActualFileClose(i32 %17)
%27 = ashr i32 %25, 31
br label %28
28: ; preds = %24, %14, %4, %22
%29 = phi i32 [ -1, %22 ], [ -1, %4 ], [ -1, %14 ], [ %27, %24 ]
ret i32 %29
}