#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 */
struct stat {
  int st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                         char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ isdigit(char);
scalar_t__ isspace(char);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
scalar_t__ strcasecmp(char *, char *);
char *strdup(char *);
scalar_t__ strncmp(char *, char *, int);
char *strsep(char **, char *);
int strtol(char *, int /*<<< orphan*/ *, int);
int strtoul(char *, int /*<<< orphan*/ *, int);
char *ParseKeyFile(char *file, char *index) {
  struct stat s;
  FILE *f = fopen(file, "r");
  char *buf = 0;
  char *key = 0;
  int i, j, k;
  if (!f) {
    error(0, errno, "Couldn't open %s", file);
    goto error;
  }
  if (stat(file, &s) == -1) {
    error(0, errno, "Couldn't stat %s", file);
    goto error;
  }
  buf = malloc(s.st_size);
  if (!buf) {
    fprintf(stderr, "No memory for %s", file);
    goto error;
  }
  if (fread(buf, 1, s.st_size, f) != s.st_size) {
    error(0, errno, "Couldn't read %s", file);
    goto error;
  }
  int indexNum = -1;
  for (i = 0; index[i]; i++)
    if (!isdigit(index[i]))
      goto string_index;
  indexNum = strtol(index, NULL, 10);
string_index:
  if (strncmp(buf, "Version 2 Keyfile", sizeof("Version 2 Keyfile") - 1) == 0) {
    char *b;
    int keyNum;
    i = 0;
    char *rest = buf;
    strsep(&rest, "\n");
    while (b = strsep(&rest, "\n\r")) {
      char *r = b, *keyIndex = strsep(&r, " ");
      if (!keyIndex || !r)
        continue;
      i++;
      if (indexNum != -1 && strtoul(keyIndex, NULL, 10) != indexNum ||
          indexNum == -1 && strcasecmp(keyIndex, index) != 0)
        continue;
      while (isspace(*r))
        r++;
      key = strdup(r);
      goto gotkey;
    }
    i--;
  } else {
    if (indexNum == -1) {
      fprintf(stderr,
              "Version 1 keyfile's can't have non-numeric key indices! (\"%s\" "
              "is not allowed)\n",
              index);
      goto error;
    }
    for (j = 0, i = 0; j < s.st_size; j++) {
      if (i == indexNum) {
        for (k = j; k < s.st_size; k++) {
          if (buf[k] == '\0')
            break;
        }
        key = malloc(k - j + 1);
        if (!key) {
          fprintf(stderr, "Out of memory!\n");
          goto error;
        }
        memcpy(key, &buf[j], k - j);
        key[k - j] = '\0';
        goto gotkey;
      }
      if (buf[j] == '\0')
        i++;
    }
  }
  fprintf(stderr, "There is no key %s in \"%s\". There is only 0 through %d!\n",
          index, file, i);
gotkey:
error:
  if (f)
    fclose(f);
  if (buf)
    free(buf);
  return key;
}


x86 assembly (clang, -O0):
<ParseKeyFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdd5(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    126f <ParseKeyFile+0x5f>
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
xor    %edi,%edi
lea    0xd9d(%rip),%rdx
call   1100 <error@plt>
jmp    160a <ParseKeyFile+0x3fa>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
jne    12a5 <ParseKeyFile+0x95>
mov    0x2d4c(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
xor    %edi,%edi
lea    0xd78(%rip),%rdx
call   1100 <error@plt>
jmp    160a <ParseKeyFile+0x3fa>
mov    -0x18(%rbp),%edi
call   10e0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12dc <ParseKeyFile+0xcc>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd54(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    160a <ParseKeyFile+0x3fa>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fread@plt>
cmp    -0x18(%rbp),%eax
je     131a <ParseKeyFile+0x10a>
mov    0x2cd7(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
xor    %edi,%edi
lea    0xd25(%rip),%rdx
call   1100 <error@plt>
jmp    160a <ParseKeyFile+0x3fa>
movl   $0xffffffff,-0x40(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     136c <ParseKeyFile+0x15c>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <isdigit@plt>
cmp    $0x0,%eax
jne    1359 <ParseKeyFile+0x149>
jmp    1381 <ParseKeyFile+0x171>
jmp    135e <ParseKeyFile+0x14e>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1328 <ParseKeyFile+0x118>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10c0 <strtol@plt>
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xcba(%rip),%rsi
mov    $0x11,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    14b4 <ParseKeyFile+0x2a4>
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x58(%rbp),%rdi
lea    0xd39(%rip),%rsi
call   10f0 <strsep@plt>
lea    -0x58(%rbp),%rdi
lea    0xc8e(%rip),%rsi
call   10f0 <strsep@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     14a6 <ParseKeyFile+0x296>
mov    -0x48(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xc6b(%rip),%rsi
call   10f0 <strsep@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     140f <ParseKeyFile+0x1ff>
cmpq   $0x0,-0x60(%rbp)
jne    1414 <ParseKeyFile+0x204>
jmp    13bf <ParseKeyFile+0x1af>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x40(%rbp)
je     1442 <ParseKeyFile+0x232>
mov    -0x68(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1120 <strtoul@plt>
cmp    -0x40(%rbp),%eax
jne    1463 <ParseKeyFile+0x253>
cmpl   $0xffffffff,-0x40(%rbp)
jne    1468 <ParseKeyFile+0x258>
mov    -0x68(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     1468 <ParseKeyFile+0x258>
jmp    13bf <ParseKeyFile+0x1af>
jmp    146d <ParseKeyFile+0x25d>
mov    -0x60(%rbp),%rax
movsbl (%rax),%edi
call   1090 <isspace@plt>
cmp    $0x0,%rax
je     1494 <ParseKeyFile+0x284>
mov    -0x60(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
jmp    146d <ParseKeyFile+0x25d>
mov    -0x60(%rbp),%rdi
call   1130 <strdup@plt>
mov    %rax,-0x30(%rbp)
jmp    1605 <ParseKeyFile+0x3f5>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    15e2 <ParseKeyFile+0x3d2>
cmpl   $0xffffffff,-0x40(%rbp)
jne    14de <ParseKeyFile+0x2ce>
mov    0x2b1b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xb8b(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    160a <ParseKeyFile+0x3fa>
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    15dd <ParseKeyFile+0x3cd>
mov    -0x34(%rbp),%eax
cmp    -0x40(%rbp),%eax
jne    15ac <ParseKeyFile+0x39c>
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1543 <ParseKeyFile+0x333>
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1530 <ParseKeyFile+0x320>
jmp    1543 <ParseKeyFile+0x333>
jmp    1535 <ParseKeyFile+0x325>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    150a <ParseKeyFile+0x2fa>
mov    -0x3c(%rbp),%edi
sub    -0x38(%rbp),%edi
add    $0x1,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    157c <ParseKeyFile+0x36c>
mov    0x2a79(%rip),%rax
mov    (%rax),%edi
lea    0xb3c(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    160a <ParseKeyFile+0x3fa>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x38(%rbp),%rax
add    %rax,%rsi
mov    -0x3c(%rbp),%edx
sub    -0x38(%rbp),%edx
call   10d0 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x3c(%rbp),%ecx
sub    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1605 <ParseKeyFile+0x3f5>
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    15ca <ParseKeyFile+0x3ba>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    15cf <ParseKeyFile+0x3bf>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    14ec <ParseKeyFile+0x2dc>
jmp    15e2 <ParseKeyFile+0x3d2>
mov    0x29f7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    -0x34(%rbp),%r8d
lea    0xabe(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    160a <ParseKeyFile+0x3fa>
cmpq   $0x0,-0x20(%rbp)
je     161e <ParseKeyFile+0x40e>
mov    -0x20(%rbp),%rdi
call   1080 <fclose@plt>
cmpq   $0x0,-0x28(%rbp)
je     1632 <ParseKeyFile+0x422>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ParseKeyFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xdd5(%rip),%rsi
call   1110 <fopen@plt>
test   %rax,%rax
je     131f <ParseKeyFile+0x10f>
mov    %rax,%r15
lea    0x18(%rsp),%rsi
mov    %r12,%rdi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
je     1340 <ParseKeyFile+0x130>
mov    0x18(%rsp),%ebp
mov    %ebp,%edi
call   10e0 <malloc@plt>
test   %rax,%rax
je     135c <ParseKeyFile+0x14c>
mov    %rax,(%rsp)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r15,%rcx
call   1070 <fread@plt>
cmp    %ebp,%eax
jne    1385 <ParseKeyFile+0x175>
mov    (%r14),%al
test   %al,%al
je     12ab <ParseKeyFile+0x9b>
lea    0x1(%r14),%rbx
nop
movsbl %al,%edi
call   1060 <isdigit@plt>
test   %eax,%eax
je     13a6 <ParseKeyFile+0x196>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1290 <ParseKeyFile+0x80>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10c0 <strtol@plt>
mov    %eax,%r13d
lea    0xd82(%rip),%rsi
mov    (%rsp),%rdi
mov    $0x11,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
je     13e7 <ParseKeyFile+0x1d7>
cmp    $0xffffffff,%r13d
je     13c0 <ParseKeyFile+0x1b0>
mov    %r14,0x10(%rsp)
test   %ebp,%ebp
jle    14aa <ParseKeyFile+0x29a>
xor    %ebx,%ebx
xor    %r14d,%r14d
mov    (%rsp),%rax
nopl   0x0(%rax,%rax,1)
cmp    %r13d,%r14d
je     14f4 <ParseKeyFile+0x2e4>
cmpb   $0x1,(%rax,%rbx,1)
adc    $0x0,%r14d
add    $0x1,%rbx
cmp    %rbp,%rbx
jne    1300 <ParseKeyFile+0xf0>
jmp    14ad <ParseKeyFile+0x29d>
mov    0x2cb2(%rip),%rax
mov    (%rax),%esi
lea    0xcd3(%rip),%rdx
xor    %ebp,%ebp
xor    %edi,%edi
mov    %r12,%rcx
call   1100 <error@plt>
jmp    14e2 <ParseKeyFile+0x2d2>
mov    0x2c91(%rip),%rax
mov    (%rax),%esi
lea    0xcc3(%rip),%rdx
xor    %edi,%edi
mov    %r12,%rcx
call   1100 <error@plt>
jmp    1376 <ParseKeyFile+0x166>
mov    0x2c7d(%rip),%rax
mov    (%rax),%edi
lea    0xcb8(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r15,%rdi
call   1080 <fclose@plt>
xor    %ebp,%ebp
jmp    14e2 <ParseKeyFile+0x2d2>
mov    0x2c4c(%rip),%rax
mov    (%rax),%esi
lea    0xca0(%rip),%rdx
xor    %ebp,%ebp
xor    %edi,%edi
mov    %r12,%rcx
call   1100 <error@plt>
jmp    14d1 <ParseKeyFile+0x2c1>
lea    0xc99(%rip),%rsi
mov    (%rsp),%rdi
mov    $0x11,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
je     13e1 <ParseKeyFile+0x1d1>
mov    0x2c19(%rip),%rax
mov    (%rax),%edi
lea    0xc8d(%rip),%rsi
xor    %ebp,%ebp
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    14d1 <ParseKeyFile+0x2c1>
mov    $0xffffffff,%r13d
mov    (%rsp),%rax
mov    %r14,0x10(%rsp)
mov    %rax,0x20(%rsp)
lea    0xcf7(%rip),%rsi
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   10f0 <strsep@plt>
lea    0xc48(%rip),%rsi
mov    %rbp,%rdi
call   10f0 <strsep@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     14a4 <ParseKeyFile+0x294>
lea    0x20(%rsp),%rbp
jmp    1454 <ParseKeyFile+0x244>
mov    0x10(%rsp),%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1561 <ParseKeyFile+0x351>
xchg   %ax,%ax
mov    %rbp,%rdi
lea    0xc0e(%rip),%rsi
call   10f0 <strsep@plt>
test   %rax,%rax
je     14a4 <ParseKeyFile+0x294>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0xbf6(%rip),%rsi
call   10f0 <strsep@plt>
test   %rax,%rax
je     1440 <ParseKeyFile+0x230>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     1440 <ParseKeyFile+0x230>
add    $0x1,%r14d
mov    %rax,%rdi
cmp    $0xffffffff,%r13d
je     142b <ParseKeyFile+0x21b>
xor    %esi,%esi
mov    $0xa,%edx
call   1120 <strtoul@plt>
cmp    %r13d,%eax
jne    1440 <ParseKeyFile+0x230>
mov    0x8(%rsp),%rbx
movsbl (%rbx),%edi
jmp    1582 <ParseKeyFile+0x372>
add    $0xffffffff,%r14d
jmp    14ad <ParseKeyFile+0x29d>
xor    %r14d,%r14d
mov    0x2b2c(%rip),%rax
mov    (%rax),%edi
lea    0xbff(%rip),%rsi
xor    %ebp,%ebp
mov    0x10(%rsp),%rdx
mov    %r12,%rcx
mov    %r14d,%r8d
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r15,%rdi
call   1080 <fclose@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%r14d
cmp    %ebx,%ebp
jle    1511 <ParseKeyFile+0x301>
mov    %rbx,%r14
cmpb   $0x0,(%rax,%r14,1)
je     1511 <ParseKeyFile+0x301>
add    $0x1,%r14
cmp    %r14,%rbp
jne    14fe <ParseKeyFile+0x2ee>
mov    %ebp,%r14d
sub    %ebx,%r14d
lea    0x1(%r14),%edi
call   10e0 <malloc@plt>
test   %rax,%rax
je     1543 <ParseKeyFile+0x333>
mov    %rax,%rbp
mov    %ebx,%eax
mov    (%rsp),%rsi
add    %rax,%rsi
mov    %rbp,%rdi
mov    %r14d,%edx
call   10d0 <memcpy@plt>
movslq %r14d,%rax
movb   $0x0,0x0(%rbp,%rax,1)
jmp    14d1 <ParseKeyFile+0x2c1>
mov    0x2a96(%rip),%rax
mov    (%rax),%edi
lea    0xb59(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    14d1 <ParseKeyFile+0x2c1>
movsbl (%rbx),%edi
jmp    1582 <ParseKeyFile+0x372>
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x8(%rsp)
movsbl 0x1(%rax),%edi
call   1090 <isspace@plt>
test   %rax,%rax
jne    1570 <ParseKeyFile+0x360>
mov    0x8(%rsp),%rdi
call   1130 <strdup@plt>
mov    %rax,%rbp
jmp    14d1 <ParseKeyFile+0x2c1>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@errno = global i32 0
@.str.1 = [17 x i8] c"Couldn't open %s\00"
@.str.2 = [17 x i8] c"Couldn't stat %s\00"
@stderr = global i32 0
@.str.3 = [17 x i8] c"No memory for %s\00"
@.str.4 = [17 x i8] c"Couldn't read %s\00"
@.str.5 = [18 x i8] c"Version 2 Keyfile\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [3 x i8] c"\0A\0D\00"
@.str.8 = [2 x i8] c" \00"
@.str.9 = [79 x i8] c"Version 1 keyfile's can't have non-numeric key indices! (\22%s\22 is not allowed)\0A\00"
@.str.10 = [16 x i8] c"Out of memory!\0A\00"
@.str.11 = [57 x i8] c"There is no key %s in \22%s\22. There is only 0 through %d!\0A\00"
define i8* @ParseKeyFile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.stat
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%18 = load i8*, i8** %3
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %6
store i8* null, i8** %7
store i8* null, i8** %8
%20 = load i32*, i32** %6
%21 = icmp ne i32* %20, null
br i1 %21, label %26, label %22
22: ; preds = %2
%23 = load i32, i32* @errno
%24 = load i8*, i8** %3
%25 = call i32 @error(i32 0, i32 %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %221
26: ; preds = %2
%27 = load i8*, i8** %3
%28 = call i32 @stat(i8* %27, %struct.stat* %5)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* @errno
%32 = load i8*, i8** %3
%33 = call i32 @error(i32 0, i32 %31, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %221
34: ; preds = %26
%35 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i8* @malloc(i32 %36)
store i8* %37, i8** %7
%38 = load i8*, i8** %7
%39 = icmp ne i8* %38, null
br i1 %39, label %44, label %40
40: ; preds = %34
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %3
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %42)
br label %221
44: ; preds = %34
%45 = load i8*, i8** %7
%46 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%47 = load i32, i32* %46
%48 = load i32*, i32** %6
%49 = call i32 @fread(i8* %45, i32 1, i32 %47, i32* %48)
%50 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%51 = load i32, i32* %50
%52 = icmp ne i32 %49, %51
br i1 %52, label %53, label %57
53: ; preds = %44
%54 = load i32, i32* @errno
%55 = load i8*, i8** %3
%56 = call i32 @error(i32 0, i32 %54, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %55)
br label %221
57: ; preds = %44
store i32 -1, i32* %12
store i32 0, i32* %9
br label %58
58: ; preds = %75, %57
%59 = load i8*, i8** %4
%60 = load i32, i32* %9
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i8, i8* %62
%64 = icmp ne i8 %63, 0
br i1 %64, label %65, label %78
65: ; preds = %58
%66 = load i8*, i8** %4
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
%70 = load i8, i8* %69
%71 = call i32 @isdigit(i8 signext %70)
%72 = icmp ne i32 %71, 0
br i1 %72, label %74, label %73
73: ; preds = %65
br label %81
74: ; preds = %65
br label %75
75: ; preds = %74
%76 = load i32, i32* %9
%77 = add nsw i32 %76, 1
store i32 %77, i32* %9
br label %58
78: ; preds = %58
%79 = load i8*, i8** %4
%80 = call i32 @strtol(i8* %79, i32* null, i32 10)
store i32 %80, i32* %12
br label %81
81: ; preds = %78, %73
%82 = load i8*, i8** %7
%83 = call i64 @strncmp(i8* %82, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 17)
%84 = icmp eq i64 %83, 0
br i1 %84, label %85, label %134
85: ; preds = %81
store i32 0, i32* %9
%86 = load i8*, i8** %7
store i8* %86, i8** %15
%87 = call i8* @strsep(i8** %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %88
88: ; preds = %118, %99, %85
%89 = call i8* @strsep(i8** %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i8* %89, i8** %13
%90 = icmp ne i8* %89, null
br i1 %90, label %91, label %131
91: ; preds = %88
%92 = load i8*, i8** %13
store i8* %92, i8** %16
%93 = call i8* @strsep(i8** %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i8* %93, i8** %17
%94 = load i8*, i8** %17
%95 = icmp ne i8* %94, null
br i1 %95, label %96, label %99
96: ; preds = %91
%97 = load i8*, i8** %16
%98 = icmp ne i8* %97, null
br i1 %98, label %100, label %99
99: ; preds = %96, %91
br label %88
100: ; preds = %96
%101 = load i32, i32* %9
%102 = add nsw i32 %101, 1
store i32 %102, i32* %9
%103 = load i32, i32* %12
%104 = icmp ne i32 %103, -1
br i1 %104, label %105, label %110
105: ; preds = %100
%106 = load i8*, i8** %17
%107 = call i32 @strtoul(i8* %106, i32* null, i32 10)
%108 = load i32, i32* %12
%109 = icmp ne i32 %107, %108
br i1 %109, label %118, label %110
110: ; preds = %105, %100
%111 = load i32, i32* %12
%112 = icmp eq i32 %111, -1
br i1 %112, label %113, label %119
113: ; preds = %110
%114 = load i8*, i8** %17
%115 = load i8*, i8** %4
%116 = call i64 @strcasecmp(i8* %114, i8* %115)
%117 = icmp ne i64 %116, 0
br i1 %117, label %118, label %119
118: ; preds = %113, %105
br label %88
119: ; preds = %113, %110
br label %120
120: ; preds = %125, %119
%121 = load i8*, i8** %16
%122 = load i8, i8* %121
%123 = call i64 @isspace(i8 signext %122)
%124 = icmp ne i64 %123, 0
br i1 %124, label %125, label %128
125: ; preds = %120
%126 = load i8*, i8** %16
%127 = getelementptr inbounds i8, i8* %126, i32 1
store i8* %127, i8** %16
br label %120
128: ; preds = %120
%129 = load i8*, i8** %16
%130 = call i8* @strdup(i8* %129)
store i8* %130, i8** %8
br label %220
131: ; preds = %88
%132 = load i32, i32* %9
%133 = add nsw i32 %132, -1
store i32 %133, i32* %9
br label %214
134: ; preds = %81
%135 = load i32, i32* %12
%136 = icmp eq i32 %135, -1
br i1 %136, label %137, label %141
137: ; preds = %134
%138 = load i32, i32* @stderr
%139 = load i8*, i8** %4
%140 = call i32 (i32, i8*, ...) @fprintf(i32 %138, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.9, i64 0, i64 0), i8* %139)
br label %221
141: ; preds = %134
store i32 0, i32* %10
store i32 0, i32* %9
br label %142
142: ; preds = %210, %141
%143 = load i32, i32* %10
%144 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%145 = load i32, i32* %144
%146 = icmp slt i32 %143, %145
br i1 %146, label %147, label %213
147: ; preds = %142
%148 = load i32, i32* %9
%149 = load i32, i32* %12
%150 = icmp eq i32 %148, %149
br i1 %150, label %151, label %198
151: ; preds = %147
%152 = load i32, i32* %10
store i32 %152, i32* %11
br label %153
153: ; preds = %168, %151
%154 = load i32, i32* %11
%155 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%156 = load i32, i32* %155
%157 = icmp slt i32 %154, %156
br i1 %157, label %158, label %171
158: ; preds = %153
%159 = load i8*, i8** %7
%160 = load i32, i32* %11
%161 = sext i32 %160 to i64
%162 = getelementptr inbounds i8, i8* %159, i64 %161
%163 = load i8, i8* %162
%164 = sext i8 %163 to i32
%165 = icmp eq i32 %164, 0
br i1 %165, label %166, label %167
166: ; preds = %158
br label %171
167: ; preds = %158
br label %168
168: ; preds = %167
%169 = load i32, i32* %11
%170 = add nsw i32 %169, 1
store i32 %170, i32* %11
br label %153
171: ; preds = %166, %153
%172 = load i32, i32* %11
%173 = load i32, i32* %10
%174 = sub nsw i32 %172, %173
%175 = add nsw i32 %174, 1
%176 = call i8* @malloc(i32 %175)
store i8* %176, i8** %8
%177 = load i8*, i8** %8
%178 = icmp ne i8* %177, null
br i1 %178, label %182, label %179
179: ; preds = %171
%180 = load i32, i32* @stderr
%181 = call i32 (i32, i8*, ...) @fprintf(i32 %180, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %221
182: ; preds = %171
%183 = load i8*, i8** %8
%184 = load i8*, i8** %7
%185 = load i32, i32* %10
%186 = sext i32 %185 to i64
%187 = getelementptr inbounds i8, i8* %184, i64 %186
%188 = load i32, i32* %11
%189 = load i32, i32* %10
%190 = sub nsw i32 %188, %189
%191 = call i32 @memcpy(i8* %183, i8* %187, i32 %190)
%192 = load i8*, i8** %8
%193 = load i32, i32* %11
%194 = load i32, i32* %10
%195 = sub nsw i32 %193, %194
%196 = sext i32 %195 to i64
%197 = getelementptr inbounds i8, i8* %192, i64 %196
store i8 0, i8* %197
br label %220
198: ; preds = %147
%199 = load i8*, i8** %7
%200 = load i32, i32* %10
%201 = sext i32 %200 to i64
%202 = getelementptr inbounds i8, i8* %199, i64 %201
%203 = load i8, i8* %202
%204 = sext i8 %203 to i32
%205 = icmp eq i32 %204, 0
br i1 %205, label %206, label %209
206: ; preds = %198
%207 = load i32, i32* %9
%208 = add nsw i32 %207, 1
store i32 %208, i32* %9
br label %209
209: ; preds = %206, %198
br label %210
210: ; preds = %209
%211 = load i32, i32* %10
%212 = add nsw i32 %211, 1
store i32 %212, i32* %10
br label %142
213: ; preds = %142
br label %214
214: ; preds = %213, %131
%215 = load i32, i32* @stderr
%216 = load i8*, i8** %4
%217 = load i8*, i8** %3
%218 = load i32, i32* %9
%219 = call i32 (i32, i8*, ...) @fprintf(i32 %215, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.11, i64 0, i64 0), i8* %216, i8* %217, i32 %218)
br label %220
220: ; preds = %214, %182, %128
br label %221
221: ; preds = %220, %179, %137, %53, %40, %30, %22
%222 = load i32*, i32** %6
%223 = icmp ne i32* %222, null
br i1 %223, label %224, label %227
224: ; preds = %221
%225 = load i32*, i32** %6
%226 = call i32 @fclose(i32* %225)
br label %227
227: ; preds = %224, %221
%228 = load i8*, i8** %7
%229 = icmp ne i8* %228, null
br i1 %229, label %230, label %233
230: ; preds = %227
%231 = load i8*, i8** %7
%232 = call i32 @free(i8* %231)
br label %233
233: ; preds = %230, %227
%234 = load i8*, i8** %8
ret i8* %234
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@errno = global i32 0
@.str.1 = [17 x i8] c"Couldn't open %s\00"
@.str.2 = [17 x i8] c"Couldn't stat %s\00"
@stderr = global i32 0
@.str.3 = [17 x i8] c"No memory for %s\00"
@.str.4 = [17 x i8] c"Couldn't read %s\00"
@.str.5 = [18 x i8] c"Version 2 Keyfile\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [3 x i8] c"\0A\0D\00"
@.str.8 = [2 x i8] c" \00"
@.str.9 = [79 x i8] c"Version 1 keyfile's can't have non-numeric key indices! (\22%s\22 is not allowed)\0A\00"
@.str.10 = [16 x i8] c"Out of memory!\0A\00"
@.str.11 = [57 x i8] c"There is no key %s in \22%s\22. There is only 0 through %d!\0A\00"
define i8* @ParseKeyFile(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = alloca i8*
%5 = alloca i8*
%6 = bitcast %struct.stat* %3 to i8*
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @errno
%11 = tail call i32 @error(i32 0, i32 %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %159
12: ; preds = %2
%13 = call i32 @stat(i8* %0, %struct.stat* %3)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @errno
%17 = tail call i32 @error(i32 0, i32 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %153
18: ; preds = %12
%19 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%20 = load i32, i32* %19
%21 = tail call i8* @malloc(i32 %20)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %153
26: ; preds = %18
%27 = tail call i32 @fread(i8* %21, i32 1, i32 %20, i32* %7)
%28 = icmp eq i32 %27, %20
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i8, i8* %1
%31 = icmp eq i8 %30, 0
br i1 %31, label %45, label %39
32: ; preds = %26
%33 = load i32, i32* @errno
%34 = tail call i32 @error(i32 0, i32 %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %155
35: ; preds = %39
%36 = getelementptr inbounds i8, i8* %1, i64 %44
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %29, %35
%40 = phi i64 [ %44, %35 ], [ 0, %29 ]
%41 = phi i8 [ %37, %35 ], [ %30, %29 ]
%42 = tail call i32 @isdigit(i8 signext %41)
%43 = icmp eq i32 %42, 0
%44 = add nuw i64 %40, 1
br i1 %43, label %49, label %35
45: ; preds = %35, %29
%46 = tail call i32 @strtol(i8* nocapture %1, i32* null, i32 10)
%47 = tail call i64 @strncmp(i8* %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 17)
%48 = icmp eq i64 %47, 0
br i1 %48, label %52, label %100
49: ; preds = %39
%50 = tail call i64 @strncmp(i8* %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 17)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %106
52: ; preds = %49, %45
%53 = phi i32 [ -1, %49 ], [ %46, %45 ]
%54 = bitcast i8** %4 to i8*
store i8* %21, i8** %4
%55 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%56 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%57 = icmp eq i8* %56, null
br i1 %57, label %94, label %58
58: ; preds = %52
%59 = bitcast i8** %5 to i8*
%60 = icmp eq i32 %53, -1
br label %61
61: ; preds = %58, %90
%62 = phi i8* [ %56, %58 ], [ %92, %90 ]
%63 = phi i32 [ 0, %58 ], [ %91, %90 ]
store i8* %62, i8** %5
%64 = call i8* @strsep(i8** %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%65 = icmp ne i8* %64, null
%66 = load i8*, i8** %5
%67 = icmp ne i8* %66, null
%68 = select i1 %65, i1 %67, i1 false
br i1 %68, label %69, label %90
69: ; preds = %61
%70 = add nsw i32 %63, 1
br i1 %60, label %76, label %71
71: ; preds = %69
%72 = call i32 @strtoul(i8* nocapture %64, i32* null, i32 10)
%73 = icmp eq i32 %72, %53
br i1 %73, label %74, label %90
74: ; preds = %71
%75 = load i8*, i8** %5
br label %79
76: ; preds = %69
%77 = call i64 @strcasecmp(i8* %64, i8* %1)
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %90
79: ; preds = %76, %74
%80 = phi i8* [ %75, %74 ], [ %66, %76 ]
%81 = load i8, i8* %80
%82 = call i64 @isspace(i8 signext %81)
%83 = icmp eq i64 %82, 0
br i1 %83, label %97, label %84
84: ; preds = %79, %84
%85 = load i8*, i8** %5
%86 = getelementptr inbounds i8, i8* %85, i64 1
store i8* %86, i8** %5
%87 = load i8, i8* %86
%88 = call i64 @isspace(i8 signext %87)
%89 = icmp eq i64 %88, 0
br i1 %89, label %97, label %84
90: ; preds = %71, %76, %61
%91 = phi i32 [ %63, %61 ], [ %70, %76 ], [ %70, %71 ]
%92 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%93 = icmp eq i8* %92, null
br i1 %93, label %94, label %61
94: ; preds = %90, %52
%95 = phi i32 [ 0, %52 ], [ %91, %90 ]
%96 = add nsw i32 %95, -1
br label %149
97: ; preds = %84, %79
%98 = load i8*, i8** %5
%99 = call i8* @strdup(i8* %98)
br label %155
100: ; preds = %45
%101 = icmp eq i32 %46, -1
br i1 %101, label %106, label %102
102: ; preds = %100
%103 = icmp sgt i32 %20, 0
br i1 %103, label %104, label %149
104: ; preds = %102
%105 = zext i32 %20 to i64
br label %109
106: ; preds = %49, %100
%107 = load i32, i32* @stderr
%108 = tail call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.9, i64 0, i64 0), i8* %1)
br label %155
109: ; preds = %104, %141
%110 = phi i64 [ 0, %104 ], [ %147, %141 ]
%111 = phi i32 [ 0, %104 ], [ %146, %141 ]
%112 = icmp eq i32 %111, %46
br i1 %112, label %113, label %141
113: ; preds = %109
%114 = trunc i64 %110 to i32
%115 = icmp sgt i32 %20, %114
br i1 %115, label %116, label %126
116: ; preds = %113, %121
%117 = phi i64 [ %122, %121 ], [ %110, %113 ]
%118 = getelementptr inbounds i8, i8* %21, i64 %117
%119 = load i8, i8* %118
%120 = icmp eq i8 %119, 0
br i1 %120, label %124, label %121
121: ; preds = %116
%122 = add nuw nsw i64 %117, 1
%123 = icmp eq i64 %122, %105
br i1 %123, label %126, label %116
124: ; preds = %116
%125 = trunc i64 %117 to i32
br label %126
126: ; preds = %121, %124, %113
%127 = phi i32 [ %114, %113 ], [ %125, %124 ], [ %20, %121 ]
%128 = sub nsw i32 %127, %114
%129 = add nsw i32 %128, 1
%130 = tail call i8* @malloc(i32 %129)
%131 = icmp eq i8* %130, null
br i1 %131, label %132, label %135
132: ; preds = %126
%133 = load i32, i32* @stderr
%134 = tail call i32 (i32, i8*, ...) @fprintf(i32 %133, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %155
135: ; preds = %126
%136 = and i64 %110, 4294967295
%137 = getelementptr inbounds i8, i8* %21, i64 %136
%138 = tail call i32 @memcpy(i8* %130, i8* %137, i32 %128)
%139 = sext i32 %128 to i64
%140 = getelementptr inbounds i8, i8* %130, i64 %139
store i8 0, i8* %140
br label %155
141: ; preds = %109
%142 = getelementptr inbounds i8, i8* %21, i64 %110
%143 = load i8, i8* %142
%144 = icmp eq i8 %143, 0
%145 = zext i1 %144 to i32
%146 = add nuw nsw i32 %111, %145
%147 = add nuw nsw i64 %110, 1
%148 = icmp eq i64 %147, %105
br i1 %148, label %149, label %109
149: ; preds = %141, %102, %94
%150 = phi i32 [ %96, %94 ], [ 0, %102 ], [ %146, %141 ]
%151 = load i32, i32* @stderr
%152 = call i32 (i32, i8*, ...) @fprintf(i32 %151, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.11, i64 0, i64 0), i8* %1, i8* %0, i32 %150)
br label %155
153: ; preds = %23, %15
%154 = call i32 @fclose(i32* %7)
br label %159
155: ; preds = %106, %132, %149, %135, %97, %32
%156 = phi i8* [ null, %32 ], [ %99, %97 ], [ null, %149 ], [ null, %106 ], [ %130, %135 ], [ null, %132 ]
%157 = call i32 @fclose(i32* %7)
%158 = call i32 @free(i8* %21)
br label %159
159: ; preds = %153, %9, %155
%160 = phi i8* [ null, %9 ], [ %156, %155 ], [ null, %153 ]
ret i8* %160
}