double my_random() {
  double mylist[] = {0.92, 0.33, 0.98, 0.45, 0.07, 0.51, 0.72};
  static double random = 0;
  int size = (int)(sizeof(mylist) / sizeof(mylist[0]));
  static int i = 0;
  if (random != mylist[size - 1]) {
    random = mylist[i];
    i++;
  } else {
    i = 0;
    random = mylist[i];
  }
  return random;
}


x86 assembly (clang, -O0):
<my_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x40(%rbp),%rdi
lea    0xedd(%rip),%rsi
mov    $0x38,%edx
call   1030 <memcpy@plt>
movl   $0x7,-0x44(%rbp)
movsd  0x2ef4(%rip),%xmm0
mov    -0x44(%rbp),%eax
sub    $0x1,%eax
cltq
ucomisd -0x40(%rbp,%rax,8),%xmm0
jne    115b <my_random+0x4b>
jp     115b <my_random+0x4b>
jmp    1184 <my_random+0x74>
movslq 0x2ed6(%rip),%rax
movsd  -0x40(%rbp,%rax,8),%xmm0
movsd  %xmm0,0x2ec0(%rip)
mov    0x2ec2(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2eb9(%rip)
jmp    11a3 <my_random+0x93>
movl   $0x0,0x2eaa(%rip)
movslq 0x2ea3(%rip),%rax
movsd  -0x40(%rbp,%rax,8),%xmm0
movsd  %xmm0,0x2e8d(%rip)
movsd  0x2e85(%rip),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_random>:
movsd  0x2f20(%rip),%xmm0
ucomisd 0xef0(%rip),%xmm0
jne    1114 <my_random+0x14>
jnp    1139 <my_random+0x39>
movslq 0x2f15(%rip),%rax
lea    0xeee(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
movsd  %xmm0,0x2ef9(%rip)
add    $0x1,%eax
mov    %eax,0x2ef8(%rip)
ret
movl   $0x0,0x2eed(%rip)
movabs $0x3fed70a3d70a3d71,%rax
70 ed 3f
mov    %rax,0x2ed4(%rip)
movsd  0xeac(%rip),%xmm0
ret

LLVM IR (-O0):
@__const.my_random.mylist = [7 x double] [double 9.200000e-01, double 3.300000e-01, double 0x3FEF5C28F5C28F5C, double 4.500000e-01, double 7.000000e-02, double 5.100000e-01, double 0x3FE70A3D70A3D70A]
@my_random.random = internal global double 0.000000e+00
@my_random.i = internal global i32 0
define double @my_random() {
%1 = alloca [7 x double]
%2 = alloca i32
%3 = bitcast [7 x double]* %1 to i8*
store i32 7, i32* %2
%4 = load double, double* @my_random.random
%5 = load i32, i32* %2
%6 = sub nsw i32 %5, 1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [7 x double], [7 x double]* %1, i64 0, i64 %7
%9 = load double, double* %8
%10 = fcmp une double %4, %9
br i1 %10, label %11, label %18
11: ; preds = %0
%12 = load i32, i32* @my_random.i
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [7 x double], [7 x double]* %1, i64 0, i64 %13
%15 = load double, double* %14
store double %15, double* @my_random.random
%16 = load i32, i32* @my_random.i
%17 = add nsw i32 %16, 1
store i32 %17, i32* @my_random.i
br label %23
18: ; preds = %0
store i32 0, i32* @my_random.i
%19 = load i32, i32* @my_random.i
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [7 x double], [7 x double]* %1, i64 0, i64 %20
%22 = load double, double* %21
store double %22, double* @my_random.random
br label %23
23: ; preds = %18, %11
%24 = load double, double* @my_random.random
ret double %24
}

LLVM IR (-O2):
@__const.my_random.mylist = [7 x double] [double 9.200000e-01, double 3.300000e-01, double 0x3FEF5C28F5C28F5C, double 4.500000e-01, double 7.000000e-02, double 5.100000e-01, double 0x3FE70A3D70A3D70A]
@my_random.random = internal unnamed_addr global double 0.000000e+00
@my_random.i = internal unnamed_addr global i32 0
define double @my_random() {
%1 = load double, double* @my_random.random
%2 = fcmp une double %1, 0x3FE70A3D70A3D70A
br i1 %2, label %3, label %9
3: ; preds = %0
%4 = load i32, i32* @my_random.i
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds [7 x double], [7 x double]* @__const.my_random.mylist, i64 0, i64 %5
%7 = load double, double* %6
store double %7, double* @my_random.random
%8 = add nsw i32 %4, 1
store i32 %8, i32* @my_random.i
br label %10
9: ; preds = %0
store i32 0, i32* @my_random.i
store double 9.200000e-01, double* @my_random.random
br label %10
10: ; preds = %9, %3
%11 = phi double [ 9.200000e-01, %9 ], [ %7, %3 ]
ret double %11
}