#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*/ errx(int, char *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  volatile int modified;
  char buffer[64];
  char *variable;
  variable = getenv("GREENIE");
  if (variable == NULL) {
    errx(1, "please set the GREENIE environment variable\n");
  }
  modified = 0;
  strcpy(buffer, variable);
  if (modified == 0x0d0a0d0a) {
    printf("you have correctly modified the variable\n");
  } else {
    printf("Try again, you got 0x%08x\n", modified);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    1182 <main+0x42>
mov    $0x1,%edi
lea    0xe8b(%rip),%rsi
call   1050 <errx@plt>
movl   $0x0,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x14(%rbp),%eax
cmp    $0xd0a0d0a,%eax
jne    11b7 <main+0x77>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    11c8 <main+0x88>
mov    -0x14(%rbp),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
lea    0xea4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117a <main+0x2a>
lea    0xe98(%rip),%rsi
mov    $0x1,%edi
call   1060 <errx@plt>
movl   $0x0,0xc(%rsp)
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    0xc(%rsp),%eax
cmp    $0xd0a0d0a,%eax
jne    11a8 <main+0x58>
lea    0xeaf(%rip),%rdi
call   1050 <puts@plt>
jmp    11ba <main+0x6a>
mov    0xc(%rsp),%esi
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"GREENIE\00"
@.str.1 = [45 x i8] c"please set the GREENIE environment variable\0A\00"
@.str.2 = [42 x i8] c"you have correctly modified the variable\0A\00"
@.str.3 = [27 x i8] c"Try again, you got 0x%08x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [64 x i8]
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %8
%10 = load i8*, i8** %8
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @errx(i32 1, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
store volatile i32 0, i32* %6
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%16 = load i8*, i8** %8
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = load volatile i32, i32* %6
%19 = icmp eq i32 %18, 218762506
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %25
22: ; preds = %14
%23 = load volatile i32, i32* %6
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %20
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [8 x i8] c"GREENIE\00"
@.str.1 = [45 x i8] c"please set the GREENIE environment variable\0A\00"
@.str.3 = [27 x i8] c"Try again, you got 0x%08x\0A\00"
@str = [41 x i8] c"you have correctly modified the variable\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
store volatile i32 0, i32* %3
%12 = call i32 @strcpy(i8* %6, i8* %7)
%13 = load volatile i32, i32* %3
%14 = icmp eq i32 %13, 218762506
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %20
17: ; preds = %11
%18 = load volatile i32, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17, %15
ret i32 0
}