#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 DBL_EPSILON;
int /*<<< orphan*/ sncn_limit(double, double, double *, double *);
double sqrt(double);
void landen(double u, double rk, double *sn, double *cn) {
  int n;
  double k, kp, kt, ktp;
  double delta, fact;
  delta = sqrt(DBL_EPSILON);
  kp = 1.0 / sqrt(1.0 + rk * rk);
  k = rk * kp;
  for (n = 0; k > delta; n++) {
    kt = (k * k) / ((1.0 + kp) * (1.0 + kp));
    ktp = (2.0 * sqrt(kp)) / (1.0 + kp);
    u *= (0.5 + 0.5 * kp);
    k = kt;
    kp = ktp;
  }
  sncn_limit(u, k / kp, sn, cn);
  kt = k;
  ktp = kp;
  for (; n > 0; n--) {
    k = (2.0 * sqrt(kt)) / (1.0 + kt);
    kp = (ktp * ktp) / ((1.0 + kt) * (1.0 + kt));
    fact = 1.0 / (1.0 + kt * (*sn) * (*sn));
    (*sn) = (1.0 + kt) * (*sn) * fact;
    (*cn) = (*cn) * sqrt(ktp * ktp + kt * kt * (*cn) * (*cn)) * fact;
    kt = k;
    ktp = kp;
  }
}


x86 assembly (clang, -O0):
<landen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    0x2ea7(%rip),%rax
movsd  (%rax),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe9b(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe87(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    1249 <landen+0x129>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  0xe46(%rip),%xmm1
addsd  -0x38(%rbp),%xmm1
movsd  0xe39(%rip),%xmm2
addsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe1a(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe06(%rip),%xmm1
addsd  -0x38(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xdfb(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1198 <landen+0x78>
movsd  -0x8(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
divsd  -0x38(%rbp),%xmm1
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <sncn_limit@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    13b4 <landen+0x294>
movsd  -0x40(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xd70(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd5c(%rip),%xmm1
addsd  -0x40(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  0xd3c(%rip),%xmm1
addsd  -0x40(%rbp),%xmm1
movsd  0xd2f(%rip),%xmm2
addsd  -0x40(%rbp),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x40(%rbp),%xmm1
mov    -0x18(%rbp),%rax
mulsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xcfc(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xcf0(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xcdf(%rip),%xmm0
addsd  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mulsd  (%rax),%xmm0
mulsd  -0x58(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mov    -0x20(%rbp),%rax
mulsd  (%rax),%xmm1
mov    -0x20(%rbp),%rax
mulsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mulsd  -0x58(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1279 <landen+0x159>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<landen>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movapd %xmm0,%xmm2
mov    0x2eaf(%rip),%rax
movsd  (%rax),%xmm0
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
movsd  %xmm2,(%rsp)
movapd %xmm1,0x20(%rsp)
jb     1159 <landen+0x39>
sqrtsd %xmm0,%xmm8
jmp    116d <landen+0x4d>
call   1040 <sqrt@plt>
xorpd  %xmm3,%xmm3
movapd 0x20(%rsp),%xmm1
movapd %xmm0,%xmm8
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  0xe83(%rip),%xmm0
ucomisd %xmm3,%xmm0
movsd  %xmm8,0x18(%rsp)
jb     1190 <landen+0x70>
sqrtsd %xmm0,%xmm0
jmp    11a2 <landen+0x82>
call   1040 <sqrt@plt>
movsd  0x18(%rsp),%xmm8
movapd 0x20(%rsp),%xmm1
movsd  (%rsp),%xmm3
movsd  0xe51(%rip),%xmm7
divsd  %xmm0,%xmm7
mulsd  %xmm7,%xmm1
ucomisd %xmm8,%xmm1
jbe    12a7 <landen+0x187>
mov    $0x1,%ebp
xorpd  %xmm9,%xmm9
movapd 0xe4b(%rip),%xmm10
movsd  0xe2b(%rip),%xmm6
jmp    1287 <landen+0x167>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movapd %xmm7,%xmm0
movsd  %xmm3,(%rsp)
movapd %xmm1,0x20(%rsp)
movsd  %xmm7,0x40(%rsp)
movapd %xmm4,0x30(%rsp)
call   1040 <sqrt@plt>
movapd 0x30(%rsp),%xmm4
movsd  0xdea(%rip),%xmm6
movapd 0xdf9(%rip),%xmm10
movsd  0x40(%rsp),%xmm7
xorpd  %xmm9,%xmm9
movsd  0x18(%rsp),%xmm8
movapd 0x20(%rsp),%xmm1
movsd  (%rsp),%xmm3
movapd %xmm4,%xmm5
mulsd  %xmm4,%xmm5
unpcklpd %xmm1,%xmm0
movapd %xmm10,%xmm2
unpcklpd %xmm1,%xmm2
mulpd  %xmm0,%xmm2
unpcklpd %xmm5,%xmm4
divpd  %xmm4,%xmm2
mulsd  %xmm6,%xmm7
addsd  %xmm6,%xmm7
mulsd  %xmm7,%xmm3
movapd %xmm2,%xmm1
unpckhpd %xmm2,%xmm1
add    $0x1,%ebp
ucomisd %xmm8,%xmm1
movapd %xmm2,%xmm7
jbe    12c2 <landen+0x1a2>
movapd %xmm7,%xmm4
addsd  0xd6d(%rip),%xmm4
ucomisd %xmm9,%xmm7
jb     11f0 <landen+0xd0>
xorps  %xmm0,%xmm0
sqrtsd %xmm7,%xmm0
jmp    1244 <landen+0x124>
divsd  %xmm7,%xmm1
movapd %xmm3,%xmm0
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <sncn_limit@plt>
divsd  %xmm2,%xmm1
movapd %xmm3,%xmm0
mov    %rbx,%rdi
mov    %r14,%rsi
movapd %xmm2,(%rsp)
call   1030 <sncn_limit@plt>
movapd (%rsp),%xmm3
xorpd  %xmm8,%xmm8
jmp    136c <landen+0x24c>
nopl   0x0(%rax)
movapd %xmm5,0x20(%rsp)
movapd %xmm6,0x40(%rsp)
movsd  %xmm2,0x30(%rsp)
movsd  %xmm4,0x18(%rsp)
call   1040 <sqrt@plt>
movsd  0x18(%rsp),%xmm4
movsd  0x30(%rsp),%xmm2
movapd 0x40(%rsp),%xmm6
movapd 0x20(%rsp),%xmm5
xorpd  %xmm8,%xmm8
movapd (%rsp),%xmm3
movapd %xmm3,%xmm1
unpcklpd %xmm6,%xmm1
movhpd 0xcd1(%rip),%xmm3
mulpd  %xmm1,%xmm3
movapd %xmm5,%xmm1
mulsd  %xmm5,%xmm1
unpcklpd %xmm5,%xmm1
divpd  %xmm1,%xmm3
mulsd  %xmm0,%xmm4
mulsd  %xmm4,%xmm2
movsd  %xmm2,(%r14)
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jle    1418 <landen+0x2f8>
movapd %xmm3,%xmm7
unpckhpd %xmm3,%xmm7
ucomisd %xmm8,%xmm7
movapd %xmm3,(%rsp)
jb     1390 <landen+0x270>
xorps  %xmm6,%xmm6
sqrtsd %xmm7,%xmm6
jmp    13b3 <landen+0x293>
nopl   0x0(%rax)
movapd %xmm7,%xmm0
movapd %xmm7,0x20(%rsp)
call   1040 <sqrt@plt>
movapd 0x20(%rsp),%xmm7
xorpd  %xmm8,%xmm8
movapd (%rsp),%xmm3
movapd %xmm0,%xmm6
movapd %xmm7,%xmm5
movsd  0xc41(%rip),%xmm2
addsd  %xmm2,%xmm5
movsd  (%rbx),%xmm0
movapd %xmm7,%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm2
mulsd  %xmm5,%xmm0
mulsd  %xmm2,%xmm0
movsd  %xmm0,(%rbx)
movsd  (%r14),%xmm4
mulsd  %xmm7,%xmm7
mulsd  %xmm4,%xmm7
mulsd  %xmm4,%xmm7
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
addsd  %xmm7,%xmm0
ucomisd %xmm8,%xmm0
jb     12f0 <landen+0x1d0>
sqrtsd %xmm0,%xmm0
jmp    132f <landen+0x20f>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@DBL_EPSILON = global double 0.000000e+00
define void @landen(double %0, double %1, double* %2, double* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double %0, double* %5
store double %1, double* %6
store double* %2, double** %7
store double* %3, double** %8
%16 = load double, double* @DBL_EPSILON
%17 = call double @sqrt(double %16)
store double %17, double* %14
%18 = load double, double* %6
%19 = load double, double* %6
%20 = call double @llvm.fmuladd.f64(double %18, double %19, double 1.000000e+00)
%21 = call double @sqrt(double %20)
%22 = fdiv double 1.000000e+00, %21
store double %22, double* %11
%23 = load double, double* %6
%24 = load double, double* %11
%25 = fmul double %23, %24
store double %25, double* %10
store i32 0, i32* %9
br label %26
26: ; preds = %52, %4
%27 = load double, double* %10
%28 = load double, double* %14
%29 = fcmp ogt double %27, %28
br i1 %29, label %30, label %55
30: ; preds = %26
%31 = load double, double* %10
%32 = load double, double* %10
%33 = fmul double %31, %32
%34 = load double, double* %11
%35 = fadd double 1.000000e+00, %34
%36 = load double, double* %11
%37 = fadd double 1.000000e+00, %36
%38 = fmul double %35, %37
%39 = fdiv double %33, %38
store double %39, double* %12
%40 = load double, double* %11
%41 = call double @sqrt(double %40)
%42 = fmul double 2.000000e+00, %41
%43 = load double, double* %11
%44 = fadd double 1.000000e+00, %43
%45 = fdiv double %42, %44
store double %45, double* %13
%46 = load double, double* %11
%47 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %46, double 5.000000e-01)
%48 = load double, double* %5
%49 = fmul double %48, %47
store double %49, double* %5
%50 = load double, double* %12
store double %50, double* %10
%51 = load double, double* %13
store double %51, double* %11
br label %52
52: ; preds = %30
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
br label %26
55: ; preds = %26
%56 = load double, double* %5
%57 = load double, double* %10
%58 = load double, double* %11
%59 = fdiv double %57, %58
%60 = load double*, double** %7
%61 = load double*, double** %8
%62 = call i32 @sncn_limit(double %56, double %59, double* %60, double* %61)
%63 = load double, double* %10
store double %63, double* %12
%64 = load double, double* %11
store double %64, double* %13
br label %65
65: ; preds = %121, %55
%66 = load i32, i32* %9
%67 = icmp sgt i32 %66, 0
br i1 %67, label %68, label %124
68: ; preds = %65
%69 = load double, double* %12
%70 = call double @sqrt(double %69)
%71 = fmul double 2.000000e+00, %70
%72 = load double, double* %12
%73 = fadd double 1.000000e+00, %72
%74 = fdiv double %71, %73
store double %74, double* %10
%75 = load double, double* %13
%76 = load double, double* %13
%77 = fmul double %75, %76
%78 = load double, double* %12
%79 = fadd double 1.000000e+00, %78
%80 = load double, double* %12
%81 = fadd double 1.000000e+00, %80
%82 = fmul double %79, %81
%83 = fdiv double %77, %82
store double %83, double* %11
%84 = load double, double* %12
%85 = load double*, double** %7
%86 = load double, double* %85
%87 = fmul double %84, %86
%88 = load double*, double** %7
%89 = load double, double* %88
%90 = call double @llvm.fmuladd.f64(double %87, double %89, double 1.000000e+00)
%91 = fdiv double 1.000000e+00, %90
store double %91, double* %15
%92 = load double, double* %12
%93 = fadd double 1.000000e+00, %92
%94 = load double*, double** %7
%95 = load double, double* %94
%96 = fmul double %93, %95
%97 = load double, double* %15
%98 = fmul double %96, %97
%99 = load double*, double** %7
store double %98, double* %99
%100 = load double*, double** %8
%101 = load double, double* %100
%102 = load double, double* %13
%103 = load double, double* %13
%104 = load double, double* %12
%105 = load double, double* %12
%106 = fmul double %104, %105
%107 = load double*, double** %8
%108 = load double, double* %107
%109 = fmul double %106, %108
%110 = load double*, double** %8
%111 = load double, double* %110
%112 = fmul double %109, %111
%113 = call double @llvm.fmuladd.f64(double %102, double %103, double %112)
%114 = call double @sqrt(double %113)
%115 = fmul double %101, %114
%116 = load double, double* %15
%117 = fmul double %115, %116
%118 = load double*, double** %8
store double %117, double* %118
%119 = load double, double* %10
store double %119, double* %12
%120 = load double, double* %11
store double %120, double* %13
br label %121
121: ; preds = %68
%122 = load i32, i32* %9
%123 = add nsw i32 %122, -1
store i32 %123, i32* %9
br label %65
124: ; preds = %65
ret void
}

LLVM IR (-O2):
@DBL_EPSILON = global double 0.000000e+00
define void @landen(double %0, double %1, double* %2, double* %3) {
%5 = load double, double* @DBL_EPSILON
%6 = tail call double @sqrt(double %5)
%7 = tail call double @llvm.fmuladd.f64(double %1, double %1, double 1.000000e+00)
%8 = tail call double @sqrt(double %7)
%9 = fdiv double 1.000000e+00, %8
%10 = fmul double %9, %1
%11 = fcmp ogt double %10, %6
br i1 %11, label %12, label %33
12: ; preds = %4, %12
%13 = phi double [ %28, %12 ], [ %0, %4 ]
%14 = phi i32 [ %29, %12 ], [ 0, %4 ]
%15 = phi double [ %32, %12 ], [ %9, %4 ]
%16 = phi double [ %30, %12 ], [ %10, %4 ]
%17 = fadd double %15, 1.000000e+00
%18 = fmul double %17, %17
%19 = tail call double @sqrt(double %15)
%20 = insertelement <2 x double> poison, double %19, i64 0
%21 = insertelement <2 x double> %20, double %16, i64 1
%22 = insertelement <2 x double> <double 2.000000e+00, double poison>, double %16, i64 1
%23 = fmul <2 x double> %21, %22
%24 = insertelement <2 x double> poison, double %17, i64 0
%25 = insertelement <2 x double> %24, double %18, i64 1
%26 = fdiv <2 x double> %23, %25
%27 = tail call double @llvm.fmuladd.f64(double %15, double 5.000000e-01, double 5.000000e-01)
%28 = fmul double %27, %13
%29 = add nuw nsw i32 %14, 1
%30 = extractelement <2 x double> %26, i64 1
%31 = fcmp ogt double %30, %6
%32 = extractelement <2 x double> %26, i64 0
br i1 %31, label %12, label %36
33: ; preds = %4
%34 = fdiv double %10, %9
%35 = tail call i32 @sncn_limit(double %0, double %34, double* %2, double* %3)
br label %70
36: ; preds = %12
%37 = extractelement <2 x double> %26, i64 0
%38 = fdiv double %30, %37
%39 = tail call i32 @sncn_limit(double %28, double %38, double* %2, double* %3)
br label %40
40: ; preds = %36, %40
%41 = phi i32 [ %68, %40 ], [ %29, %36 ]
%42 = phi <2 x double> [ %53, %40 ], [ %26, %36 ]
%43 = extractelement <2 x double> %42, i64 1
%44 = tail call double @sqrt(double %43)
%45 = fadd double %43, 1.000000e+00
%46 = extractelement <2 x double> %42, i64 0
%47 = insertelement <2 x double> %42, double %44, i64 1
%48 = insertelement <2 x double> %42, double 2.000000e+00, i64 1
%49 = fmul <2 x double> %47, %48
%50 = fmul double %45, %45
%51 = insertelement <2 x double> poison, double %50, i64 0
%52 = insertelement <2 x double> %51, double %45, i64 1
%53 = fdiv <2 x double> %49, %52
%54 = load double, double* %2
%55 = fmul double %43, %54
%56 = tail call double @llvm.fmuladd.f64(double %55, double %54, double 1.000000e+00)
%57 = fdiv double 1.000000e+00, %56
%58 = fmul double %45, %54
%59 = fmul double %58, %57
store double %59, double* %2
%60 = load double, double* %3
%61 = fmul double %43, %43
%62 = fmul double %61, %60
%63 = fmul double %60, %62
%64 = tail call double @llvm.fmuladd.f64(double %46, double %46, double %63)
%65 = tail call double @sqrt(double %64)
%66 = fmul double %60, %65
%67 = fmul double %57, %66
store double %67, double* %3
%68 = add nsw i32 %41, -1
%69 = icmp sgt i32 %41, 1
br i1 %69, label %40, label %70
70: ; preds = %40, %33
ret void
}