#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 */
char *getenv(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int strlen(char *);
int check_environment_variable(char *variable_name, char repeating_character) {
  char *value;
  int failed;
  failed = 0;
  value = getenv(variable_name);
  if (value == NULL) {
    printf("Failed: %s doesn't exist.\n", variable_name);
    failed = 1;
  } else if (strlen(value) != 1000) {
    printf(
        "Failed: %s is corrupt (bad length). hi Should be 1000 but %ld, %s\n",
        variable_name, strlen(value), value);
    failed = 1;
  } else {
    while (*value != 0) {
      if (*value != repeating_character) {
        printf("Failed: %s is corrupt.\n", variable_name);
        failed = 1;
        break;
      } else {
        value++;
      }
    }
  }
  if (!failed) {
    printf("Passed: %s is okay.\n", variable_name);
  }
  return failed;
}


x86 assembly (clang, -O0):
<check_environment_variable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117f <check_environment_variable+0x4f>
mov    -0x8(%rbp),%rsi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x1c(%rbp)
jmp    1229 <check_environment_variable+0xf9>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x3e8,%eax
je     11c8 <check_environment_variable+0x98>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x1c(%rbp)
jmp    1224 <check_environment_variable+0xf4>
jmp    11cd <check_environment_variable+0x9d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     121f <check_environment_variable+0xef>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
je     120e <check_environment_variable+0xde>
mov    -0x8(%rbp),%rsi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x1c(%rbp)
jmp    121f <check_environment_variable+0xef>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11cd <check_environment_variable+0x9d>
jmp    1224 <check_environment_variable+0xf4>
jmp    1229 <check_environment_variable+0xf9>
cmpl   $0x0,-0x1c(%rbp)
jne    1245 <check_environment_variable+0x115>
mov    -0x8(%rbp),%rsi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_environment_variable>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
call   1030 <getenv@plt>
test   %rax,%rax
je     1185 <check_environment_variable+0x55>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0x3e8,%eax
jne    118e <check_environment_variable+0x5e>
mov    (%rbx),%al
test   %al,%al
je     1170 <check_environment_variable+0x40>
add    $0x1,%rbx
nop
cmp    %bpl,%al
jne    11ae <check_environment_variable+0x7e>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <check_environment_variable+0x30>
lea    0xeff(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c4 <check_environment_variable+0x94>
lea    0xe74(%rip),%rdi
jmp    11b5 <check_environment_variable+0x85>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe7e(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11bf <check_environment_variable+0x8f>
lea    0xea9(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Failed: %s doesn't exist.\0A\00"
@.str.1 = [67 x i8] c"Failed: %s is corrupt (bad length). hi Should be 1000 but %ld, %s\0A\00"
@.str.2 = [24 x i8] c"Failed: %s is corrupt.\0A\00"
@.str.3 = [21 x i8] c"Passed: %s is okay.\0A\00"
define i32 @check_environment_variable(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8 %1, i8* %4
store i32 0, i32* %6
%7 = load i8*, i8** %3
%8 = call i8* @getenv(i8* %7)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 1, i32* %6
br label %46
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
%17 = icmp ne i32 %16, 1000
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
%22 = load i8*, i8** %5
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i8* %19, i32 %21, i8* %22)
store i32 1, i32* %6
br label %45
24: ; preds = %14
br label %25
25: ; preds = %43, %24
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %44
30: ; preds = %25
%31 = load i8*, i8** %5
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = load i8, i8* %4
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %33, %35
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = load i8*, i8** %3
%39 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %38)
store i32 1, i32* %6
br label %44
40: ; preds = %30
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %5
br label %43
43: ; preds = %40
br label %25
44: ; preds = %37, %25
br label %45
45: ; preds = %44, %18
br label %46
46: ; preds = %45, %11
%47 = load i32, i32* %6
%48 = icmp ne i32 %47, 0
br i1 %48, label %52, label %49
49: ; preds = %46
%50 = load i8*, i8** %3
%51 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %49, %46
%53 = load i32, i32* %6
ret i32 %53
}

LLVM IR (-O2):
@.str = [27 x i8] c"Failed: %s doesn't exist.\0A\00"
@.str.1 = [67 x i8] c"Failed: %s is corrupt (bad length). hi Should be 1000 but %ld, %s\0A\00"
@.str.2 = [24 x i8] c"Failed: %s is corrupt.\0A\00"
@.str.3 = [21 x i8] c"Passed: %s is okay.\0A\00"
define i32 @check_environment_variable(i8* %0, i8 signext %1) {
%3 = tail call i8* @getenv(i8* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %28
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %3)
%9 = icmp eq i32 %8, 1000
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i8, i8* %3
%12 = icmp eq i8 %11, 0
br i1 %12, label %26, label %19
13: ; preds = %7
%14 = tail call i32 @strlen(i8* %3)
%15 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %14, i8* %3)
br label %28
16: ; preds = %19
%17 = load i8, i8* %23
%18 = icmp eq i8 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %10, %16
%20 = phi i8 [ %17, %16 ], [ %11, %10 ]
%21 = phi i8* [ %23, %16 ], [ %3, %10 ]
%22 = icmp eq i8 %20, %1
%23 = getelementptr inbounds i8, i8* %21, i64 1
br i1 %22, label %16, label %24
24: ; preds = %19
%25 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %28
26: ; preds = %16, %10
%27 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %28
28: ; preds = %5, %24, %13, %26
%29 = phi i32 [ 0, %26 ], [ 1, %13 ], [ 1, %24 ], [ 1, %5 ]
ret i32 %29
}