#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).\n", variable_name);
    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    $0x20,%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    117d <check_environment_variable+0x4d>
mov    -0x8(%rbp),%rsi
lea    0xe94(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x1c(%rbp)
jmp    120c <check_environment_variable+0xdc>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x3e8,%eax
je     11ad <check_environment_variable+0x7d>
mov    -0x8(%rbp),%rsi
lea    0xe7f(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x1c(%rbp)
jmp    1207 <check_environment_variable+0xd7>
jmp    11b2 <check_environment_variable+0x82>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1202 <check_environment_variable+0xd2>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
je     11f1 <check_environment_variable+0xc1>
mov    -0x8(%rbp),%rsi
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x1c(%rbp)
jmp    1202 <check_environment_variable+0xd2>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11b2 <check_environment_variable+0x82>
jmp    1207 <check_environment_variable+0xd7>
jmp    120c <check_environment_variable+0xdc>
cmpl   $0x0,-0x1c(%rbp)
jne    1226 <check_environment_variable+0xf6>
mov    -0x8(%rbp),%rsi
lea    0xe37(%rip),%rdi
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_environment_variable>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r15
call   1030 <getenv@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     1195 <check_environment_variable+0x65>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0x3e8,%eax
jne    119e <check_environment_variable+0x6e>
mov    (%rbx),%al
lea    0xef1(%rip),%rdi
test   %al,%al
je     1190 <check_environment_variable+0x60>
add    $0x1,%rbx
lea    0xeca(%rip),%rcx
cs nopw 0x0(%rax,%rax,1)
cmp    %bpl,%al
jne    11a7 <check_environment_variable+0x77>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1180 <check_environment_variable+0x50>
xor    %r14d,%r14d
jmp    11aa <check_environment_variable+0x7a>
lea    0xe64(%rip),%rdi
jmp    11aa <check_environment_variable+0x7a>
lea    0xe76(%rip),%rdi
jmp    11aa <check_environment_variable+0x7a>
mov    %rcx,%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Failed: %s doesn't exist.\0A\00"
@.str.1 = [37 x i8] c"Failed: %s is corrupt (bad length).\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 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 1, i32* %6
br label %43
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 %21
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %19)
store i32 1, i32* %6
br label %42
21: ; preds = %14
br label %22
22: ; preds = %40, %21
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %41
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = load i8, i8* %4
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %30, %32
br i1 %33, label %34, label %37
34: ; preds = %27
%35 = load i8*, i8** %3
%36 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %35)
store i32 1, i32* %6
br label %41
37: ; preds = %27
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %5
br label %40
40: ; preds = %37
br label %22
41: ; preds = %34, %22
br label %42
42: ; preds = %41, %18
br label %43
43: ; preds = %42, %11
%44 = load i32, i32* %6
%45 = icmp ne i32 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %43
%47 = load i8*, i8** %3
%48 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %46, %43
%50 = load i32, i32* %6
ret i32 %50
}

LLVM IR (-O2):
@.str = [27 x i8] c"Failed: %s doesn't exist.\0A\00"
@.str.1 = [37 x i8] c"Failed: %s is corrupt (bad length).\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 %19, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %3)
%7 = icmp eq i32 %6, 1000
br i1 %7, label %8, label %19
8: ; preds = %5
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 0
br i1 %10, label %19, label %14
11: ; preds = %14
%12 = load i8, i8* %18
%13 = icmp eq i8 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %8, %11
%15 = phi i8 [ %12, %11 ], [ %9, %8 ]
%16 = phi i8* [ %18, %11 ], [ %3, %8 ]
%17 = icmp eq i8 %15, %1
%18 = getelementptr inbounds i8, i8* %16, i64 1
br i1 %17, label %11, label %19
19: ; preds = %11, %14, %8, %5, %2
%20 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), %5 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), %8 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), %14 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), %11 ]
%21 = phi i32 [ 1, %2 ], [ 1, %5 ], [ 0, %8 ], [ 1, %14 ], [ 0, %11 ]
%22 = tail call i32 @printf(i8* %20, i8* %0)
ret i32 %21
}