#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 *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
int /*<<< orphan*/ strlen(char *);
char *cb_get_env(char *filename, int num) {
  char *path = NULL;
  char buff[256];
  switch (num) {
  case 1:
    path = getenv("OPNCBL_COBDIR");
    break;
  case 2:
    path = getenv("OPNCBL_SRCDIR");
    break;
  case 3:
    path = getenv("OPNCBL_EROUT");
    break;
  default:
    break;
  }
  if (path == NULL)
    return strdup(filename);
  memset(buff, 0, strlen(buff));
  strcpy(buff, path);
  strcat(buff, filename);
  return strdup(buff);
}


x86 assembly (clang, -O0):
<cb_get_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x124(%rbp)
sub    $0x1,%eax
je     11b9 <cb_get_env+0x59>
jmp    1191 <cb_get_env+0x31>
mov    -0x124(%rbp),%eax
sub    $0x2,%eax
je     11ce <cb_get_env+0x6e>
jmp    11a5 <cb_get_env+0x45>
mov    -0x124(%rbp),%eax
sub    $0x3,%eax
je     11e3 <cb_get_env+0x83>
jmp    11f8 <cb_get_env+0x98>
lea    0xe40(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
jmp    11fd <cb_get_env+0x9d>
lea    0xe39(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
jmp    11fd <cb_get_env+0x9d>
lea    0xe32(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
jmp    11fd <cb_get_env+0x9d>
jmp    11fd <cb_get_env+0x9d>
cmpq   $0x0,-0x20(%rbp)
jne    121a <cb_get_env+0xba>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1274 <cb_get_env+0x114>
lea    -0x120(%rbp),%rax
mov    %rax,-0x130(%rbp)
lea    -0x120(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x130(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
lea    -0x120(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cb_get_env>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
add    $0xffffffff,%esi
cmp    $0x2,%esi
ja     11d7 <cb_get_env+0x77>
movslq %esi,%rax
lea    0xeab(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11d7 <cb_get_env+0x77>
mov    %rax,%r14
mov    %rsp,%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <strcat@plt>
mov    %r15,%rdi
call   1080 <strdup@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <strdup@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"OPNCBL_COBDIR\00"
@.str.1 = [14 x i8] c"OPNCBL_SRCDIR\00"
@.str.2 = [13 x i8] c"OPNCBL_EROUT\00"
define i8* @cb_get_env(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [256 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* null, i8** %6
%8 = load i32, i32* %5
switch i32 %8, label %15 [
i32 1, label %9
i32 2, label %11
i32 3, label %13
]
9: ; preds = %2
%10 = call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %6
br label %16
11: ; preds = %2
%12 = call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i8* %12, i8** %6
br label %16
13: ; preds = %2
%14 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i8* %14, i8** %6
br label %16
15: ; preds = %2
br label %16
16: ; preds = %15, %13, %11, %9
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = call i8* @strdup(i8* %20)
store i8* %21, i8** %3
br label %35
22: ; preds = %16
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @memset(i8* %23, i32 0, i32 %25)
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%28 = load i8*, i8** %6
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%31 = load i8*, i8** %4
%32 = call i32 @strcat(i8* %30, i8* %31)
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%34 = call i8* @strdup(i8* %33)
store i8* %34, i8** %3
br label %35
35: ; preds = %22, %19
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
@.str = [14 x i8] c"OPNCBL_COBDIR\00"
@.str.1 = [14 x i8] c"OPNCBL_SRCDIR\00"
@.str.2 = [13 x i8] c"OPNCBL_EROUT\00"
@reltable.cb_get_env = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @reltable.cb_get_env to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.cb_get_env to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.cb_get_env to i64)) to i32)]
define noalias i8* @cb_get_env(i8* %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = add i32 %1, -1
%6 = icmp ult i32 %5, 3
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = sext i32 %5 to i64
%9 = shl i64 %8, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.cb_get_env to i8*), i64 %9)
%11 = tail call i8* @getenv(i8* %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2, %7
%14 = tail call i8* @strdup(i8* %0)
br label %21
15: ; preds = %7
%16 = call i32 @strlen(i8* %4)
%17 = call i32 @memset(i8* %4, i32 0, i32 %16)
%18 = call i32 @strcpy(i8* %4, i8* %11)
%19 = call i32 @strcat(i8* %4, i8* %0)
%20 = call i8* @strdup(i8* %4)
br label %21
21: ; preds = %15, %13
%22 = phi i8* [ %14, %13 ], [ %20, %15 ]
ret i8* %22
}