#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 */
double drand48();
double log(double);
double sqrt(double);
double ukf_filter_rand_normal() {
  static int is_ready = 0;
  double norm2, x, y;
  double bm;
  double saved_value;
  if (is_ready == 0) {
    do {
      x = 2.0 * drand48() - 1.0;
      y = 2.0 * drand48() - 1.0;
      norm2 = x * x + y * y;
    } while (norm2 >= 1.0 || norm2 == 0.0);
    bm = sqrt(-2.0 * log(norm2) / norm2);
    saved_value = x * bm;
    is_ready = 1;
    return y * bm;
  } else {
    is_ready = 0;
    return saved_value;
  }
}


x86 assembly (clang, -O0):
<ukf_filter_rand_normal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
cmpl   $0x0,0x2efd(%rip)
jne    1236 <ukf_filter_rand_normal+0x106>
jmp    114a <ukf_filter_rand_normal+0x1a>
mov    $0x0,%al
call   1050 <drand48@plt>
addsd  %xmm0,%xmm0
movsd  0xea3(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1050 <drand48@plt>
addsd  %xmm0,%xmm0
movsd  0xe87(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    $0x1,%al
movsd  0xe56(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jae    11d6 <ukf_filter_rand_normal+0xa6>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    114a <ukf_filter_rand_normal+0x1a>
movsd  -0x10(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe1a(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,0x2e1a(%rip)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    124a <ukf_filter_rand_normal+0x11a>
movl   $0x0,0x2dfc(%rip)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ukf_filter_rand_normal>:
sub    $0x18,%rsp
cmpb   $0x0,0x2f01(%rip)
je     1150 <ukf_filter_rand_normal+0x20>
movb   $0x0,0x2ef8(%rip)
jmp    11fd <ukf_filter_rand_normal+0xcd>
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <drand48@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe99(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1050 <drand48@plt>
addsd  %xmm0,%xmm0
addsd  0xe7c(%rip),%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
ucomisd 0xe66(%rip),%xmm2
jae    1150 <ukf_filter_rand_normal+0x20>
movapd %xmm2,%xmm1
ucomisd 0xe68(%rip),%xmm2
jne    11b4 <ukf_filter_rand_normal+0x84>
jnp    1150 <ukf_filter_rand_normal+0x20>
movsd  %xmm0,0x10(%rsp)
movapd %xmm1,%xmm0
movsd  %xmm1,0x8(%rsp)
call   1030 <log@plt>
mulsd  0xe3f(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11e7 <ukf_filter_rand_normal+0xb7>
sqrtsd %xmm0,%xmm0
jmp    11ec <ukf_filter_rand_normal+0xbc>
call   1040 <sqrt@plt>
movb   $0x1,0x2e49(%rip)
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@ukf_filter_rand_normal.is_ready = internal global i32 0
define double @ukf_filter_rand_normal() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = load i32, i32* @ukf_filter_rand_normal.is_ready
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %42
9: ; preds = %0
br label %10
10: ; preds = %27, %9
%11 = call double (...) @drand48()
%12 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %11, double -1.000000e+00)
store double %12, double* %3
%13 = call double (...) @drand48()
%14 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %13, double -1.000000e+00)
store double %14, double* %4
%15 = load double, double* %3
%16 = load double, double* %3
%17 = load double, double* %4
%18 = load double, double* %4
%19 = fmul double %17, %18
%20 = call double @llvm.fmuladd.f64(double %15, double %16, double %19)
store double %20, double* %2
br label %21
21: ; preds = %10
%22 = load double, double* %2
%23 = fcmp oge double %22, 1.000000e+00
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load double, double* %2
%26 = fcmp oeq double %25, 0.000000e+00
br label %27
27: ; preds = %24, %21
%28 = phi i1 [ true, %21 ], [ %26, %24 ]
br i1 %28, label %10, label %29
29: ; preds = %27
%30 = load double, double* %2
%31 = call double @log(double %30)
%32 = fmul double -2.000000e+00, %31
%33 = load double, double* %2
%34 = fdiv double %32, %33
%35 = call double @sqrt(double %34)
store double %35, double* %5
%36 = load double, double* %3
%37 = load double, double* %5
%38 = fmul double %36, %37
store double %38, double* %6
store i32 1, i32* @ukf_filter_rand_normal.is_ready
%39 = load double, double* %4
%40 = load double, double* %5
%41 = fmul double %39, %40
store double %41, double* %1
br label %44
42: ; preds = %0
store i32 0, i32* @ukf_filter_rand_normal.is_ready
%43 = load double, double* %6
store double %43, double* %1
br label %44
44: ; preds = %42, %29
%45 = load double, double* %1
ret double %45
}

LLVM IR (-O2):
@ukf_filter_rand_normal.is_ready = internal unnamed_addr global i1 false
define double @ukf_filter_rand_normal() {
%1 = load i1, i1* @ukf_filter_rand_normal.is_ready
br i1 %1, label %18, label %2
2: ; preds = %0, %2
%3 = tail call double (...) @drand48()
%4 = tail call double @llvm.fmuladd.f64(double %3, double 2.000000e+00, double -1.000000e+00)
%5 = tail call double (...) @drand48()
%6 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double -1.000000e+00)
%7 = fmul double %6, %6
%8 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %7)
%9 = fcmp oge double %8, 1.000000e+00
%10 = fcmp oeq double %8, 0.000000e+00
%11 = or i1 %9, %10
br i1 %11, label %2, label %12
12: ; preds = %2
%13 = tail call double @log(double %8)
%14 = fmul double %13, -2.000000e+00
%15 = fdiv double %14, %8
%16 = tail call double @sqrt(double %15)
store i1 true, i1* @ukf_filter_rand_normal.is_ready
%17 = fmul double %6, %16
br label %19
18: ; preds = %0
store i1 false, i1* @ukf_filter_rand_normal.is_ready
br label %19
19: ; preds = %18, %12
%20 = phi double [ %17, %12 ], [ undef, %18 ]
ret double %20
}