#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(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ getenv(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int main() {
  int counter = 0;
  setenv("ABC", "abc", 1);
  while (1) {
    if (counter++ % 1000000 == 0) {
      printf("b");
      fflush(stdout);
    }
    if (strcmp(getenv("ABC"), "abc") != 0) {
      printf("\nEnvironment was not preserved across checkpoint/restart.\n");
      exit(1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xe83(%rip),%rdi
lea    0xe80(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
mov    $0xf4240,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11c4 <main+0x64>
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xe35(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
lea    0xe2b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11fe <main+0x9e>
lea    0xe1b(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    118e <main+0x2e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe81(%rip),%r14
lea    0xe7e(%rip),%r12
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1060 <setenv@plt>
xor    %ebp,%ebp
mov    0x2e41(%rip),%r15
xor    %ebx,%ebx
jmp    11cd <main+0x5d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
mov    %r12,%rsi
call   1070 <strcmp@plt>
add    $0xffffffff,%ebp
add    $0x1,%ebx
test   %rax,%rax
jne    11f8 <main+0x88>
mov    %ebx,%eax
imul   $0x431bde83,%rax,%rax
shr    $0x32,%rax
imul   $0xf4240,%eax,%eax
add    %ebp,%eax
jne    11b0 <main+0x40>
mov    $0x62,%edi
call   1040 <putchar@plt>
mov    (%r15),%edi
call   1080 <fflush@plt>
jmp    11b0 <main+0x40>
lea    0xe09(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"ABC\00"
@.str.1 = [4 x i8] c"abc\00"
@.str.2 = [2 x i8] c"b\00"
@stdout = global i32 0
@.str.3 = [59 x i8] c"\0AEnvironment was not preserved across checkpoint/restart.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%3 = call i32 @setenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %4
4: ; preds = %0, %20
%5 = load i32, i32* %2
%6 = add nsw i32 %5, 1
store i32 %6, i32* %2
%7 = srem i32 %5, 1000000
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @stdout
%12 = call i32 @fflush(i32 %11)
br label %13
13: ; preds = %9, %4
%14 = call i32 @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = call i64 @strcmp(i32 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %13
br label %4
}

LLVM IR (-O2):
@.str = [4 x i8] c"ABC\00"
@.str.1 = [4 x i8] c"abc\00"
@stdout = global i32 0
@str = [58 x i8] c"\0AEnvironment was not preserved across checkpoint/restart.\00"
define i32 @main() {
%1 = tail call i32 @setenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %2
2: ; preds = %11, %0
%3 = phi i32 [ 0, %0 ], [ %4, %11 ]
%4 = add nuw nsw i32 %3, 1
%5 = urem i32 %3, 1000000
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = tail call i32 @putchar(i32 98)
%9 = load i32, i32* @stdout
%10 = tail call i32 @fflush(i32 %9)
br label %11
11: ; preds = %7, %2
%12 = tail call i32 @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = tail call i64 @strcmp(i32 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %2, label %15
15: ; preds = %11
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
}