#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 EXIT_SUCCESS;
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  printf("main    HOME    = %s\n", getenv("HOME"));
  printf("main    PATH    = %s\n", getenv("PATH"));
  printf("main    TERM    = %s\n", getenv("TERM"));
  printf("main    DISPLAY = %s\n", getenv("DISPLAY"));
  printf("--- Let's fake shell command prompt with system\n");
  printf("$ ls -li system.c\n");
  system("ls -li system.c");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xec7(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xec5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xec3(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xed6(%rip),%rdi
call   1040 <system@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xece(%rip),%rdi
call   1030 <getenv@plt>
lea    0xeac(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xecc(%rip),%rdi
call   1030 <getenv@plt>
lea    0xeaa(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xeca(%rip),%rdi
call   1030 <getenv@plt>
lea    0xea8(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xec8(%rip),%rdi
call   1030 <getenv@plt>
lea    0xea6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xeb3(%rip),%rdi
call   1040 <puts@plt>
lea    0xed7(%rip),%rdi
call   1040 <puts@plt>
lea    0xecd(%rip),%rdi
call   1050 <system@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"main HOME = %s\0A\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [22 x i8] c"main PATH = %s\0A\00"
@.str.3 = [5 x i8] c"PATH\00"
@.str.4 = [22 x i8] c"main TERM = %s\0A\00"
@.str.5 = [5 x i8] c"TERM\00"
@.str.6 = [22 x i8] c"main DISPLAY = %s\0A\00"
@.str.7 = [8 x i8] c"DISPLAY\00"
@.str.8 = [49 x i8] c"--- Let's fake shell command prompt with system\0A\00"
@.str.9 = [19 x i8] c"$ ls -li system.c\0A\00"
@.str.10 = [16 x i8] c"ls -li system.c\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%12 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
%16 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
%17 = load i32, i32* @EXIT_SUCCESS
ret i32 %17
}

LLVM IR (-O2):
@.str = [22 x i8] c"main HOME = %s\0A\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [22 x i8] c"main PATH = %s\0A\00"
@.str.3 = [5 x i8] c"PATH\00"
@.str.4 = [22 x i8] c"main TERM = %s\0A\00"
@.str.5 = [5 x i8] c"TERM\00"
@.str.6 = [22 x i8] c"main DISPLAY = %s\0A\00"
@.str.7 = [8 x i8] c"DISPLAY\00"
@.str.10 = [16 x i8] c"ls -li system.c\00"
@EXIT_SUCCESS = global i32 0
@str = [48 x i8] c"--- Let's fake shell command prompt with system\00"
@str.11 = [18 x i8] c"$ ls -li system.c\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %9)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.11, i64 0, i64 0))
%13 = tail call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
%14 = load i32, i32* @EXIT_SUCCESS
ret i32 %14
}