#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 *getenv(char *);
size_t strlen(char *);
const char *get_base_path(int drive) {
  char env[15] = "EMU2_DRIVE_"
                 "\0\0";
  env[strlen(env)] = drive + 'A';
  char *base = getenv(env);
  if (!base)
    return ".";
  return base;
}


x86 assembly (clang, -O0):
<get_base_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x1b(%rbp)
mov    0xecc(%rip),%eax
mov    %eax,-0x13(%rbp)
mov    0xec6(%rip),%ax
mov    %ax,-0xf(%rbp)
mov    0xebe(%rip),%al
mov    %al,-0xd(%rbp)
mov    -0xc(%rbp),%eax
add    $0x41,%eax
mov    %al,-0x29(%rbp)
lea    -0x1b(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x29(%rbp),%cl
mov    %cl,-0x1b(%rbp,%rax,1)
lea    -0x1b(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1194 <get_base_path+0x74>
lea    0xe84(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119c <get_base_path+0x7c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_base_path>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movabs $0x4952445f32554d45,%rax
44 52 49
mov    %rax,0x8(%rsp)
movq   $0x5f455649,0xf(%rsp)
45 5f
add    $0x41,%bl
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %bl,0x8(%rsp,%rax,1)
mov    %r14,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xea8(%rip),%rcx
cmove  %rcx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.get_base_path.env = [15 x i8] c"EMU2_DRIVE_\00\00\00\00"
@.str = [2 x i8] c".\00"
define i8* @get_base_path(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [15 x i8]
%5 = alloca i8*
store i32 %0, i32* %3
%6 = bitcast [15 x i8]* %4 to i8*
%7 = load i32, i32* %3
%8 = add nsw i32 %7, 65
%9 = trunc i32 %8 to i8
%10 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%11 = call i64 @strlen(i8* %10)
%12 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 %11
store i8 %9, i8* %12
%13 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%14 = call i8* @getenv(i8* %13)
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2
br label %20
18: ; preds = %1
%19 = load i8*, i8** %5
store i8* %19, i8** %2
br label %20
20: ; preds = %18, %17
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
@__const.get_base_path.env = [15 x i8] c"EMU2_DRIVE_\00\00\00\00"
@.str = [2 x i8] c".\00"
define i8* @get_base_path(i32 %0) {
%2 = alloca [15 x i8]
%3 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 0
%4 = trunc i32 %0 to i8
%5 = add i8 %4, 65
%6 = call i64 @strlen(i8* %3)
%7 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 %6
store i8 %5, i8* %7
%8 = call i8* @getenv(i8* %3)
%9 = icmp eq i8* %8, null
%10 = select i1 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %8
ret i8* %10
}