#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 myrand(long *);
double randflt(long *);
double resettable_randflt(long *rand_seed, int reset) {
  double rranf;
  unsigned kranf;
  int n;
  static int randflt_initial_flag = 0;
  long initial_seed;
  static double random_array[256];
  if (*rand_seed < 0)
    *rand_seed = -*rand_seed;
  if ((randflt_initial_flag == 0) || reset) {
    initial_seed = *rand_seed;
    for (n = 0; n < 256; ++n)
      random_array[n] = myrand(&initial_seed);
    randflt_initial_flag = 1;
    for (n = 0; n < 1000; ++n)
      rranf = randflt(&initial_seed);
    rranf = randflt(rand_seed);
    return (rranf);
  }
  kranf = (unsigned)(myrand(rand_seed) * 256) % 256;
  rranf = *(random_array + kranf);
  *(random_array + kranf) = myrand(rand_seed);
  return (rranf);
}


x86 assembly (clang, -O0):
<resettable_randflt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jge    114d <resettable_randflt+0x2d>
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
sub    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpl   $0x0,0x2eec(%rip)
je     1164 <resettable_randflt+0x44>
cmpl   $0x0,-0x14(%rbp)
je     1205 <resettable_randflt+0xe5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x100,-0x28(%rbp)
jge    11ae <resettable_randflt+0x8e>
lea    -0x30(%rbp),%rdi
call   1030 <myrand@plt>
cvtsi2sd %eax,%xmm0
movslq -0x28(%rbp),%rcx
lea    0x2eb5(%rip),%rax
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1176 <resettable_randflt+0x56>
movl   $0x1,0x2e88(%rip)
movl   $0x0,-0x28(%rbp)
cmpl   $0x3e8,-0x28(%rbp)
jge    11e8 <resettable_randflt+0xc8>
lea    -0x30(%rbp),%rdi
call   1040 <randflt@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11bf <resettable_randflt+0x9f>
mov    -0x10(%rbp),%rdi
call   1040 <randflt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1257 <resettable_randflt+0x137>
mov    -0x10(%rbp),%rdi
call   1030 <myrand@plt>
shl    $0x8,%eax
and    $0xff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
lea    0x2e2b(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <myrand@plt>
cvtsi2sd %eax,%xmm0
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
lea    0x2e08(%rip),%rax
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resettable_randflt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    (%rdi),%rax
test   %rax,%rax
js     113d <resettable_randflt+0x1d>
test   %esi,%esi
je     1147 <resettable_randflt+0x27>
jmp    1185 <resettable_randflt+0x65>
neg    %rax
mov    %rax,(%r14)
test   %esi,%esi
jne    1185 <resettable_randflt+0x65>
testb  $0x1,0x2ef2(%rip)
je     1185 <resettable_randflt+0x65>
mov    %r14,%rdi
call   1030 <myrand@plt>
movsd  0x2ef0(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
call   1030 <myrand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x2ed3(%rip)
movsd  0x8(%rsp),%xmm0
jmp    11f5 <resettable_randflt+0xd5>
mov    %rax,(%rsp)
xor    %ebx,%ebx
mov    %rsp,%r15
lea    0x2ebb(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1030 <myrand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rbx,%r12,1)
add    $0x8,%rbx
cmp    $0x800,%rbx
jne    11a0 <resettable_randflt+0x80>
movb   $0x1,0x2e77(%rip)
mov    $0x3e8,%ebp
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <randflt@plt>
add    $0xffffffff,%ebp
jne    11e0 <resettable_randflt+0xc0>
mov    %r14,%rdi
call   1040 <randflt@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@resettable_randflt.randflt_initial_flag = internal global i32 0
@resettable_randflt.random_array = internal global [256 x double] zeroinitializer
define double @resettable_randflt(i64* %0, i32 %1) {
%3 = alloca double
%4 = alloca i64*
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
store i64* %0, i64** %4
store i32 %1, i32* %5
%10 = load i64*, i64** %4
%11 = load i64, i64* %10
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i64*, i64** %4
%15 = load i64, i64* %14
%16 = sub nsw i64 0, %15
%17 = load i64*, i64** %4
store i64 %16, i64* %17
br label %18
18: ; preds = %13, %2
%19 = load i32, i32* @resettable_randflt.randflt_initial_flag
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %52
24: ; preds = %21, %18
%25 = load i64*, i64** %4
%26 = load i64, i64* %25
store i64 %26, i64* %9
store i32 0, i32* %8
br label %27
27: ; preds = %36, %24
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 256
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = call i32 @myrand(i64* %9)
%32 = sitofp i32 %31 to double
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [256 x double], [256 x double]* @resettable_randflt.random_array, i64 0, i64 %34
store double %32, double* %35
br label %36
36: ; preds = %30
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %27
39: ; preds = %27
store i32 1, i32* @resettable_randflt.randflt_initial_flag
store i32 0, i32* %8
br label %40
40: ; preds = %45, %39
%41 = load i32, i32* %8
%42 = icmp slt i32 %41, 1000
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = call double @randflt(i64* %9)
store double %44, double* %6
br label %45
45: ; preds = %43
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %40
48: ; preds = %40
%49 = load i64*, i64** %4
%50 = call double @randflt(i64* %49)
store double %50, double* %6
%51 = load double, double* %6
store double %51, double* %3
br label %68
52: ; preds = %21
%53 = load i64*, i64** %4
%54 = call i32 @myrand(i64* %53)
%55 = mul nsw i32 %54, 256
%56 = urem i32 %55, 256
store i32 %56, i32* %7
%57 = load i32, i32* %7
%58 = zext i32 %57 to i64
%59 = getelementptr inbounds double, double* getelementptr inbounds ([256 x double], [256 x double]* @resettable_randflt.random_array, i64 0, i64 0), i64 %58
%60 = load double, double* %59
store double %60, double* %6
%61 = load i64*, i64** %4
%62 = call i32 @myrand(i64* %61)
%63 = sitofp i32 %62 to double
%64 = load i32, i32* %7
%65 = zext i32 %64 to i64
%66 = getelementptr inbounds double, double* getelementptr inbounds ([256 x double], [256 x double]* @resettable_randflt.random_array, i64 0, i64 0), i64 %65
store double %63, double* %66
%67 = load double, double* %6
store double %67, double* %3
br label %68
68: ; preds = %52, %48
%69 = load double, double* %3
ret double %69
}

LLVM IR (-O2):
@resettable_randflt.randflt_initial_flag = internal unnamed_addr global i1 false
@resettable_randflt.random_array = internal unnamed_addr global [256 x double] zeroinitializer
define double @resettable_randflt(i64* %0, i32 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = load i64, i64* %0
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = sub nsw i64 0, %5
store i64 %8, i64* %0
br label %9
9: ; preds = %7, %2
%10 = phi i64 [ %8, %7 ], [ %5, %2 ]
%11 = load i1, i1* @resettable_randflt.randflt_initial_flag
%12 = icmp eq i32 %1, 0
%13 = and i1 %12, %11
br i1 %13, label %30, label %14
14: ; preds = %9
store i64 %10, i64* %3
br label %15
15: ; preds = %14, %15
%16 = phi i64 [ 0, %14 ], [ %20, %15 ]
%17 = call i32 @myrand(i64* %3)
%18 = sitofp i32 %17 to double
%19 = getelementptr inbounds [256 x double], [256 x double]* @resettable_randflt.random_array, i64 0, i64 %16
store double %18, double* %19
%20 = add nuw nsw i64 %16, 1
%21 = icmp eq i64 %20, 256
br i1 %21, label %22, label %15
22: ; preds = %15
store i1 true, i1* @resettable_randflt.randflt_initial_flag
br label %23
23: ; preds = %22, %23
%24 = phi i32 [ 0, %22 ], [ %26, %23 ]
%25 = call double @randflt(i64* %3)
%26 = add nuw nsw i32 %24, 1
%27 = icmp eq i32 %26, 1000
br i1 %27, label %28, label %23
28: ; preds = %23
%29 = call double @randflt(i64* %0)
br label %35
30: ; preds = %9
%31 = tail call i32 @myrand(i64* %0)
%32 = load double, double* getelementptr inbounds ([256 x double], [256 x double]* @resettable_randflt.random_array, i64 0, i64 0)
%33 = tail call i32 @myrand(i64* %0)
%34 = sitofp i32 %33 to double
store double %34, double* getelementptr inbounds ([256 x double], [256 x double]* @resettable_randflt.random_array, i64 0, i64 0)
br label %35
35: ; preds = %30, %28
%36 = phi double [ %29, %28 ], [ %32, %30 ]
ret double %36
}