#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 */
int /*<<< orphan*/ DL_TrimQuotesInPlace(char *);
char *getenv(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int XTL_GetEnvVariable(char *name, char *var, int size) {
  char *p;
  char *retval = NULL;
  if (name == NULL || var == NULL || size < 1)
    return -3;
  p = getenv(name);
  if (p == NULL)
    return -1;
  if (strlen(p) < size)
    strcpy(var, p);
  else
    return -2;
  DL_TrimQuotesInPlace(var);
  return 0;
}


x86 assembly (clang, -O0):
<XTL_GetEnvVariable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117b <XTL_GetEnvVariable+0x3b>
cmpq   $0x0,-0x18(%rbp)
je     117b <XTL_GetEnvVariable+0x3b>
cmpl   $0x1,-0x1c(%rbp)
jge    1187 <XTL_GetEnvVariable+0x47>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11eb <XTL_GetEnvVariable+0xab>
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ab <XTL_GetEnvVariable+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <XTL_GetEnvVariable+0xab>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
cmp    -0x1c(%rbp),%eax
jge    11cf <XTL_GetEnvVariable+0x8f>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    11db <XTL_GetEnvVariable+0x9b>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11eb <XTL_GetEnvVariable+0xab>
mov    -0x18(%rbp),%rdi
call   1060 <DL_TrimQuotesInPlace@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XTL_GetEnvVariable>:
push   %rbp
push   %r14
push   %rbx
mov    $0xfffffffd,%eax
test   %rdi,%rdi
je     1198 <XTL_GetEnvVariable+0x58>
mov    %rsi,%r14
test   %rsi,%rsi
je     1198 <XTL_GetEnvVariable+0x58>
mov    %edx,%ebp
test   %edx,%edx
jle    1198 <XTL_GetEnvVariable+0x58>
call   1030 <getenv@plt>
test   %rax,%rax
je     1193 <XTL_GetEnvVariable+0x53>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    $0xfffffffe,%eax
cmp    %ebp,%ecx
jge    1198 <XTL_GetEnvVariable+0x58>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1060 <DL_TrimQuotesInPlace@plt>
xor    %eax,%eax
jmp    1198 <XTL_GetEnvVariable+0x58>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @XTL_GetEnvVariable(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* null, i8** %9
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %18, label %12
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %15, %12, %3
store i32 -3, i32* %4
br label %38
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = call i8* @getenv(i8* %20)
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 -1, i32* %4
br label %38
25: ; preds = %19
%26 = load i8*, i8** %8
%27 = call i32 @strlen(i8* %26)
%28 = load i32, i32* %7
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i8*, i8** %6
%32 = load i8*, i8** %8
%33 = call i32 @strcpy(i8* %31, i8* %32)
br label %35
34: ; preds = %25
store i32 -2, i32* %4
br label %38
35: ; preds = %30
%36 = load i8*, i8** %6
%37 = call i32 @DL_TrimQuotesInPlace(i8* %36)
store i32 0, i32* %4
br label %38
38: ; preds = %35, %34, %24, %18
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
define i32 @XTL_GetEnvVariable(i8* %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
%7 = icmp slt i32 %2, 1
%8 = or i1 %6, %7
br i1 %8, label %18, label %9
9: ; preds = %3
%10 = tail call i8* @getenv(i8* %0)
%11 = icmp eq i8* %10, null
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = tail call i32 @strlen(i8* %10)
%14 = icmp slt i32 %13, %2
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 @strcpy(i8* %1, i8* %10)
%17 = tail call i32 @DL_TrimQuotesInPlace(i8* %1)
br label %18
18: ; preds = %12, %9, %3, %15
%19 = phi i32 [ 0, %15 ], [ -3, %3 ], [ -1, %9 ], [ -2, %12 ]
ret i32 %19
}