#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(int n, mpz_t y, const mpz_t x, const mpz_t coeff[]) {
  int i;
  mpz_set(y, x);
  for (i = n - 1; i; i--) {
    field_add(y, y, coeff[i]);
    field_mult(y, y, x);
  }
  field_add(y, y, coeff[0]);
}


x86 assembly (clang, -O0):
<horner>:
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>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1195 <horner+0x65>
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    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1159 <horner+0x29>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1040 <field_add@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<horner>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,(%rsp)
mov    %edx,%r12d
mov    %esi,%ebx
mov    %edi,%r15d
mov    %esi,%edi
mov    %edx,%esi
call   1030 <mpz_set@plt>
mov    %r15d,%eax
add    $0xffffffff,%eax
je     1193 <horner+0x63>
cltq
mov    (%rsp),%rcx
lea    (%rcx,%rax,4),%r13
mov    $0x1,%r14d
sub    %r15d,%r14d
xor    %ebp,%ebp
nopl   (%rax)
mov    0x0(%r13,%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    $0xffffffffffffffff,%rbp
cmp    %ebp,%r14d
jne    1170 <horner+0x40>
mov    (%rsp),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <field_add@plt>

LLVM IR (-O0):
define void @horner(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)
%13 = load i32, i32* %5
%14 = sub nsw i32 %13, 1
store i32 %14, i32* %9
br label %15
15: ; preds = %31, %4
%16 = load i32, i32* %9
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %34
18: ; preds = %15
%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 %15
34: ; preds = %15
%35 = load i32, i32* %6
%36 = load i32, i32* %6
%37 = load i32*, i32** %8
%38 = getelementptr inbounds i32, i32* %37, i64 0
%39 = load i32, i32* %38
%40 = call i32 @field_add(i32 %35, i32 %36, i32 %39)
ret void
}

LLVM IR (-O2):
define void @horner(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 eq i32 %6, 0
br i1 %7, label %19, label %8
8: ; preds = %4
%9 = sext i32 %6 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ %9, %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 nsw i64 %11, -1
%17 = trunc i64 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %10
19: ; preds = %10, %4
%20 = load i32, i32* %3
%21 = tail call i32 @field_add(i32 %1, i32 %1, i32 %20)
ret void
}