#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*/ snprintf(char *, size_t, char *, char *, ...);
char *oclGetProgramPath(char *path, char *name, size_t path_size) {
  char *base = getenv("OCL_APP_BUILD");
  if (base != NULL) {
    snprintf(path, path_size, "%s/%s", base, name);
  } else {
    snprintf(path, path_size, "./%s", name);
  }
  return path;
}


x86 assembly (clang, -O0):
<oclGetProgramPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xec5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1172 <oclGetProgramPath+0x52>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xea8(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    118c <oclGetProgramPath+0x6c>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rcx
lea    0xe8f(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oclGetProgramPath>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xecb(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     115b <oclGetProgramPath+0x3b>
lea    0xec8(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rax,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    1172 <oclGetProgramPath+0x52>
lea    0xeb2(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"OCL_APP_BUILD\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [5 x i8] c"./%s\00"
define i8* @oclGetProgramPath(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %7
%9 = load i8*, i8** %7
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = load i64, i64* %6
%14 = load i8*, i8** %7
%15 = load i8*, i8** %5
%16 = call i32 (i8*, i64, i8*, i8*, ...) @snprintf(i8* %12, i64 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %15)
br label %22
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = load i64, i64* %6
%20 = load i8*, i8** %5
%21 = call i32 (i8*, i64, i8*, i8*, ...) @snprintf(i8* %18, i64 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %17, %11
%23 = load i8*, i8** %4
ret i8* %23
}

LLVM IR (-O2):
@.str = [14 x i8] c"OCL_APP_BUILD\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [5 x i8] c"./%s\00"
define i8* @oclGetProgramPath(i8* returned %0, i8* %1, i64 %2) {
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 (i8*, i64, i8*, i8*, ...) @snprintf(i8* %0, i64 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %1)
br label %10
8: ; preds = %3
%9 = tail call i32 (i8*, i64, i8*, i8*, ...) @snprintf(i8* %0, i64 %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %10
10: ; preds = %8, %6
ret i8* %0
}