#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 */
typedef int /*<<< orphan*/ const mpf_t;
typedef double mp_bitcnt_t;

/* Variables and functions */
int /*<<< orphan*/ fp_epsilon(int /*<<< orphan*/ const, unsigned int);
int /*<<< orphan*/ mpf_abs(int /*<<< orphan*/ const, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_add(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_clear(int /*<<< orphan*/ const);
scalar_t__ mpf_cmp(int /*<<< orphan*/ const, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_div_ui(int /*<<< orphan*/ const,
                              int /*<<< orphan*/ const, int);
int /*<<< orphan*/ mpf_init2(int /*<<< orphan*/ const, double);
int /*<<< orphan*/ mpf_mul(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_set(int /*<<< orphan*/ const, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_sub(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
void atan_series(mpf_t atn, const mpf_t zee, unsigned int prec) {
  mp_bitcnt_t bits = ((double)prec) * 3.322 + 50;
  mpf_t z_n, zsq, term;
  mpf_init2(z_n, bits);
  mpf_init2(zsq, bits);
  mpf_init2(term, bits);
  mpf_t maxterm;
  mpf_init2(maxterm, bits);
  fp_epsilon(maxterm, prec);
  mpf_mul(zsq, zee, zee);
  mpf_mul(z_n, zee, zsq);
  mpf_set(atn, zee);
  unsigned int n = 1;
  while (1) {
    mpf_div_ui(term, z_n, 2 * n + 1);
    if (n % 2) {
      mpf_sub(atn, atn, term);
    } else {
      mpf_add(atn, atn, term);
    }
    mpf_abs(term, term);
    if (mpf_cmp(term, maxterm) < 0)
      break;
    n++;
    mpf_mul(z_n, z_n, zsq);
  }
  mpf_clear(z_n);
  mpf_clear(zsq);
  mpf_clear(term);
  mpf_clear(maxterm);
}


x86 assembly (clang, -O0):
<atan_series>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe3f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe3b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10c0 <mpf_init2@plt>
mov    -0x20(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10c0 <mpf_init2@plt>
mov    -0x24(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10c0 <mpf_init2@plt>
mov    -0x28(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10c0 <mpf_init2@plt>
mov    -0x28(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <fp_epsilon@plt>
mov    -0x20(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
call   10b0 <mpf_mul@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x20(%rbp),%edx
call   10b0 <mpf_mul@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1080 <mpf_set@plt>
movl   $0x1,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x2c(%rbp),%edx
shl    $0x1,%edx
add    $0x1,%edx
call   1090 <mpf_div_ui@plt>
mov    -0x2c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1279 <atan_series+0xd9>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x24(%rbp),%edx
call   10a0 <mpf_sub@plt>
jmp    1287 <atan_series+0xe7>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1060 <mpf_add@plt>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1030 <mpf_abs@plt>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1040 <mpf_cmp@plt>
cmp    $0x0,%rax
jge    12ac <atan_series+0x10c>
jmp    12c8 <atan_series+0x128>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   10b0 <mpf_mul@plt>
jmp    1243 <atan_series+0xa3>
mov    -0x1c(%rbp),%edi
call   1070 <mpf_clear@plt>
mov    -0x20(%rbp),%edi
call   1070 <mpf_clear@plt>
mov    -0x24(%rbp),%edi
call   1070 <mpf_clear@plt>
mov    -0x28(%rbp),%edi
call   1070 <mpf_clear@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atan_series>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%r15d
mov    %edx,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xe42(%rip),%xmm0
addsd  0xe42(%rip),%xmm0
movsd  %xmm0,(%rsp)
call   10c0 <mpf_init2@plt>
movsd  (%rsp),%xmm0
call   10c0 <mpf_init2@plt>
movsd  (%rsp),%xmm0
call   10c0 <mpf_init2@plt>
movsd  (%rsp),%xmm0
call   10c0 <mpf_init2@plt>
mov    %r14d,%esi
call   1050 <fp_epsilon@plt>
mov    %ebp,%esi
mov    %ebp,%edx
call   10b0 <mpf_mul@plt>
mov    %ebp,%esi
call   10b0 <mpf_mul@plt>
mov    %r15d,%edi
mov    %ebp,%esi
call   1080 <mpf_set@plt>
mov    $0x1,%ebx
mov    $0x3,%ebp
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edx
call   1090 <mpf_div_ui@plt>
mov    %r15d,%edi
mov    %r15d,%esi
test   $0x1,%bl
jne    1240 <atan_series+0xa0>
call   1060 <mpf_add@plt>
jmp    1245 <atan_series+0xa5>
nopl   0x0(%rax)
call   10a0 <mpf_sub@plt>
call   1030 <mpf_abs@plt>
call   1040 <mpf_cmp@plt>
test   %rax,%rax
js     1261 <atan_series+0xc1>
add    $0x1,%ebx
call   10b0 <mpf_mul@plt>
add    $0x2,%ebp
jmp    1220 <atan_series+0x80>
call   1070 <mpf_clear@plt>
call   1070 <mpf_clear@plt>
call   1070 <mpf_clear@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <mpf_clear@plt>

LLVM IR (-O0):
define void @atan_series(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%13 = load i32, i32* %6
%14 = uitofp i32 %13 to double
%15 = call double @llvm.fmuladd.f64(double %14, double 3.322000e+00, double 5.000000e+01)
store double %15, double* %7
%16 = load i32, i32* %8
%17 = load double, double* %7
%18 = call i32 @mpf_init2(i32 %16, double %17)
%19 = load i32, i32* %9
%20 = load double, double* %7
%21 = call i32 @mpf_init2(i32 %19, double %20)
%22 = load i32, i32* %10
%23 = load double, double* %7
%24 = call i32 @mpf_init2(i32 %22, double %23)
%25 = load i32, i32* %11
%26 = load double, double* %7
%27 = call i32 @mpf_init2(i32 %25, double %26)
%28 = load i32, i32* %11
%29 = load i32, i32* %6
%30 = call i32 @fp_epsilon(i32 %28, i32 %29)
%31 = load i32, i32* %9
%32 = load i32, i32* %5
%33 = load i32, i32* %5
%34 = call i32 @mpf_mul(i32 %31, i32 %32, i32 %33)
%35 = load i32, i32* %8
%36 = load i32, i32* %5
%37 = load i32, i32* %9
%38 = call i32 @mpf_mul(i32 %35, i32 %36, i32 %37)
%39 = load i32, i32* %4
%40 = load i32, i32* %5
%41 = call i32 @mpf_set(i32 %39, i32 %40)
store i32 1, i32* %12
br label %42
42: ; preds = %3, %71
%43 = load i32, i32* %10
%44 = load i32, i32* %8
%45 = load i32, i32* %12
%46 = mul i32 2, %45
%47 = add i32 %46, 1
%48 = call i32 @mpf_div_ui(i32 %43, i32 %44, i32 %47)
%49 = load i32, i32* %12
%50 = urem i32 %49, 2
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %42
%53 = load i32, i32* %4
%54 = load i32, i32* %4
%55 = load i32, i32* %10
%56 = call i32 @mpf_sub(i32 %53, i32 %54, i32 %55)
br label %62
57: ; preds = %42
%58 = load i32, i32* %4
%59 = load i32, i32* %4
%60 = load i32, i32* %10
%61 = call i32 @mpf_add(i32 %58, i32 %59, i32 %60)
br label %62
62: ; preds = %57, %52
%63 = load i32, i32* %10
%64 = load i32, i32* %10
%65 = call i32 @mpf_abs(i32 %63, i32 %64)
%66 = load i32, i32* %10
%67 = load i32, i32* %11
%68 = call i64 @mpf_cmp(i32 %66, i32 %67)
%69 = icmp slt i64 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %62
br label %78
71: ; preds = %62
%72 = load i32, i32* %12
%73 = add i32 %72, 1
store i32 %73, i32* %12
%74 = load i32, i32* %8
%75 = load i32, i32* %8
%76 = load i32, i32* %9
%77 = call i32 @mpf_mul(i32 %74, i32 %75, i32 %76)
br label %42
78: ; preds = %70
%79 = load i32, i32* %8
%80 = call i32 @mpf_clear(i32 %79)
%81 = load i32, i32* %9
%82 = call i32 @mpf_clear(i32 %81)
%83 = load i32, i32* %10
%84 = call i32 @mpf_clear(i32 %83)
%85 = load i32, i32* %11
%86 = call i32 @mpf_clear(i32 %85)
ret void
}

LLVM IR (-O2):
define void @atan_series(i32 %0, i32 %1, i32 %2) {
%4 = uitofp i32 %2 to double
%5 = tail call double @llvm.fmuladd.f64(double %4, double 3.322000e+00, double 5.000000e+01)
%6 = tail call i32 @mpf_init2(i32 undef, double %5)
%7 = tail call i32 @mpf_init2(i32 undef, double %5)
%8 = tail call i32 @mpf_init2(i32 undef, double %5)
%9 = tail call i32 @mpf_init2(i32 undef, double %5)
%10 = tail call i32 @fp_epsilon(i32 undef, i32 %2)
%11 = tail call i32 @mpf_mul(i32 undef, i32 %1, i32 %1)
%12 = tail call i32 @mpf_mul(i32 undef, i32 %1, i32 undef)
%13 = tail call i32 @mpf_set(i32 %0, i32 %1)
br label %14
14: ; preds = %29, %3
%15 = phi i32 [ 1, %3 ], [ %30, %29 ]
%16 = shl i32 %15, 1
%17 = or i32 %16, 1
%18 = tail call i32 @mpf_div_ui(i32 undef, i32 undef, i32 %17)
%19 = and i32 %15, 1
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %14
%22 = tail call i32 @mpf_sub(i32 %0, i32 %0, i32 undef)
br label %25
23: ; preds = %14
%24 = tail call i32 @mpf_add(i32 %0, i32 %0, i32 undef)
br label %25
25: ; preds = %23, %21
%26 = tail call i32 @mpf_abs(i32 undef, i32 undef)
%27 = tail call i64 @mpf_cmp(i32 undef, i32 undef)
%28 = icmp slt i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = add i32 %15, 1
%31 = tail call i32 @mpf_mul(i32 undef, i32 undef, i32 undef)
br label %14
32: ; preds = %25
%33 = tail call i32 @mpf_clear(i32 undef)
%34 = tail call i32 @mpf_clear(i32 undef)
%35 = tail call i32 @mpf_clear(i32 undef)
%36 = tail call i32 @mpf_clear(i32 undef)
ret void
}