#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*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ stderr;
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int getIndexofElektraRoot(char *cmakeCacheFilename) {
  FILE *input = NULL;
  if (!cmakeCacheFilename) {
    cmakeCacheFilename = "CMakeCache.txt";
  }
  input = fopen(cmakeCacheFilename, "r");
  if (!input) {
    fprintf(stderr, "fopen Error: CmakeCacheFile %s not found\n",
            cmakeCacheFilename);
    return -1;
  }
  char line[1024 + 1];
  int lenCmakecacheVar = strlen("Elektra_SOURCE_DIR");
  bool foundCmakecacheVar = false;
  while (fgets(line, 1024, input)) {
    if (strncmp("Elektra_SOURCE_DIR", line, lenCmakecacheVar) == 0) {
      foundCmakecacheVar = true;
      break;
    }
  }
  fclose(input);
  if (!foundCmakecacheVar) {
    fprintf(stderr, "%s parse Error: Variable %s not found\n", "CMakeCache.txt",
            "Elektra_SOURCE_DIR");
    return -1;
  }
  char *CmakecacheVarValue = line;
  while (*CmakecacheVarValue && *CmakecacheVarValue != '=') {
    ++CmakecacheVarValue;
  }
  ++CmakecacheVarValue;
  return strlen(CmakecacheVarValue);
}


x86 assembly (clang, -O0):
<getIndexofElektraRoot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118d <getIndexofElektraRoot+0x2d>
lea    0xe77(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d3 <getIndexofElektraRoot+0x73>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1316 <getIndexofElektraRoot+0x1b6>
lea    0xe61(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x424(%rbp)
movl   $0x0,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1245 <getIndexofElektraRoot+0xe5>
lea    -0x420(%rbp),%rsi
mov    -0x424(%rbp),%edx
lea    0xe19(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1240 <getIndexofElektraRoot+0xe0>
movl   $0x1,-0x428(%rbp)
jmp    1245 <getIndexofElektraRoot+0xe5>
jmp    11ef <getIndexofElektraRoot+0x8f>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x428(%rbp)
jne    128c <getIndexofElektraRoot+0x12c>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
lea    0xd8e(%rip),%rdx
lea    0xdc2(%rip),%rcx
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1316 <getIndexofElektraRoot+0x1b6>
lea    -0x420(%rbp),%rax
mov    %rax,-0x430(%rbp)
mov    -0x430(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x431(%rbp)
je     12cb <getIndexofElektraRoot+0x16b>
mov    -0x430(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3d,%eax
setne  %al
mov    %al,-0x431(%rbp)
mov    -0x431(%rbp),%al
test   $0x1,%al
jne    12de <getIndexofElektraRoot+0x17e>
jmp    12f5 <getIndexofElektraRoot+0x195>
mov    -0x430(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x430(%rbp)
jmp    129a <getIndexofElektraRoot+0x13a>
mov    -0x430(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x430(%rbp)
mov    -0x430(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getIndexofElektraRoot>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
test   %rdi,%rdi
lea    0xe89(%rip),%rbx
cmovne %rdi,%rbx
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1202 <getIndexofElektraRoot+0xa2>
mov    %rax,%r15
lea    0xea2(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1223 <getIndexofElektraRoot+0xc3>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11b0 <getIndexofElektraRoot+0x50>
mov    %r15,%rdi
call   1040 <fclose@plt>
lea    0x1(%rsp),%rdi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl -0x1(%rdi),%eax
test   %al,%al
je     1257 <getIndexofElektraRoot+0xf7>
cmp    $0x3d,%al
je     1257 <getIndexofElektraRoot+0xf7>
add    $0x1,%rdi
jmp    11f0 <getIndexofElektraRoot+0x90>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    125c <getIndexofElektraRoot+0xfc>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
lea    0xdbe(%rip),%rdx
lea    0xdf2(%rip),%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    125c <getIndexofElektraRoot+0xfc>
call   1050 <strlen@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"CMakeCache.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [42 x i8] c"fopen Error: CmakeCacheFile %s not found\0A\00"
@.str.3 = [19 x i8] c"Elektra_SOURCE_DIR\00"
@.str.4 = [39 x i8] c"%s parse Error: Variable %s not found\0A\00"
define i32 @getIndexofElektraRoot(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [1025 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %3
store i32* null, i32** %4
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %3
br label %12
12: ; preds = %11, %1
%13 = load i8*, i8** %3
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %4
%15 = load i32*, i32** %4
%16 = icmp ne i32* %15, null
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %3
%20 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %19)
store i32 -1, i32* %2
br label %65
21: ; preds = %12
%22 = call i32 @strlen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 %22, i32* %6
store i32 0, i32* %7
br label %23
23: ; preds = %34, %21
%24 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%25 = load i32*, i32** %4
%26 = call i64 @fgets(i8* %24, i32 1024, i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %23
%29 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%30 = load i32, i32* %6
%31 = call i64 @strncmp(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %29, i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 1, i32* %7
br label %35
34: ; preds = %28
br label %23
35: ; preds = %33, %23
%36 = load i32*, i32** %4
%37 = call i32 @fclose(i32* %36)
%38 = load i32, i32* %7
%39 = icmp ne i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %35
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %65
43: ; preds = %35
%44 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
store i8* %44, i8** %8
br label %45
45: ; preds = %57, %43
%46 = load i8*, i8** %8
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %45
%51 = load i8*, i8** %8
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 61
br label %55
55: ; preds = %50, %45
%56 = phi i1 [ false, %45 ], [ %54, %50 ]
br i1 %56, label %57, label %60
57: ; preds = %55
%58 = load i8*, i8** %8
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %8
br label %45
60: ; preds = %55
%61 = load i8*, i8** %8
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %8
%63 = load i8*, i8** %8
%64 = call i32 @strlen(i8* %63)
store i32 %64, i32* %2
br label %65
65: ; preds = %60, %40, %17
%66 = load i32, i32* %2
ret i32 %66
}

LLVM IR (-O2):
@.str = [15 x i8] c"CMakeCache.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [42 x i8] c"fopen Error: CmakeCacheFile %s not found\0A\00"
@.str.3 = [19 x i8] c"Elektra_SOURCE_DIR\00"
@.str.4 = [39 x i8] c"%s parse Error: Variable %s not found\0A\00"
define i32 @getIndexofElektraRoot(i8* %0) {
%2 = alloca [1025 x i8]
%3 = icmp eq i8* %0, null
%4 = select i1 %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0
%5 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %35
10: ; preds = %1
%11 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 0
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %16, %10
%14 = call i64 @fgets(i8* %11, i32 1024, i32* %5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %13
%17 = call i64 @strncmp(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %11, i32 %12)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %13
19: ; preds = %16
%20 = call i32 @fclose(i32* %5)
br label %25
21: ; preds = %13
%22 = call i32 @fclose(i32* %5)
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %33
25: ; preds = %19, %28
%26 = phi i8* [ %29, %28 ], [ %11, %19 ]
%27 = load i8, i8* %26
switch i8 %27, label %28 [
i8 0, label %30
i8 61, label %30
]
28: ; preds = %25
%29 = getelementptr inbounds i8, i8* %26, i64 1
br label %25
30: ; preds = %25, %25
%31 = getelementptr inbounds i8, i8* %26, i64 1
%32 = call i32 @strlen(i8* %31)
br label %33
33: ; preds = %30, %21
%34 = phi i32 [ %32, %30 ], [ -1, %21 ]
br label %35
35: ; preds = %33, %7
%36 = phi i32 [ %34, %33 ], [ -1, %7 ]
ret i32 %36
}