#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 */
typedef scalar_t__ time_t;
typedef int /*<<< orphan*/ time_string;
struct tm {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ WrMessage(char *);
char *getenv(char *);
struct tm *localtime(scalar_t__ *);
int /*<<< orphan*/ printf(char *, char *);
char *setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
scalar_t__ time(int /*<<< orphan*/ *);
void WrEnvironment(int argc, char *argv0) {
  char *penv;
  char *plocale;
  char time_string[40];
  time_t curr_time;
  struct tm *curr_tm;
  WrMessage("@ENVIRONMENT");
  if (argc != 0) {
    printf("Argument 0: %s\n\n", argv0);
  } else {
    WrMessage("@ENVIRONMENT-NO-COMMAND-ARGS");
  }
  penv = getenv("PATH");
  if (penv != NULL) {
    printf("PATH variable: %s\n\n", penv);
  } else {
    WrMessage("@ENVIRONMENT-NO-PATH");
  }
  penv = getenv("LANG");
  if (penv != NULL) {
    printf("LANG variable: %s\n\n", penv);
  } else {
    WrMessage("@ENVIRONMENT-NO-LANG");
  }
  curr_time = time(NULL);
  curr_tm = localtime(&curr_time);
  if (curr_time != (time_t)-1) {
    WrMessage("@ENVIRONMENT-CURR-TIME");
    strftime(time_string, sizeof(time_string), "%c", curr_tm);
    printf("Current time: %s\n\n", time_string);
  } else {
    WrMessage("@ENVIRONMENT-NO-TIME");
  }
  WrMessage("@ENVIRONMENT-SETLOCALE");
  plocale = setlocale(LC_ALL, "");
  printf("Current locale: %s\n", plocale);
  return;
}


x86 assembly (clang, -O0):
<WrEnvironment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe7a(%rip),%rdi
call   1090 <WrMessage@plt>
cmpl   $0x0,-0x4(%rbp)
je     11aa <WrEnvironment+0x3a>
mov    -0x10(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1050 <printf@plt>
jmp    11b6 <WrEnvironment+0x46>
lea    0xe6d(%rip),%rdi
call   1090 <WrMessage@plt>
lea    0xea2(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e6 <WrEnvironment+0x76>
mov    -0x18(%rbp),%rsi
lea    0xe5f(%rip),%rdi
call   1050 <printf@plt>
jmp    11f2 <WrEnvironment+0x82>
lea    0xe62(%rip),%rdi
call   1090 <WrMessage@plt>
lea    0xe8f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1222 <WrEnvironment+0xb2>
mov    -0x18(%rbp),%rsi
lea    0xe4c(%rip),%rdi
call   1050 <printf@plt>
jmp    122e <WrEnvironment+0xbe>
lea    0xe4f(%rip),%rdi
call   1090 <WrMessage@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x58(%rbp)
lea    -0x58(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0xffffffffffffffff,-0x58(%rbp)
je     128d <WrEnvironment+0x11d>
lea    0xe33(%rip),%rdi
call   1090 <WrMessage@plt>
lea    -0x50(%rbp),%rdi
mov    -0x60(%rbp),%rcx
mov    $0x28,%esi
lea    0xe31(%rip),%rdx
call   1080 <strftime@plt>
lea    -0x50(%rbp),%rsi
lea    0xe24(%rip),%rdi
call   1050 <printf@plt>
jmp    1299 <WrEnvironment+0x129>
lea    0xe26(%rip),%rdi
call   1090 <WrMessage@plt>
lea    0xe2f(%rip),%rdi
call   1090 <WrMessage@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rsi
call   1070 <setlocale@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe1d(%rip),%rdi
call   1050 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WrEnvironment>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe7e(%rip),%rdi
call   1090 <WrMessage@plt>
test   %ebp,%ebp
je     119c <WrEnvironment+0x2c>
lea    0xe7b(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
jmp    11a8 <WrEnvironment+0x38>
lea    0xe7b(%rip),%rdi
call   1090 <WrMessage@plt>
lea    0xeb0(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ca <WrEnvironment+0x5a>
lea    0xe7b(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
jmp    11d6 <WrEnvironment+0x66>
lea    0xe7e(%rip),%rdi
call   1090 <WrMessage@plt>
lea    0xeab(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11f8 <WrEnvironment+0x88>
lea    0xe76(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
jmp    1204 <WrEnvironment+0x94>
lea    0xe79(%rip),%rdi
call   1090 <WrMessage@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1040 <localtime@plt>
cmpq   $0xffffffffffffffff,0x8(%rsp)
je     125e <WrEnvironment+0xee>
mov    %rax,%rbx
lea    0xe61(%rip),%rdi
call   1090 <WrMessage@plt>
lea    0xe6c(%rip),%rdx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x28,%esi
mov    %rbx,%rcx
call   1080 <strftime@plt>
lea    0xe53(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
jmp    126a <WrEnvironment+0xfa>
lea    0xe55(%rip),%rdi
call   1090 <WrMessage@plt>
lea    0xe5e(%rip),%rdi
call   1090 <WrMessage@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
call   1070 <setlocale@plt>
lea    0xe54(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [13 x i8] c"@ENVIRONMENT\00"
@.str.1 = [17 x i8] c"Argument 0: %s\0A\0A\00"
@.str.2 = [29 x i8] c"@ENVIRONMENT-NO-COMMAND-ARGS\00"
@.str.3 = [5 x i8] c"PATH\00"
@.str.4 = [20 x i8] c"PATH variable: %s\0A\0A\00"
@.str.5 = [21 x i8] c"@ENVIRONMENT-NO-PATH\00"
@.str.6 = [5 x i8] c"LANG\00"
@.str.7 = [20 x i8] c"LANG variable: %s\0A\0A\00"
@.str.8 = [21 x i8] c"@ENVIRONMENT-NO-LANG\00"
@.str.9 = [23 x i8] c"@ENVIRONMENT-CURR-TIME\00"
@.str.10 = [3 x i8] c"%c\00"
@.str.11 = [19 x i8] c"Current time: %s\0A\0A\00"
@.str.12 = [21 x i8] c"@ENVIRONMENT-NO-TIME\00"
@.str.13 = [23 x i8] c"@ENVIRONMENT-SETLOCALE\00"
@LC_ALL = global i32 0
@.str.14 = [1 x i8] zeroinitializer
@.str.15 = [20 x i8] c"Current locale: %s\0A\00"
define void @WrEnvironment(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [40 x i8]
%8 = alloca i64
%9 = alloca %struct.tm*
store i32 %0, i32* %3
store i8* %1, i8** %4
%10 = call i32 @WrMessage(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %18
16: ; preds = %2
%17 = call i32 @WrMessage(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
%19 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %23)
br label %27
25: ; preds = %18
%26 = call i32 @WrMessage(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
store i8* %28, i8** %5
%29 = load i8*, i8** %5
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i8*, i8** %5
%33 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %32)
br label %36
34: ; preds = %27
%35 = call i32 @WrMessage(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
%37 = call i64 @time(i32* null)
store i64 %37, i64* %8
%38 = call %struct.tm* @localtime(i64* %8)
store %struct.tm* %38, %struct.tm** %9
%39 = load i64, i64* %8
%40 = icmp ne i64 %39, -1
br i1 %40, label %41, label %48
41: ; preds = %36
%42 = call i32 @WrMessage(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%43 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%44 = load %struct.tm*, %struct.tm** %9
%45 = call i32 @strftime(i8* %43, i32 40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), %struct.tm* %44)
%46 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%47 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i8* %46)
br label %50
48: ; preds = %36
%49 = call i32 @WrMessage(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0))
br label %50
50: ; preds = %48, %41
%51 = call i32 @WrMessage(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0))
%52 = load i32, i32* @LC_ALL
%53 = call i8* @setlocale(i32 %52, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.14, i64 0, i64 0))
store i8* %53, i8** %6
%54 = load i8*, i8** %6
%55 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.15, i64 0, i64 0), i8* %54)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [13 x i8] c"@ENVIRONMENT\00"
@.str.1 = [17 x i8] c"Argument 0: %s\0A\0A\00"
@.str.2 = [29 x i8] c"@ENVIRONMENT-NO-COMMAND-ARGS\00"
@.str.3 = [5 x i8] c"PATH\00"
@.str.4 = [20 x i8] c"PATH variable: %s\0A\0A\00"
@.str.5 = [21 x i8] c"@ENVIRONMENT-NO-PATH\00"
@.str.6 = [5 x i8] c"LANG\00"
@.str.7 = [20 x i8] c"LANG variable: %s\0A\0A\00"
@.str.8 = [21 x i8] c"@ENVIRONMENT-NO-LANG\00"
@.str.9 = [23 x i8] c"@ENVIRONMENT-CURR-TIME\00"
@.str.10 = [3 x i8] c"%c\00"
@.str.11 = [19 x i8] c"Current time: %s\0A\0A\00"
@.str.12 = [21 x i8] c"@ENVIRONMENT-NO-TIME\00"
@.str.13 = [23 x i8] c"@ENVIRONMENT-SETLOCALE\00"
@LC_ALL = global i32 0
@.str.14 = [1 x i8] zeroinitializer
@.str.15 = [20 x i8] c"Current locale: %s\0A\00"
define void @WrEnvironment(i32 %0, i8* %1) {
%3 = alloca [40 x i8]
%4 = alloca i64
%5 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%6 = bitcast i64* %4 to i8*
%7 = tail call i32 @WrMessage(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %0, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %13
11: ; preds = %2
%12 = tail call i32 @WrMessage(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %9
%14 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %14)
br label %20
18: ; preds = %13
%19 = tail call i32 @WrMessage(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
%21 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %21)
br label %27
25: ; preds = %20
%26 = tail call i32 @WrMessage(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
br label %27
27: ; preds = %25, %23
%28 = tail call i64 @time(i32* null)
store i64 %28, i64* %4
%29 = call %struct.tm* @localtime(i64* %4)
%30 = load i64, i64* %4
%31 = icmp eq i64 %30, -1
br i1 %31, label %36, label %32
32: ; preds = %27
%33 = call i32 @WrMessage(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%34 = call i32 @strftime(i8* %5, i32 40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), %struct.tm* %29)
%35 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i8* %5)
br label %38
36: ; preds = %27
%37 = call i32 @WrMessage(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0))
br label %38
38: ; preds = %36, %32
%39 = call i32 @WrMessage(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0))
%40 = load i32, i32* @LC_ALL
%41 = call i8* @setlocale(i32 %40, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.14, i64 0, i64 0))
%42 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.15, i64 0, i64 0), i8* %41)
ret void
}