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

/* Variables and functions */
int /*<<< orphan*/ field_add(int /*<<< orphan*/, int /*<<< orphan*/,
                             int /*<<< orphan*/ const);
int /*<<< orphan*/ field_mult(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/ const);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/ const);
void horner_r(int n, mpz_t y, const mpz_t x, const mpz_t coeff_rev[]) {
  int i;
  mpz_set(y, x);
  for (i = 0; i < n - 1; i++) {
    field_add(y, y, coeff_rev[i]);
    field_mult(y, y, x);
  }
  field_add(y, y, coeff_rev[i]);
}


x86 assembly (clang, -O0):
<horner_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <mpz_set@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    119a <horner_r+0x6a>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
call   1040 <field_add@plt>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1050 <field_mult@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1157 <horner_r+0x27>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
call   1040 <field_add@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<horner_r>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %edx,%r12d
mov    %esi,%ebx
mov    %edi,%r15d
mov    %esi,%edi
mov    %edx,%esi
call   1030 <mpz_set@plt>
cmp    $0x2,%r15d
jl     1184 <horner_r+0x54>
add    $0xffffffff,%r15d
mov    %r15d,%r15d
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbp,4),%edx
mov    %ebx,%edi
mov    %ebx,%esi
call   1040 <field_add@plt>
mov    %ebx,%edi
mov    %ebx,%esi
mov    %r12d,%edx
call   1050 <field_mult@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1160 <horner_r+0x30>
jmp    1187 <horner_r+0x57>
xor    %r15d,%r15d
mov    (%r14,%r15,4),%edx
mov    %ebx,%edi
mov    %ebx,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <field_add@plt>

LLVM IR (-O0):
define void @horner_r(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%10 = load i32, i32* %6
%11 = load i32, i32* %7
%12 = call i32 @mpz_set(i32 %10, i32 %11)
store i32 0, i32* %9
br label %13
13: ; preds = %31, %4
%14 = load i32, i32* %9
%15 = load i32, i32* %5
%16 = sub nsw i32 %15, 1
%17 = icmp slt i32 %14, %16
br i1 %17, label %18, label %34
18: ; preds = %13
%19 = load i32, i32* %6
%20 = load i32, i32* %6
%21 = load i32*, i32** %8
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = call i32 @field_add(i32 %19, i32 %20, i32 %25)
%27 = load i32, i32* %6
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = call i32 @field_mult(i32 %27, i32 %28, i32 %29)
br label %31
31: ; preds = %18
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
br label %13
34: ; preds = %13
%35 = load i32, i32* %6
%36 = load i32, i32* %6
%37 = load i32*, i32** %8
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = call i32 @field_add(i32 %35, i32 %36, i32 %41)
ret void
}

LLVM IR (-O2):
define void @horner_r(i32 %0, i32 %1, i32 %2, i32* nocapture %3) {
%5 = tail call i32 @mpz_set(i32 %1, i32 %2)
%6 = add i32 %0, -1
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %20
8: ; preds = %4
%9 = zext i32 %6 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %16, %10 ]
%12 = getelementptr inbounds i32, i32* %3, i64 %11
%13 = load i32, i32* %12
%14 = tail call i32 @field_add(i32 %1, i32 %1, i32 %13)
%15 = tail call i32 @field_mult(i32 %1, i32 %1, i32 %2)
%16 = add nuw nsw i64 %11, 1
%17 = icmp eq i64 %16, %9
br i1 %17, label %18, label %10
18: ; preds = %10
%19 = zext i32 %6 to i64
br label %20
20: ; preds = %4, %18
%21 = phi i64 [ %19, %18 ], [ 0, %4 ]
%22 = getelementptr inbounds i32, i32* %3, i64 %21
%23 = load i32, i32* %22
%24 = tail call i32 @field_add(i32 %1, i32 %1, i32 %23)
ret void
}