#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 */
typedef int /*<<< orphan*/ int8_t;
typedef int int32_t;

/* Variables and functions */
double oof2_filter(double *, double);
int oof2_state_size();
double rand_normal(int *, int /*<<< orphan*/ *, double *);
double rand_oof(int32_t *flat_state, int8_t *empty, double *gset,
                double *oof_state, int32_t oof_state_size) {
  double x2 = rand_normal(flat_state, empty, gset);
  int32_t i;
  for (i = 0; i < oof_state_size; ++i) {
    x2 = oof2_filter(oof_state + i * oof2_state_size(), x2);
  }
  return x2;
}


x86 assembly (clang, -O0):
<rand_oof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <rand_normal@plt>
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11bc <rand_oof+0x8c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1040 <oof2_state_size@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
imul   %ecx,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
movsd  -0x30(%rbp),%xmm0
call   1030 <oof2_filter@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1169 <rand_oof+0x39>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_oof>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %r8d,%ebx
mov    %rcx,%r14
call   1050 <rand_normal@plt>
test   %ebx,%ebx
jle    1178 <rand_oof+0x48>
xor    %ebp,%ebp
nopl   0x0(%rax)
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <oof2_state_size@plt>
imul   %ebp,%eax
cltq
lea    (%r14,%rax,8),%rdi
movsd  0x8(%rsp),%xmm0
call   1030 <oof2_filter@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1150 <rand_oof+0x20>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @rand_oof(i32* %0, i32* %1, double* %2, double* %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca double
%12 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store double* %2, double** %8
store double* %3, double** %9
store i32 %4, i32* %10
%13 = load i32*, i32** %6
%14 = load i32*, i32** %7
%15 = load double*, double** %8
%16 = call double @rand_normal(i32* %13, i32* %14, double* %15)
store double %16, double* %11
store i32 0, i32* %12
br label %17
17: ; preds = %30, %5
%18 = load i32, i32* %12
%19 = load i32, i32* %10
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %33
21: ; preds = %17
%22 = load double*, double** %9
%23 = load i32, i32* %12
%24 = call i32 (...) @oof2_state_size()
%25 = mul nsw i32 %23, %24
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %22, i64 %26
%28 = load double, double* %11
%29 = call double @oof2_filter(double* %27, double %28)
store double %29, double* %11
br label %30
30: ; preds = %21
%31 = load i32, i32* %12
%32 = add nsw i32 %31, 1
store i32 %32, i32* %12
br label %17
33: ; preds = %17
%34 = load double, double* %11
ret double %34
}

LLVM IR (-O2):
define double @rand_oof(i32* %0, i32* %1, double* %2, double* %3, i32 %4) {
%6 = tail call double @rand_normal(i32* %0, i32* %1, double* %2)
%7 = icmp sgt i32 %4, 0
br i1 %7, label %8, label %18
8: ; preds = %5, %8
%9 = phi i32 [ %16, %8 ], [ 0, %5 ]
%10 = phi double [ %15, %8 ], [ %6, %5 ]
%11 = tail call i32 (...) @oof2_state_size()
%12 = mul nsw i32 %11, %9
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds double, double* %3, i64 %13
%15 = tail call double @oof2_filter(double* %14, double %10)
%16 = add nuw nsw i32 %9, 1
%17 = icmp eq i32 %16, %4
br i1 %17, label %18, label %8
18: ; preds = %8, %5
%19 = phi double [ %6, %5 ], [ %15, %8 ]
ret double %19
}