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


x86 assembly (clang, -O0):
<brsudickson>:
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    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jg     1243 <brsudickson+0x113>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1030 <__ecm_gcd@plt>
cmp    $0x1,%eax
jne    1230 <brsudickson+0x100>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x28(%rbp),%edi
sub    $0x1,%edi
mov    -0x24(%rbp),%esi
call   1030 <__ecm_gcd@plt>
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%edi
add    $0x1,%edi
mov    -0x24(%rbp),%esi
call   1030 <__ecm_gcd@plt>
movsd  -0x60(%rbp),%xmm3
movsd  -0x58(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
add    %ecx,%eax
sub    $0x4,%eax
cvtsi2sd %eax,%xmm4
mulsd  %xmm4,%xmm3
movsd  0xde8(%rip),%xmm4
divsd  %xmm4,%xmm3
call   1050 <brentsuyama@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1235 <brsudickson+0x105>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1171 <brsudickson+0x41>
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<brsudickson>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %edi,%r15d
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,%r15d
jl     120f <brsudickson+0xdf>
mov    %r15d,%r12d
shr    %r12d
add    $0x1,%r12d
mov    $0x1,%ebp
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    11f8 <brsudickson+0xc8>
xchg   %ax,%ax
lea    -0x1(%rbp),%edi
mov    %r15d,%esi
call   1030 <__ecm_gcd@plt>
mov    %eax,%ebx
add    $0x1,%ebp
mov    %ebp,%edi
mov    %r15d,%esi
call   1030 <__ecm_gcd@plt>
add    %ebx,%eax
add    $0xfffffffc,%eax
xorps  %xmm3,%xmm3
cvtsi2sd %eax,%xmm3
mulsd  0x28(%rsp),%xmm3
mulsd  0xe3c(%rip),%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)
cmp    %r12d,%ebp
je     120f <brsudickson+0xdf>
mov    %ebp,%edi
mov    %r15d,%esi
call   1030 <__ecm_gcd@plt>
cmp    $0x1,%eax
je     1190 <brsudickson+0x60>
add    $0x1,%ebp
cmp    %r12d,%ebp
jne    11f8 <brsudickson+0xc8>
mov    %r14d,%eax
shr    $0x1f,%eax
add    %r14d,%eax
sar    %eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @brsudickson(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)
%16 = sdiv i32 %15, 2
store i32 %16, i32* %12
store i32 1, i32* %11
br label %17
17: ; preds = %50, %5
%18 = load i32, i32* %11
%19 = load i32, i32* %10
%20 = sdiv i32 %19, 2
%21 = icmp sle i32 %18, %20
br i1 %21, label %22, label %53
22: ; preds = %17
%23 = load i32, i32* %11
%24 = load i32, i32* %10
%25 = call i32 @__ecm_gcd(i32 %23, i32 %24)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %49
27: ; preds = %22
%28 = load double, double* %6
%29 = load double, double* %7
%30 = load double, double* %8
%31 = load double, double* %9
%32 = load i32, i32* %11
%33 = sub nsw i32 %32, 1
%34 = load i32, i32* %10
%35 = call i32 @__ecm_gcd(i32 %33, i32 %34)
%36 = load i32, i32* %11
%37 = add nsw i32 %36, 1
%38 = load i32, i32* %10
%39 = call i32 @__ecm_gcd(i32 %37, i32 %38)
%40 = add nsw i32 %35, %39
%41 = sub nsw i32 %40, 4
%42 = sitofp i32 %41 to double
%43 = fmul double %31, %42
%44 = fdiv double %43, 2.000000e+00
%45 = call i64 @brentsuyama(double %28, double %29, double %30, double %44)
%46 = sitofp i64 %45 to double
%47 = load double, double* %13
%48 = fadd double %47, %46
store double %48, double* %13
br label %49
49: ; preds = %27, %22
br label %50
50: ; preds = %49
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %17
53: ; preds = %17
%54 = load double, double* %13
%55 = load i32, i32* %12
%56 = sitofp i32 %55 to double
%57 = fdiv double %54, %56
ret double %57
}

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