#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
char *ltr_int_get_default_file_name(int /*<<< orphan*/ *);
int /*<<< orphan*/ ltr_int_log_message(char *, ...);
char *ltr_int_my_strcat(char *, char const *);
scalar_t__ sscanf(char *, char *, char *);
scalar_t__ strcasecmp(char *, char *);
char *ltr_int_get_app_path(const char *suffix) {
  char *fname = ltr_int_get_default_file_name(NULL);
  if (fname == NULL) {
    return NULL;
  }
  FILE *f = fopen(fname, "r");
  if (f == NULL) {
    ltr_int_log_message("Can't open file '%s'!\n", fname);
    free(fname);
    return NULL;
  }
  free(fname);
  fname = NULL;
  char key[2048];
  char val[2048];
  bool found = false;
  while (!feof(f)) {
    if (fscanf(f, "%2040s", key) == 1) {
      if (strcasecmp(key, "PREFIX") == 0) {
        if (fgets(key, 2040, f) != NULL) {
          if (sscanf(key, " = \"%[^\"\n]", val) > 0) {
            found = true;
            break;
          }
        }
      }
    }
  }
  fclose(f);
  if (found) {
    return ltr_int_my_strcat(val, suffix);
  }
  ltr_int_log_message("Couldn't find prefix!\n");
  return NULL;
}


x86 assembly (clang, -O0):
<ltr_int_get_app_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <ltr_int_get_default_file_name@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e4 <ltr_int_get_app_path+0x34>
movq   $0x0,-0x8(%rbp)
jmp    134c <ltr_int_get_app_path+0x19c>
mov    -0x18(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    122b <ltr_int_get_app_path+0x7b>
mov    -0x18(%rbp),%rsi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1060 <ltr_int_log_message@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    134c <ltr_int_get_app_path+0x19c>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1024(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1264 <ltr_int_get_app_path+0xb4>
jmp    1307 <ltr_int_get_app_path+0x157>
mov    -0x20(%rbp),%rdi
lea    -0x820(%rbp),%rdx
lea    0xda3(%rip),%rsi
call   1080 <fscanf@plt>
cmp    $0x1,%eax
jne    1302 <ltr_int_get_app_path+0x152>
lea    -0x820(%rbp),%rdi
lea    0xd8e(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    12fd <ltr_int_get_app_path+0x14d>
lea    -0x820(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x7f8,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     12f8 <ltr_int_get_app_path+0x148>
lea    -0x820(%rbp),%rdi
lea    -0x1020(%rbp),%rdx
lea    0xd52(%rip),%rsi
call   10b0 <sscanf@plt>
cmp    $0x0,%rax
jle    12f3 <ltr_int_get_app_path+0x143>
movl   $0x1,-0x1024(%rbp)
jmp    1307 <ltr_int_get_app_path+0x157>
jmp    12f8 <ltr_int_get_app_path+0x148>
jmp    12fd <ltr_int_get_app_path+0x14d>
jmp    1302 <ltr_int_get_app_path+0x152>
jmp    1246 <ltr_int_get_app_path+0x96>
mov    -0x20(%rbp),%rdi
call   1070 <fclose@plt>
cmpl   $0x0,-0x1024(%rbp)
je     1336 <ltr_int_get_app_path+0x186>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10c0 <ltr_int_my_strcat@plt>
mov    %rax,-0x8(%rbp)
jmp    134c <ltr_int_get_app_path+0x19c>
lea    0xcf5(%rip),%rdi
mov    $0x0,%al
call   1060 <ltr_int_log_message@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ltr_int_get_app_path>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <ltr_int_get_default_file_name@plt>
test   %rax,%rax
je     1235 <ltr_int_get_app_path+0x85>
mov    %rax,%rbp
lea    0xe24(%rip),%rsi
mov    %rax,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     121a <ltr_int_get_app_path+0x6a>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
je     124a <ltr_int_get_app_path+0x9a>
mov    %rbx,%rdi
call   1070 <fclose@plt>
lea    0xe23(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <ltr_int_log_message@plt>
jmp    1235 <ltr_int_get_app_path+0x85>
lea    0xde1(%rip),%rdi
xor    %ebx,%ebx
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <ltr_int_log_message@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc8(%rip),%r15
lea    0x800(%rsp),%r12
lea    0xdc0(%rip),%r13
mov    %rsp,%rbp
jmp    127c <ltr_int_get_app_path+0xcc>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    1200 <ltr_int_get_app_path+0x50>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1080 <fscanf@plt>
cmp    $0x1,%eax
jne    1270 <ltr_int_get_app_path+0xc0>
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    1270 <ltr_int_get_app_path+0xc0>
mov    %r12,%rdi
mov    $0x7f8,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1270 <ltr_int_get_app_path+0xc0>
mov    %r12,%rdi
lea    0xd69(%rip),%rsi
mov    %rbp,%rdx
call   10b0 <sscanf@plt>
test   %rax,%rax
jle    1270 <ltr_int_get_app_path+0xc0>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    %rsp,%rdi
mov    %r14,%rsi
call   10c0 <ltr_int_my_strcat@plt>
mov    %rax,%rbx
jmp    1235 <ltr_int_get_app_path+0x85>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"Can't open file '%s'!\0A\00"
@.str.2 = [7 x i8] c"%2040s\00"
@.str.3 = [7 x i8] c"PREFIX\00"
@.str.4 = [11 x i8] c" = \22%[^\22\0A]\00"
@.str.5 = [23 x i8] c"Couldn't find prefix!\0A\00"
define i8* @ltr_int_get_app_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [2048 x i8]
%7 = alloca [2048 x i8]
%8 = alloca i32
store i8* %0, i8** %3
%9 = call i8* @ltr_int_get_default_file_name(i32* null)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i8* null, i8** %2
br label %66
13: ; preds = %1
%14 = load i8*, i8** %4
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %5
%16 = load i32*, i32** %5
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = call i32 (i8*, ...) @ltr_int_log_message(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %4
%22 = call i32 @free(i8* %21)
store i8* null, i8** %2
br label %66
23: ; preds = %13
%24 = load i8*, i8** %4
%25 = call i32 @free(i8* %24)
store i8* null, i8** %4
store i32 0, i32* %8
br label %26
26: ; preds = %54, %23
%27 = load i32*, i32** %5
%28 = call i32 @feof(i32* %27)
%29 = icmp ne i32 %28, 0
%30 = xor i1 %29, true
br i1 %30, label %31, label %55
31: ; preds = %26
%32 = load i32*, i32** %5
%33 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%34 = call i32 @fscanf(i32* %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %54
36: ; preds = %31
%37 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%38 = call i64 @strcasecmp(i8* %37, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %53
40: ; preds = %36
%41 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%42 = load i32*, i32** %5
%43 = call i32* @fgets(i8* %41, i32 2040, i32* %42)
%44 = icmp ne i32* %43, null
br i1 %44, label %45, label %52
45: ; preds = %40
%46 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%47 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%48 = call i64 @sscanf(i8* %46, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%49 = icmp sgt i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %45
store i32 1, i32* %8
br label %55
51: ; preds = %45
br label %52
52: ; preds = %51, %40
br label %53
53: ; preds = %52, %36
br label %54
54: ; preds = %53, %31
br label %26
55: ; preds = %50, %26
%56 = load i32*, i32** %5
%57 = call i32 @fclose(i32* %56)
%58 = load i32, i32* %8
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %55
%61 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%62 = load i8*, i8** %3
%63 = call i8* @ltr_int_my_strcat(i8* %61, i8* %62)
store i8* %63, i8** %2
br label %66
64: ; preds = %55
%65 = call i32 (i8*, ...) @ltr_int_log_message(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
store i8* null, i8** %2
br label %66
66: ; preds = %64, %60, %18, %12
%67 = load i8*, i8** %2
ret i8* %67
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"Can't open file '%s'!\0A\00"
@.str.2 = [7 x i8] c"%2040s\00"
@.str.3 = [7 x i8] c"PREFIX\00"
@.str.4 = [11 x i8] c" = \22%[^\22\0A]\00"
@.str.5 = [23 x i8] c"Couldn't find prefix!\0A\00"
define i8* @ltr_int_get_app_path(i8* %0) {
%2 = alloca [2048 x i8]
%3 = alloca [2048 x i8]
%4 = tail call i8* @ltr_int_get_default_file_name(i32* null)
%5 = icmp eq i8* %4, null
br i1 %5, label %41, label %6
6: ; preds = %1
%7 = tail call i32* @fopen(i8* %4, 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 = %6
%10 = tail call i32 (i8*, ...) @ltr_int_log_message(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%11 = tail call i32 @free(i8* %4)
br label %41
12: ; preds = %6
%13 = tail call i32 @free(i8* %4)
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%15 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%16 = call i32 @feof(i32* %7)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %36
18: ; preds = %12, %30
%19 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %30
21: ; preds = %18
%22 = call i64 @strcasecmp(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = call i32* @fgets(i8* %14, i32 2040, i32* %7)
%26 = icmp eq i32* %25, null
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = call i64 @sscanf(i8* %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%29 = icmp sgt i64 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %21, %27, %24, %18
%31 = call i32 @feof(i32* %7)
%32 = icmp eq i32 %31, 0
br i1 %32, label %18, label %36
33: ; preds = %27
%34 = call i32 @fclose(i32* %7)
%35 = call i8* @ltr_int_my_strcat(i8* %15, i8* %0)
br label %39
36: ; preds = %30, %12
%37 = call i32 @fclose(i32* %7)
%38 = call i32 (i8*, ...) @ltr_int_log_message(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %39
39: ; preds = %36, %33
%40 = phi i8* [ %35, %33 ], [ null, %36 ]
br label %41
41: ; preds = %9, %39, %1
%42 = phi i8* [ null, %1 ], [ null, %9 ], [ %40, %39 ]
ret i8* %42
}