#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 */
char *construct_name(char *, char *, char *);
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 *);
char *getenv(char *);
int /*<<< orphan*/ linuxtrack_log(char *);
scalar_t__ malloc(int);
int sscanf(char *, char *, char *, char *);
scalar_t__ strcasecmp(char *, char *);
char *strdup(char *);
char *linuxtrack_get_prefix() {
  char *prefix = NULL;
  char *home = getenv("HOME");
  char *cfg = (char *)"/.config/linuxtrack/linuxtrack1.conf";
  char *fname;
  FILE *f;
  char *line;
  char *val, *key;
  if (home == NULL) {
    linuxtrack_log("Please set HOME variable!\n");
    return NULL;
  }
  fname = construct_name(home, cfg, "");
  if ((f = fopen(fname, "r")) == NULL) {
    free(fname);
    return NULL;
  }
  free(fname);
  line = (char *)malloc(4096);
  val = (char *)malloc(4096);
  key = (char *)malloc(4096);
  while (!feof(f)) {
    if (fgets(line, 4095, f) != NULL) {
      if ((sscanf(line, "%s = \"%[^\"\n]", key, val) == 2) &&
          strcasecmp(key, "prefix") == 0) {
        prefix = strdup(val);
        break;
      }
    }
  }
  fclose(f);
  free(line);
  free(val);
  free(key);
  return prefix;
}


x86 assembly (clang, -O0):
<linuxtrack_get_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movq   $0x0,-0x10(%rbp)
lea    0xe29(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
lea    0xe1e(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    120f <linuxtrack_get_prefix+0x4f>
lea    0xe2d(%rip),%rdi
call   10d0 <linuxtrack_log@plt>
movq   $0x0,-0x8(%rbp)
jmp    134b <linuxtrack_get_prefix+0x18b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    0xe26(%rip),%rdx
call   1070 <construct_name@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe13(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    125b <linuxtrack_get_prefix+0x9b>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    134b <linuxtrack_get_prefix+0x18b>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    $0x1000,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    $0x1000,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    $0x1000,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12ac <linuxtrack_get_prefix+0xec>
jmp    131f <linuxtrack_get_prefix+0x15f>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0xfff,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     131a <linuxtrack_get_prefix+0x15a>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xd6c(%rip),%rsi
call   10b0 <sscanf@plt>
cmp    $0x2,%eax
jne    1315 <linuxtrack_get_prefix+0x155>
mov    -0x48(%rbp),%rdi
lea    0xd60(%rip),%rsi
call   1050 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1315 <linuxtrack_get_prefix+0x155>
mov    -0x40(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x10(%rbp)
jmp    131f <linuxtrack_get_prefix+0x15f>
jmp    131a <linuxtrack_get_prefix+0x15a>
jmp    128e <linuxtrack_get_prefix+0xce>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
mov    -0x48(%rbp),%rdi
call   1040 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linuxtrack_get_prefix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe2e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1270 <linuxtrack_get_prefix+0xb0>
lea    0xe1e(%rip),%rsi
lea    0xe56(%rip),%rdx
mov    %rax,%rdi
call   1070 <construct_name@plt>
mov    %rax,%rbp
lea    0xe45(%rip),%rsi
mov    %rax,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1040 <free@plt>
test   %rbx,%rbx
je     127c <linuxtrack_get_prefix+0xbc>
mov    $0x1000,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    $0x1000,%edi
call   10a0 <malloc@plt>
mov    %rax,%r15
mov    $0x1000,%edi
call   10a0 <malloc@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1090 <feof@plt>
xor    %r13d,%r13d
test   %eax,%eax
je     1291 <linuxtrack_get_prefix+0xd1>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r12,%rdi
call   1040 <free@plt>
jmp    127f <linuxtrack_get_prefix+0xbf>
lea    0xdb3(%rip),%rdi
call   10d0 <linuxtrack_log@plt>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdaf(%rip),%rbp
jmp    12ac <linuxtrack_get_prefix+0xec>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    124e <linuxtrack_get_prefix+0x8e>
mov    %r14,%rdi
mov    $0xfff,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12a0 <linuxtrack_get_prefix+0xe0>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
call   10b0 <sscanf@plt>
cmp    $0x2,%eax
jne    12a0 <linuxtrack_get_prefix+0xe0>
mov    %r12,%rdi
lea    0xd73(%rip),%rsi
call   1050 <strcasecmp@plt>
test   %rax,%rax
jne    12a0 <linuxtrack_get_prefix+0xe0>
mov    %r15,%rdi
call   10e0 <strdup@plt>
mov    %rax,%r13
jmp    124e <linuxtrack_get_prefix+0x8e>

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [37 x i8] c"/.config/linuxtrack/linuxtrack1.conf\00"
@.str.2 = [27 x i8] c"Please set HOME variable!\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [13 x i8] c"%s = \22%[^\22\0A]\00"
@.str.6 = [7 x i8] c"prefix\00"
define i8* @linuxtrack_get_prefix() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* null, i8** %2
%10 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %3
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8** %4
%11 = load i8*, i8** %3
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @linuxtrack_log(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %1
br label %69
15: ; preds = %0
%16 = load i8*, i8** %3
%17 = load i8*, i8** %4
%18 = call i8* @construct_name(i8* %16, i8* %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %20, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i8*, i8** %5
%24 = call i32 @free(i8* %23)
store i8* null, i8** %1
br label %69
25: ; preds = %15
%26 = load i8*, i8** %5
%27 = call i32 @free(i8* %26)
%28 = call i64 @malloc(i32 4096)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %7
%30 = call i64 @malloc(i32 4096)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %8
%32 = call i64 @malloc(i32 4096)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %9
br label %34
34: ; preds = %58, %25
%35 = load i32*, i32** %6
%36 = call i32 @feof(i32* %35)
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
br i1 %38, label %39, label %59
39: ; preds = %34
%40 = load i8*, i8** %7
%41 = load i32*, i32** %6
%42 = call i32* @fgets(i8* %40, i32 4095, i32* %41)
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %58
44: ; preds = %39
%45 = load i8*, i8** %7
%46 = load i8*, i8** %9
%47 = load i8*, i8** %8
%48 = call i32 @sscanf(i8* %45, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %46, i8* %47)
%49 = icmp eq i32 %48, 2
br i1 %49, label %50, label %57
50: ; preds = %44
%51 = load i8*, i8** %9
%52 = call i64 @strcasecmp(i8* %51, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = load i8*, i8** %8
%56 = call i8* @strdup(i8* %55)
store i8* %56, i8** %2
br label %59
57: ; preds = %50, %44
br label %58
58: ; preds = %57, %39
br label %34
59: ; preds = %54, %34
%60 = load i32*, i32** %6
%61 = call i32 @fclose(i32* %60)
%62 = load i8*, i8** %7
%63 = call i32 @free(i8* %62)
%64 = load i8*, i8** %8
%65 = call i32 @free(i8* %64)
%66 = load i8*, i8** %9
%67 = call i32 @free(i8* %66)
%68 = load i8*, i8** %2
store i8* %68, i8** %1
br label %69
69: ; preds = %59, %22, %13
%70 = load i8*, i8** %1
ret i8* %70
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [37 x i8] c"/.config/linuxtrack/linuxtrack1.conf\00"
@.str.2 = [27 x i8] c"Please set HOME variable!\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [13 x i8] c"%s = \22%[^\22\0A]\00"
@.str.6 = [7 x i8] c"prefix\00"
define noalias i8* @linuxtrack_get_prefix() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @linuxtrack_log(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %39
5: ; preds = %0
%6 = tail call i8* @construct_name(i8* %1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%8 = icmp eq i32* %7, null
%9 = tail call i32 @free(i8* %6)
br i1 %8, label %39, label %10
10: ; preds = %5
%11 = tail call i64 @malloc(i32 4096)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i64 @malloc(i32 4096)
%14 = inttoptr i64 %13 to i8*
%15 = tail call i64 @malloc(i32 4096)
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 @feof(i32* %7)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %33
19: ; preds = %10, %30
%20 = tail call i32* @fgets(i8* %12, i32 4095, i32* %7)
%21 = icmp eq i32* %20, null
br i1 %21, label %30, label %22
22: ; preds = %19
%23 = tail call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %16, i8* %14)
%24 = icmp eq i32 %23, 2
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = tail call i64 @strcasecmp(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = tail call i8* @strdup(i8* %14)
br label %33
30: ; preds = %22, %25, %19
%31 = tail call i32 @feof(i32* %7)
%32 = icmp eq i32 %31, 0
br i1 %32, label %19, label %33
33: ; preds = %30, %10, %28
%34 = phi i8* [ %29, %28 ], [ null, %10 ], [ null, %30 ]
%35 = tail call i32 @fclose(i32* %7)
%36 = tail call i32 @free(i8* %12)
%37 = tail call i32 @free(i8* %14)
%38 = tail call i32 @free(i8* %16)
br label %39
39: ; preds = %5, %33, %3
%40 = phi i8* [ null, %3 ], [ %34, %33 ], [ null, %5 ]
ret i8* %40
}