#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, char *);
int snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
int main() {
  char path[80];
  char *envvar = "PATH";
  if (!getenv(envvar)) {
    fprintf(stderr, "The environment variable %s was not found.\n", envvar);
    exit(1);
  }
  if (snprintf(path, 80, "%s", getenv(envvar)) >= 80) {
    fprintf(stderr, "BUFSIZE of %d was too small. Aborting\n", 80);
    exit(1);
  }
  printf("PATH: %s\n", path);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    11a2 <main+0x52>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    -0x68(%rbp),%rdx
lea    0xe74(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x68(%rbp),%rdi
call   1030 <getenv@plt>
mov    -0x70(%rbp),%rdi
mov    %rax,%rcx
mov    $0x50,%esi
lea    0xe6b(%rip),%rdx
call   1050 <snprintf@plt>
cmp    $0x50,%eax
jl     11fa <main+0xaa>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
mov    $0x50,%edx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    -0x60(%rbp),%rsi
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x58,%rsp
lea    0xea5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1197 <main+0x47>
lea    0xec5(%rip),%rdx
mov    %rsp,%rdi
mov    $0x50,%esi
mov    %rax,%rcx
call   1050 <snprintf@plt>
cmp    $0x50,%eax
jge    11bf <main+0x6f>
lea    0xed3(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
ret
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
lea    0xe52(%rip),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
mov    $0x50,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"PATH\00"
@stderr = global i32 0
@.str.1 = [44 x i8] c"The environment variable %s was not found.\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [39 x i8] c"BUFSIZE of %d was too small. Aborting\0A\00"
@.str.4 = [10 x i8] c"PATH: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = load i8*, i8** %3
%5 = call i8* @getenv(i8* %4)
%6 = icmp ne i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %3
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = call i8* @getenv(i8* %14)
%16 = call i32 @snprintf(i8* %13, i32 80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = icmp sge i32 %16, 80
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 80)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %12
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"PATH\00"
@stderr = global i32 0
@.str.1 = [44 x i8] c"The environment variable %s was not found.\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [39 x i8] c"BUFSIZE of %d was too small. Aborting\0A\00"
@.str.4 = [10 x i8] c"PATH: %s\0A\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = call i32 @snprintf(i8* %2, i32 80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%11 = icmp sgt i32 %10, 79
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 80)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %9
%17 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %2)
ret i32 0
}