#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_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int setenv(char *, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ unsetenv(char *);
int main(int argc, char *argv[]) {
  char *home_dir, *default_editor_envvar, *new_editor_envvar;
  char *new_var, *new_var_val;
  if ((home_dir = getenv("HOME")) == NULL) {
    fprintf(stderr, "Err.(%s) get HOME env_var\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("$HOME: %s\n", home_dir);
  if ((default_editor_envvar = getenv("EDITOR")) == NULL) {
    fprintf(stderr, "Err.(%s) get EDITOR env_var\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("Valore di default $EDITOR -> ");
  printf("$EDITOR: %s\n", default_editor_envvar);
  if ((setenv("EDITOR", "nano", 1)) == -1) {
    fprintf(stderr, "Err.(%s) set EDITOR env_var\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if ((new_editor_envvar = getenv("EDITOR")) == NULL) {
    fprintf(stderr, "Err.(%s) get EDITOR env_var\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("Valore $EDITOR modificato -> ");
  printf("$EDITOR: %s\n", new_editor_envvar);
  new_var = "TEST";
  new_var_val = "Testing";
  setenv(new_var, new_var_val, 0);
  printf("Nuova variabile di ambiente TEST: %s\n", getenv("TEST"));
  unsetenv(new_var);
  if ((new_var = getenv("TEST")) == NULL)
    fprintf(stderr, "Variabile di ambiente TEST non esistente\n");
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11dc <main+0x6c>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe36(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1244 <main+0xd4>
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rdx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdc0(%rip),%rdi
lea    0xe08(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
cmp    $0xffffffff,%eax
jne    12c1 <main+0x151>
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xd63(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1317 <main+0x1a7>
mov    0x2cfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xd30(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xd3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd7c(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xd76(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xd57(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1070 <unsetenv@plt>
lea    0xd31(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    13b3 <main+0x243>
mov    0x2c3d(%rip),%rax
mov    (%rax),%edi
lea    0xd41(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c0e(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe88(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     12ae <main+0x13e>
lea    0xe93(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe8d(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     128e <main+0x11e>
mov    %rax,%rbx
lea    0xe99(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea9(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe56(%rip),%rdi
lea    0xe9e(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
cmp    $0xffffffff,%eax
je     12ce <main+0x15e>
lea    0xe35(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     128e <main+0x11e>
mov    %rax,%rbx
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe51(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe8d(%rip),%rbx
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <setenv@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
lea    0xe7a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <unsetenv@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1283 <main+0x113>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
mov    0x2d4b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd86(%rip),%rsi
jmp    12ec <main+0x17c>
mov    0x2d2b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd39(%rip),%rsi
jmp    12ec <main+0x17c>
mov    0x2d0b(%rip),%rax
mov    (%rax),%ebx
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd93(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Err.(%s) get HOME env_var\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [11 x i8] c"$HOME: %s\0A\00"
@.str.3 = [7 x i8] c"EDITOR\00"
@.str.4 = [29 x i8] c"Err.(%s) get EDITOR env_var\0A\00"
@.str.5 = [30 x i8] c"Valore di default $EDITOR -> \00"
@.str.6 = [13 x i8] c"$EDITOR: %s\0A\00"
@.str.7 = [5 x i8] c"nano\00"
@.str.8 = [29 x i8] c"Err.(%s) set EDITOR env_var\0A\00"
@.str.9 = [30 x i8] c"Valore $EDITOR modificato -> \00"
@.str.10 = [5 x i8] c"TEST\00"
@.str.11 = [8 x i8] c"Testing\00"
@.str.12 = [38 x i8] c"Nuova variabile di ambiente TEST: %s\0A\00"
@.str.13 = [42 x i8] c"Variabile di ambiente TEST non esistente\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i8* %23, i8** %7
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %32
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %20
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%34 = load i8*, i8** %7
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %34)
%36 = call i32 @setenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 1)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %45
38: ; preds = %32
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %32
%46 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i8* %46, i8** %8
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %55
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %51)
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %45
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0))
%57 = load i8*, i8** %8
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %57)
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i8** %10
%59 = load i8*, i8** %9
%60 = load i8*, i8** %10
%61 = call i32 @setenv(i8* %59, i8* %60, i32 0)
%62 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0), i8* %62)
%64 = load i8*, i8** %9
%65 = call i32 @unsetenv(i8* %64)
%66 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
store i8* %66, i8** %9
%67 = icmp eq i8* %66, null
br i1 %67, label %68, label %71
68: ; preds = %55
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.13, i64 0, i64 0))
br label %71
71: ; preds = %68, %55
%72 = load i32, i32* @EXIT_SUCCESS
ret i32 %72
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Err.(%s) get HOME env_var\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [11 x i8] c"$HOME: %s\0A\00"
@.str.3 = [7 x i8] c"EDITOR\00"
@.str.4 = [29 x i8] c"Err.(%s) get EDITOR env_var\0A\00"
@.str.5 = [30 x i8] c"Valore di default $EDITOR -> \00"
@.str.6 = [13 x i8] c"$EDITOR: %s\0A\00"
@.str.7 = [5 x i8] c"nano\00"
@.str.8 = [29 x i8] c"Err.(%s) set EDITOR env_var\0A\00"
@.str.9 = [30 x i8] c"Valore $EDITOR modificato -> \00"
@.str.10 = [5 x i8] c"TEST\00"
@.str.11 = [8 x i8] c"Testing\00"
@.str.12 = [38 x i8] c"Nuova variabile di ambiente TEST: %s\0A\00"
@.str.13 = [42 x i8] c"Variabile di ambiente TEST non esistente\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%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 %12
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%14 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %12
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %14)
%26 = tail call i32 @setenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 1)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %35
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = tail call i8* @strerror(i32 %30)
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
%34 = tail call i32 @exit(i32 %33)
unreachable
35: ; preds = %23
%36 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %45
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = tail call i8* @strerror(i32 %40)
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = tail call i32 @exit(i32 %43)
unreachable
45: ; preds = %35
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0))
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %36)
%48 = tail call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i32 0)
%49 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0), i8* %49)
%51 = tail call i32 @unsetenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%52 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %57
54: ; preds = %45
%55 = load i32, i32* @stderr
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.13, i64 0, i64 0))
br label %57
57: ; preds = %54, %45
%58 = load i32, i32* @EXIT_SUCCESS
ret i32 %58
}