#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 __ecm_eulerphi(int);
int __ecm_gcd(int, int);
scalar_t__ brentsuyama(double, double, double, double);
double brsupower(double B1, double B2, double N, double nr, int S) {
  int i, f;
  double sum;
  sum = 0;
  f = __ecm_eulerphi(S);
  for (i = 1; i < S; i++)
    if (__ecm_gcd(i, S) == 1)
      sum += brentsuyama(B1, B2, N, nr * (__ecm_gcd(i - 1, S) - 2));
  return sum / (double)f;
}


x86 assembly (clang, -O0):
<brsupower>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
mov    %edi,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x24(%rbp),%edi
call   1040 <__ecm_eulerphi@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1205 <brsupower+0xd5>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1030 <__ecm_gcd@plt>
cmp    $0x1,%eax
jne    11f2 <brsupower+0xc2>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x28(%rbp),%edi
sub    $0x1,%edi
mov    -0x24(%rbp),%esi
call   1030 <__ecm_gcd@plt>
movsd  -0x58(%rbp),%xmm3
movsd  -0x50(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
sub    $0x2,%eax
cvtsi2sd %eax,%xmm4
mulsd  %xmm4,%xmm3
call   1050 <brentsuyama@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11f7 <brsupower+0xc7>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1169 <brsupower+0x39>
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<brsupower>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ebx
movsd  %xmm3,0x28(%rsp)
movsd  %xmm2,0x20(%rsp)
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1040 <__ecm_eulerphi@plt>
mov    %eax,%r14d
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
cmp    $0x2,%ebx
jl     11e0 <brsupower+0xb0>
mov    $0x1,%ebp
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    1187 <brsupower+0x57>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %ebp,%ebx
je     11e0 <brsupower+0xb0>
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <__ecm_gcd@plt>
cmp    $0x1,%eax
jne    1180 <brsupower+0x50>
lea    -0x1(%rbp),%edi
mov    %ebx,%esi
call   1030 <__ecm_gcd@plt>
add    $0xfffffffe,%eax
xorps  %xmm3,%xmm3
cvtsi2sd %eax,%xmm3
mulsd  0x28(%rsp),%xmm3
movsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
call   1050 <brentsuyama@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
jmp    1180 <brsupower+0x50>
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @brsupower(double %0, double %1, double %2, double %3, i32 %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
store i32 %4, i32* %10
store double 0.000000e+00, double* %13
%14 = load i32, i32* %10
%15 = call i32 @__ecm_eulerphi(i32 %14)
store i32 %15, i32* %12
store i32 1, i32* %11
br label %16
16: ; preds = %42, %5
%17 = load i32, i32* %11
%18 = load i32, i32* %10
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %45
20: ; preds = %16
%21 = load i32, i32* %11
%22 = load i32, i32* %10
%23 = call i32 @__ecm_gcd(i32 %21, i32 %22)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %41
25: ; preds = %20
%26 = load double, double* %6
%27 = load double, double* %7
%28 = load double, double* %8
%29 = load double, double* %9
%30 = load i32, i32* %11
%31 = sub nsw i32 %30, 1
%32 = load i32, i32* %10
%33 = call i32 @__ecm_gcd(i32 %31, i32 %32)
%34 = sub nsw i32 %33, 2
%35 = sitofp i32 %34 to double
%36 = fmul double %29, %35
%37 = call i64 @brentsuyama(double %26, double %27, double %28, double %36)
%38 = sitofp i64 %37 to double
%39 = load double, double* %13
%40 = fadd double %39, %38
store double %40, double* %13
br label %41
41: ; preds = %25, %20
br label %42
42: ; preds = %41
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
store i32 %44, i32* %11
br label %16
45: ; preds = %16
%46 = load double, double* %13
%47 = load i32, i32* %12
%48 = sitofp i32 %47 to double
%49 = fdiv double %46, %48
ret double %49
}

LLVM IR (-O2):
define double @brsupower(double %0, double %1, double %2, double %3, i32 %4) {
%6 = tail call i32 @__ecm_eulerphi(i32 %4)
%7 = icmp sgt i32 %4, 1
br i1 %7, label %8, label %26
8: ; preds = %5, %22
%9 = phi double [ %23, %22 ], [ 0.000000e+00, %5 ]
%10 = phi i32 [ %24, %22 ], [ 1, %5 ]
%11 = tail call i32 @__ecm_gcd(i32 %10, i32 %4)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %22
13: ; preds = %8
%14 = add nsw i32 %10, -1
%15 = tail call i32 @__ecm_gcd(i32 %14, i32 %4)
%16 = add nsw i32 %15, -2
%17 = sitofp i32 %16 to double
%18 = fmul double %17, %3
%19 = tail call i64 @brentsuyama(double %0, double %1, double %2, double %18)
%20 = sitofp i64 %19 to double
%21 = fadd double %9, %20
br label %22
22: ; preds = %8, %13
%23 = phi double [ %21, %13 ], [ %9, %8 ]
%24 = add nuw nsw i32 %10, 1
%25 = icmp eq i32 %24, %4
br i1 %25, label %26, label %8
26: ; preds = %22, %5
%27 = phi double [ 0.000000e+00, %5 ], [ %23, %22 ]
%28 = sitofp i32 %6 to double
%29 = fdiv double %27, %28
ret double %29
}