#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 */
char *getLogPath(char *);
char *getenv(char *);
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
char *getConfig(int code) {
  char *home;
  switch (code) {
  case 0:
    home = getenv("LUMBHOME");
    if (home)
      return home;
    else {
      home = malloc(sizeof(char) * 100);
      strcat(home, getenv("HOME"));
      strcat(home, "/");
      strcat(home, ".lumber/");
    }
    break;
  case 1:
    home = getLogPath("default");
    break;
  case 2:
    return getenv("HISTFILE");
  }
  return home;
}


x86 assembly (clang, -O0):
<getConfig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     1180 <getConfig+0x40>
jmp    115e <getConfig+0x1e>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
je     11fb <getConfig+0xbb>
jmp    116f <getConfig+0x2f>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     1210 <getConfig+0xd0>
jmp    1225 <getConfig+0xe5>
lea    0xe79(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a8 <getConfig+0x68>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    122d <getConfig+0xed>
mov    $0x64,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe3f(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1060 <strcat@plt>
jmp    1225 <getConfig+0xe5>
lea    0xe10(%rip),%rdi
call   1050 <getLogPath@plt>
mov    %rax,-0x18(%rbp)
jmp    1225 <getConfig+0xe5>
lea    0xe03(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
jmp    122d <getConfig+0xed>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getConfig>:
cmp    $0x2,%edi
je     11aa <getConfig+0x6a>
cmp    $0x1,%edi
je     11b6 <getConfig+0x76>
push   %rbx
test   %edi,%edi
jne    11a5 <getConfig+0x65>
lea    0xeaa(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a5 <getConfig+0x65>
mov    $0x64,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
lea    0xe8d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <strcat@plt>
lea    0xe82(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
ret
lea    0xe69(%rip),%rdi
jmp    1030 <getenv@plt>
lea    0xe55(%rip),%rdi
jmp    1050 <getLogPath@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"LUMBHOME\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [9 x i8] c".lumber/\00"
@.str.4 = [8 x i8] c"default\00"
@.str.5 = [9 x i8] c"HISTFILE\00"
define i8* @getConfig(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
%5 = load i32, i32* %3
switch i32 %5, label %26 [
i32 0, label %6
i32 1, label %22
i32 2, label %24
]
6: ; preds = %1
%7 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = load i8*, i8** %4
store i8* %11, i8** %2
br label %28
12: ; preds = %6
%13 = call i8* @malloc(i32 100)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @strcat(i8* %14, i8* %15)
%17 = load i8*, i8** %4
%18 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = load i8*, i8** %4
%20 = call i32 @strcat(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %12
br label %26
22: ; preds = %1
%23 = call i8* @getLogPath(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
store i8* %23, i8** %4
br label %26
24: ; preds = %1
%25 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
store i8* %25, i8** %2
br label %28
26: ; preds = %1, %22, %21
%27 = load i8*, i8** %4
store i8* %27, i8** %2
br label %28
28: ; preds = %26, %24, %10
%29 = load i8*, i8** %2
ret i8* %29
}

LLVM IR (-O2):
@.str = [9 x i8] c"LUMBHOME\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [9 x i8] c".lumber/\00"
@.str.4 = [8 x i8] c"default\00"
@.str.5 = [9 x i8] c"HISTFILE\00"
define i8* @getConfig(i32 %0) {
switch i32 %0, label %15 [
i32 0, label %2
i32 1, label %11
i32 2, label %13
]
2: ; preds = %1
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %15
5: ; preds = %2
%6 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @strcat(i8* %6, i8* %7)
%9 = tail call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @strcat(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %15
11: ; preds = %1
%12 = tail call i8* @getLogPath(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %15
13: ; preds = %1
%14 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %15
15: ; preds = %5, %11, %1, %2, %13
%16 = phi i8* [ %14, %13 ], [ %3, %2 ], [ undef, %1 ], [ %12, %11 ], [ %6, %5 ]
ret i8* %16
}