#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 sscanf(char *, char *, double *);
double SRAND(void) {
  static bool smapa_known_SRAND = false;
  static double smapa_value_SRAND = 0;
  if (!smapa_known_SRAND) {
    int r;
    char *sv = getenv("SRAND");
    double y;
    if (sv)
      r = sscanf(sv, "%lf", &y);
    if (sv && r == 1)
      smapa_value_SRAND = y;
    smapa_known_SRAND = true;
  }
  return smapa_value_SRAND;
}


x86 assembly (clang, -O0):
<SRAND>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
cmpl   $0x0,0x2f09(%rip)
jne    1193 <SRAND+0x73>
lea    0xec4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1167 <SRAND+0x47>
mov    -0x10(%rbp),%rdi
lea    0xeab(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <sscanf@plt>
mov    %eax,-0x4(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1189 <SRAND+0x69>
cmpl   $0x1,-0x4(%rbp)
jne    1189 <SRAND+0x69>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,0x2eb7(%rip)
movl   $0x1,0x2ea5(%rip)
movsd  0x2ea5(%rip),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SRAND>:
push   %rax
cmpb   $0x0,0x2f10(%rip)
jne    1166 <SRAND+0x46>
lea    0xecf(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     115f <SRAND+0x3f>
lea    0xec4(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    115f <SRAND+0x3f>
movsd  (%rsp),%xmm0
movsd  %xmm0,0x2ee1(%rip)
movb   $0x1,0x2ed2(%rip)
movsd  0x2ed2(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
@SRAND.smapa_known_SRAND = internal global i32 0
@SRAND.smapa_value_SRAND = internal global double 0.000000e+00
@.str = [6 x i8] c"SRAND\00"
@.str.1 = [4 x i8] c"%lf\00"
define double @SRAND() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca double
%4 = load i32, i32* @SRAND.smapa_known_SRAND
%5 = icmp ne i32 %4, 0
br i1 %5, label %22, label %6
6: ; preds = %0
%7 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i8*, i8** %2
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
store i32 %12, i32* %1
br label %13
13: ; preds = %10, %6
%14 = load i8*, i8** %2
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i32, i32* %1
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = load double, double* %3
store double %20, double* @SRAND.smapa_value_SRAND
br label %21
21: ; preds = %19, %16, %13
store i32 1, i32* @SRAND.smapa_known_SRAND
br label %22
22: ; preds = %21, %0
%23 = load double, double* @SRAND.smapa_value_SRAND
ret double %23
}

LLVM IR (-O2):
@SRAND.smapa_known_SRAND = internal unnamed_addr global i1 false
@SRAND.smapa_value_SRAND = internal unnamed_addr global double 0.000000e+00
@.str = [6 x i8] c"SRAND\00"
@.str.1 = [4 x i8] c"%lf\00"
define double @SRAND() {
%1 = alloca double
%2 = load i1, i1* @SRAND.smapa_known_SRAND
br i1 %2, label %13, label %3
3: ; preds = %0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = bitcast double* %1 to i8*
%6 = icmp eq i8* %4, null
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = load double, double* %1
store double %11, double* @SRAND.smapa_value_SRAND
br label %12
12: ; preds = %3, %10, %7
store i1 true, i1* @SRAND.smapa_known_SRAND
br label %13
13: ; preds = %12, %0
%14 = load double, double* @SRAND.smapa_value_SRAND
ret double %14
}