#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*/ mpf_t;

/* Variables and functions */
int /*<<< orphan*/ mpf_div_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpf_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpf_mul(int /*<<< orphan*/, int /*<<< orphan*/ const,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpf_mul_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpf_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpf_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpf_sub(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpf_swap(int /*<<< orphan*/, int /*<<< orphan*/);
void legendre_d1(mpf_t Pn, int n, const mpf_t x) {
  int i, i0 = 0;
  static int init = 0;
  static mpf_t a, b, P_im1, P_i;
  if (!init)
    init = 1, mpf_init(a), mpf_init(b), mpf_init(P_im1), mpf_init(P_i);
  (mpf_set_ui(P_im1, 0), mpf_set_ui(P_i, 1));
  for (i = i0 + 1; i < n; ++i) {
    mpf_mul(a, x, P_i);
    mpf_mul_ui(a, a, 2 * i + 1);
    mpf_mul_ui(b, P_im1, i + 1);
    mpf_sub(a, a, b);
    mpf_swap(P_im1, P_i);
    mpf_div_ui(P_i, a, i);
  }
  mpf_set(Pn, n > i0 ? P_i : P_im1);
}


x86 assembly (clang, -O0):
<legendre_d1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,0x2ec5(%rip)
jne    11db <legendre_d1+0x5b>
movl   $0x1,0x2eb5(%rip)
mov    0x2eb3(%rip),%edi
call   1030 <mpf_init@plt>
mov    0x2eac(%rip),%edi
call   1030 <mpf_init@plt>
mov    0x2ea5(%rip),%edi
call   1030 <mpf_init@plt>
mov    0x2e9e(%rip),%edi
call   1030 <mpf_init@plt>
mov    0x2e8f(%rip),%edi
xor    %esi,%esi
call   1060 <mpf_set_ui@plt>
mov    0x2e86(%rip),%edi
mov    $0x1,%esi
call   1060 <mpf_set_ui@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    129c <legendre_d1+0x11c>
mov    0x2e55(%rip),%edi
mov    -0xc(%rbp),%esi
mov    0x2e58(%rip),%edx
call   10a0 <mpf_mul@plt>
mov    0x2e41(%rip),%edi
mov    0x2e3b(%rip),%esi
mov    -0x10(%rbp),%edx
shl    $0x1,%edx
add    $0x1,%edx
call   1070 <mpf_mul_ui@plt>
mov    0x2e2b(%rip),%edi
mov    0x2e29(%rip),%esi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
call   1070 <mpf_mul_ui@plt>
mov    0x2e10(%rip),%edi
mov    0x2e0a(%rip),%esi
mov    0x2e08(%rip),%edx
call   1080 <mpf_sub@plt>
mov    0x2e01(%rip),%edi
mov    0x2dff(%rip),%esi
call   1090 <mpf_swap@plt>
mov    0x2df4(%rip),%edi
mov    0x2de2(%rip),%esi
mov    -0x10(%rbp),%edx
call   1050 <mpf_div_ui@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1201 <legendre_d1+0x81>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    12bc <legendre_d1+0x13c>
mov    0x2dc0(%rip),%eax
mov    %eax,-0x1c(%rbp)
jmp    12c5 <legendre_d1+0x145>
mov    0x2dae(%rip),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <mpf_set@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<legendre_d1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r12d
mov    %edi,%r14d
cmpb   $0x0,0x2ec9(%rip)
jne    11c0 <legendre_d1+0x40>
movb   $0x1,0x2ec0(%rip)
xor    %edi,%edi
call   1030 <mpf_init@plt>
xor    %edi,%edi
call   1030 <mpf_init@plt>
xor    %edi,%edi
call   1030 <mpf_init@plt>
xor    %edi,%edi
call   1030 <mpf_init@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1060 <mpf_set_ui@plt>
mov    $0x1,%r13d
xor    %edi,%edi
mov    $0x1,%esi
call   1060 <mpf_set_ui@plt>
cmp    $0x2,%r12d
jl     1241 <legendre_d1+0xc1>
mov    $0x3,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r15d,%esi
xor    %edx,%edx
call   10a0 <mpf_mul@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %ebx,%edx
call   1070 <mpf_mul_ui@plt>
lea    0x1(%r13),%ebp
xor    %edi,%edi
xor    %esi,%esi
mov    %ebp,%edx
call   1070 <mpf_mul_ui@plt>
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <mpf_sub@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1090 <mpf_swap@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %r13d,%edx
call   1050 <mpf_div_ui@plt>
add    $0x2,%ebx
mov    %ebp,%r13d
cmp    %ebp,%r12d
jne    11f0 <legendre_d1+0x70>
mov    %r14d,%edi
xor    %esi,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <mpf_set@plt>

LLVM IR (-O0):
@legendre_d1.init = internal global i32 0
@legendre_d1.a = internal global i32 0
@legendre_d1.b = internal global i32 0
@legendre_d1.P_im1 = internal global i32 0
@legendre_d1.P_i = internal global i32 0
define void @legendre_d1(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
%9 = load i32, i32* @legendre_d1.init
%10 = icmp ne i32 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %3
store i32 1, i32* @legendre_d1.init
%12 = load i32, i32* @legendre_d1.a
%13 = call i32 @mpf_init(i32 %12)
%14 = load i32, i32* @legendre_d1.b
%15 = call i32 @mpf_init(i32 %14)
%16 = load i32, i32* @legendre_d1.P_im1
%17 = call i32 @mpf_init(i32 %16)
%18 = load i32, i32* @legendre_d1.P_i
%19 = call i32 @mpf_init(i32 %18)
br label %20
20: ; preds = %11, %3
%21 = load i32, i32* @legendre_d1.P_im1
%22 = call i32 @mpf_set_ui(i32 %21, i32 0)
%23 = load i32, i32* @legendre_d1.P_i
%24 = call i32 @mpf_set_ui(i32 %23, i32 1)
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %27
27: ; preds = %58, %20
%28 = load i32, i32* %7
%29 = load i32, i32* %5
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %61
31: ; preds = %27
%32 = load i32, i32* @legendre_d1.a
%33 = load i32, i32* %6
%34 = load i32, i32* @legendre_d1.P_i
%35 = call i32 @mpf_mul(i32 %32, i32 %33, i32 %34)
%36 = load i32, i32* @legendre_d1.a
%37 = load i32, i32* @legendre_d1.a
%38 = load i32, i32* %7
%39 = mul nsw i32 2, %38
%40 = add nsw i32 %39, 1
%41 = call i32 @mpf_mul_ui(i32 %36, i32 %37, i32 %40)
%42 = load i32, i32* @legendre_d1.b
%43 = load i32, i32* @legendre_d1.P_im1
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
%46 = call i32 @mpf_mul_ui(i32 %42, i32 %43, i32 %45)
%47 = load i32, i32* @legendre_d1.a
%48 = load i32, i32* @legendre_d1.a
%49 = load i32, i32* @legendre_d1.b
%50 = call i32 @mpf_sub(i32 %47, i32 %48, i32 %49)
%51 = load i32, i32* @legendre_d1.P_im1
%52 = load i32, i32* @legendre_d1.P_i
%53 = call i32 @mpf_swap(i32 %51, i32 %52)
%54 = load i32, i32* @legendre_d1.P_i
%55 = load i32, i32* @legendre_d1.a
%56 = load i32, i32* %7
%57 = call i32 @mpf_div_ui(i32 %54, i32 %55, i32 %56)
br label %58
58: ; preds = %31
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %27
61: ; preds = %27
%62 = load i32, i32* %4
%63 = load i32, i32* %5
%64 = load i32, i32* %8
%65 = icmp sgt i32 %63, %64
br i1 %65, label %66, label %68
66: ; preds = %61
%67 = load i32, i32* @legendre_d1.P_i
br label %70
68: ; preds = %61
%69 = load i32, i32* @legendre_d1.P_im1
br label %70
70: ; preds = %68, %66
%71 = phi i32 [ %67, %66 ], [ %69, %68 ]
%72 = call i32 @mpf_set(i32 %62, i32 %71)
ret void
}

LLVM IR (-O2):
@legendre_d1.init = internal unnamed_addr global i1 false
define void @legendre_d1(i32 %0, i32 %1, i32 %2) {
%4 = load i1, i1* @legendre_d1.init
br i1 %4, label %10, label %5
5: ; preds = %3
store i1 true, i1* @legendre_d1.init
%6 = tail call i32 @mpf_init(i32 0)
%7 = tail call i32 @mpf_init(i32 0)
%8 = tail call i32 @mpf_init(i32 0)
%9 = tail call i32 @mpf_init(i32 0)
br label %10
10: ; preds = %5, %3
%11 = tail call i32 @mpf_set_ui(i32 0, i32 0)
%12 = tail call i32 @mpf_set_ui(i32 0, i32 1)
%13 = icmp sgt i32 %1, 1
br i1 %13, label %14, label %26
14: ; preds = %10, %14
%15 = phi i32 [ %20, %14 ], [ 1, %10 ]
%16 = tail call i32 @mpf_mul(i32 0, i32 %2, i32 0)
%17 = shl nuw nsw i32 %15, 1
%18 = or i32 %17, 1
%19 = tail call i32 @mpf_mul_ui(i32 0, i32 0, i32 %18)
%20 = add nuw nsw i32 %15, 1
%21 = tail call i32 @mpf_mul_ui(i32 0, i32 0, i32 %20)
%22 = tail call i32 @mpf_sub(i32 0, i32 0, i32 0)
%23 = tail call i32 @mpf_swap(i32 0, i32 0)
%24 = tail call i32 @mpf_div_ui(i32 0, i32 0, i32 %15)
%25 = icmp eq i32 %20, %1
br i1 %25, label %26, label %14
26: ; preds = %14, %10
%27 = tail call i32 @mpf_set(i32 %0, i32 0)
ret void
}