#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 */
long atol(char *);
char *getenv(char *);
long *malloc(int);
long int __my_random() {
  static long int *ret = NULL;
  if (!ret) {
    char *num = getenv("GUARANTEED_RANDOM");
    ret = malloc(sizeof(long int));
    if (num) {
      *ret = atol(num);
    } else {
      *ret = 0;
    }
  }
  return *ret;
}


x86 assembly (clang, -O0):
<__my_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpq   $0x0,0x2f00(%rip)
jne    11a0 <__my_random+0x70>
lea    0xeb3(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,0x2ed9(%rip)
cmpq   $0x0,-0x8(%rbp)
je     118d <__my_random+0x5d>
mov    -0x8(%rbp),%rdi
call   1050 <atol@plt>
mov    %rax,%rcx
mov    0x2ebb(%rip),%rax
mov    %rcx,(%rax)
jmp    119b <__my_random+0x6b>
mov    0x2eac(%rip),%rax
movq   $0x0,(%rax)
jmp    11a0 <__my_random+0x70>
mov    0x2e99(%rip),%rax
mov    (%rax),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__my_random>:
push   %r14
push   %rbx
push   %rax
mov    0x2f05(%rip),%rax
test   %rax,%rax
je     1145 <__my_random+0x15>
mov    (%rax),%rax
jmp    117c <__my_random+0x4c>
lea    0xeb4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rax,0x2ed8(%rip)
test   %rbx,%rbx
je     1177 <__my_random+0x47>
mov    %rbx,%rdi
call   1050 <atol@plt>
jmp    1179 <__my_random+0x49>
xor    %eax,%eax
mov    %rax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__my_random.ret = internal global i64* null
@.str = [18 x i8] c"GUARANTEED_RANDOM\00"
define i64 @__my_random() {
%1 = alloca i8*
%2 = load i64*, i64** @__my_random.ret
%3 = icmp ne i64* %2, null
br i1 %3, label %16, label %4
4: ; preds = %0
%5 = call i8* @getenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %1
%6 = call i64* @malloc(i32 8)
store i64* %6, i64** @__my_random.ret
%7 = load i8*, i8** %1
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = load i8*, i8** %1
%11 = call i64 @atol(i8* %10)
%12 = load i64*, i64** @__my_random.ret
store i64 %11, i64* %12
br label %15
13: ; preds = %4
%14 = load i64*, i64** @__my_random.ret
store i64 0, i64* %14
br label %15
15: ; preds = %13, %9
br label %16
16: ; preds = %15, %0
%17 = load i64*, i64** @__my_random.ret
%18 = load i64, i64* %17
ret i64 %18
}

LLVM IR (-O2):
@__my_random.ret = internal unnamed_addr global i64* null
@.str = [18 x i8] c"GUARANTEED_RANDOM\00"
define i64 @__my_random() {
%1 = load i64*, i64** @__my_random.ret
%2 = icmp eq i64* %1, null
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = load i64, i64* %1
br label %13
5: ; preds = %0
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = tail call i64* @malloc(i32 8)
store i64* %7, i64** @__my_random.ret
%8 = icmp eq i8* %6, null
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i64 @atol(i8* %6)
br label %11
11: ; preds = %5, %9
%12 = phi i64 [ %10, %9 ], [ 0, %5 ]
store i64 %12, i64* %7
br label %13
13: ; preds = %3, %11
%14 = phi i64 [ %12, %11 ], [ %4, %3 ]
ret i64 %14
}