#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 randlc(double *, double);
void ipow46(double a, int exponent, double *result) {
  double dummy, q, r;
  int n, n2;
  *result = 1;
  if (exponent == 0)
    return;
  q = a;
  r = 1;
  n = exponent;
  while (n > 1) {
    n2 = n / 2;
    if (n2 * 2 == n) {
      dummy = randlc(&q, q);
      n = n2;
    } else {
      dummy = randlc(&r, q);
      n = n - 1;
    }
  }
  dummy = randlc(&r, q);
  *result = r;
}


x86 assembly (clang, -O0):
<ipow46>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsd  0xed0(%rip),%xmm0
movsd  %xmm0,(%rax)
cmpl   $0x0,-0xc(%rbp)
jne    1143 <ipow46+0x33>
jmp    11e6 <ipow46+0xd6>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xeab(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x1,-0x34(%rbp)
jle    11c6 <ipow46+0xb6>
mov    -0x34(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
shl    $0x1,%eax
cmp    -0x34(%rbp),%eax
jne    11a5 <ipow46+0x95>
movsd  -0x28(%rbp),%xmm0
lea    -0x28(%rbp),%rdi
call   1030 <randlc@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    11c1 <ipow46+0xb1>
movsd  -0x28(%rbp),%xmm0
lea    -0x30(%rbp),%rdi
call   1030 <randlc@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1160 <ipow46+0x50>
movsd  -0x28(%rbp),%xmm0
lea    -0x30(%rbp),%rdi
call   1030 <randlc@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipow46>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movabs $0x3ff0000000000000,%rax
mov    %rax,(%rsi)
test   %edi,%edi
je     119c <ipow46+0x8c>
mov    %rsi,%r14
mov    %edi,%ebp
movsd  %xmm0,0x8(%rsp)
mov    %rax,0x10(%rsp)
cmp    $0x2,%edi
jl     1187 <ipow46+0x77>
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%rbx
jmp    1166 <ipow46+0x56>
nopl   0x0(%rax)
movsd  0x8(%rsp),%xmm0
mov    %rbx,%rdi
call   1030 <randlc@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jle    1181 <ipow46+0x71>
test   $0x1,%bpl
jne    1150 <ipow46+0x40>
shr    %ebp
movsd  0x8(%rsp),%xmm0
mov    %r15,%rdi
call   1030 <randlc@plt>
cmp    $0x1,%ebp
jg     1166 <ipow46+0x56>
movsd  0x8(%rsp),%xmm0
lea    0x10(%rsp),%rdi
call   1030 <randlc@plt>
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @ipow46(double %0, i32 %1, double* %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
store double %0, double* %4
store i32 %1, i32* %5
store double* %2, double** %6
%12 = load double*, double** %6
store double 1.000000e+00, double* %12
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
br label %44
16: ; preds = %3
%17 = load double, double* %4
store double %17, double* %8
store double 1.000000e+00, double* %9
%18 = load i32, i32* %5
store i32 %18, i32* %10
br label %19
19: ; preds = %38, %16
%20 = load i32, i32* %10
%21 = icmp sgt i32 %20, 1
br i1 %21, label %22, label %39
22: ; preds = %19
%23 = load i32, i32* %10
%24 = sdiv i32 %23, 2
store i32 %24, i32* %11
%25 = load i32, i32* %11
%26 = mul nsw i32 %25, 2
%27 = load i32, i32* %10
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %22
%30 = load double, double* %8
%31 = call double @randlc(double* %8, double %30)
store double %31, double* %7
%32 = load i32, i32* %11
store i32 %32, i32* %10
br label %38
33: ; preds = %22
%34 = load double, double* %8
%35 = call double @randlc(double* %9, double %34)
store double %35, double* %7
%36 = load i32, i32* %10
%37 = sub nsw i32 %36, 1
store i32 %37, i32* %10
br label %38
38: ; preds = %33, %29
br label %19
39: ; preds = %19
%40 = load double, double* %8
%41 = call double @randlc(double* %9, double %40)
store double %41, double* %7
%42 = load double, double* %9
%43 = load double*, double** %6
store double %42, double* %43
br label %44
44: ; preds = %39, %15
ret void
}

LLVM IR (-O2):
define void @ipow46(double %0, i32 %1, double* nocapture writeonly %2) {
%4 = alloca double
%5 = alloca double
%6 = bitcast double* %4 to i8*
%7 = bitcast double* %5 to i8*
store double 1.000000e+00, double* %2
%8 = icmp eq i32 %1, 0
br i1 %8, label %32, label %9
9: ; preds = %3
store double %0, double* %4
store double 1.000000e+00, double* %5
%10 = icmp sgt i32 %1, 1
br i1 %10, label %11, label %28
11: ; preds = %9, %23
%12 = phi i32 [ %24, %23 ], [ %1, %9 ]
%13 = and i32 %12, -2
%14 = icmp eq i32 %13, %12
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = lshr i32 %12, 1
%17 = load double, double* %4
%18 = call double @randlc(double* %4, double %17)
br label %23
19: ; preds = %11
%20 = load double, double* %4
%21 = call double @randlc(double* %5, double %20)
%22 = add nsw i32 %12, -1
br label %23
23: ; preds = %19, %15
%24 = phi i32 [ %16, %15 ], [ %22, %19 ]
%25 = icmp sgt i32 %24, 1
br i1 %25, label %11, label %26
26: ; preds = %23
%27 = load double, double* %4
br label %28
28: ; preds = %26, %9
%29 = phi double [ %27, %26 ], [ %0, %9 ]
%30 = call double @randlc(double* %5, double %29)
%31 = load double, double* %5
store double %31, double* %2
br label %32
32: ; preds = %3, %28
ret void
}