#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*/ free(char *);
char *getenv(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  char *tmp = malloc(1);
  const char *myvar = getenv("GDB_TEST_VAR");
  if (myvar != NULL)
    printf("It worked!  myvar = '%s'\n", myvar);
  else
    printf("It failed.");
  free(tmp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe95(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1196 <main+0x56>
mov    -0x20(%rbp),%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11a4 <main+0x64>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xeab(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1172 <main+0x32>
lea    0xea7(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1180 <main+0x40>
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"GDB_TEST_VAR\00"
@.str.1 = [26 x i8] c"It worked! myvar = '%s'\0A\00"
@.str.2 = [11 x i8] c"It failed.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i8* @malloc(i32 1)
store i8* %8, i8** %6
%9 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %7
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = load i8*, i8** %6
%19 = call i32 @free(i8* %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"GDB_TEST_VAR\00"
@.str.1 = [26 x i8] c"It worked! myvar = '%s'\0A\00"
@.str.2 = [11 x i8] c"It failed.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %10
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %6
%11 = tail call i32 @free(i8* %3)
ret i32 0
}