#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*/ mpz_add(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_import(int /*<<< orphan*/, int, int, int,
                              int /*<<< orphan*/, int /*<<< orphan*/,
                              unsigned char const *);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul_2exp(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_sub_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
unsigned char mpz_tdiv_q_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_tdiv_r(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/);
void poly1305_gmp(unsigned char out[16], const unsigned char r[16],
                  const unsigned char s[16], const unsigned char m[],
                  unsigned int l) {
  unsigned int j;
  mpz_t rbar;
  mpz_t h;
  mpz_t c;
  mpz_t p;
  mpz_init(rbar);
  mpz_init(h);
  mpz_init(c);
  mpz_init(p);
  mpz_import(rbar, 16, -1, 1, 0, 0, r);
  mpz_set_ui(h, 0);
  mpz_set_ui(p, 1);
  mpz_mul_2exp(p, p, 130);
  mpz_sub_ui(p, p, 5);
  while (l > 0) {
    if (l < 16)
      j = l;
    else
      j = 16;
    mpz_import(c, j, -1, 1, 0, 0, m);
    m += j;
    l -= j;
    mpz_add(h, h, c);
    mpz_set_ui(c, 1);
    mpz_mul_2exp(c, c, 8 * j);
    mpz_add(h, h, c);
    mpz_mul(h, h, rbar);
    mpz_tdiv_r(h, h, p);
  }
  mpz_import(c, 16, -1, 1, 0, 0, s);
  mpz_add(h, h, c);
  for (j = 0; j < 16; ++j)
    out[j] = mpz_tdiv_q_ui(h, h, 256);
  mpz_clear(p);
  mpz_clear(c);
  mpz_clear(h);
  mpz_clear(rbar);
}


x86 assembly (clang, -O0):
<poly1305_gmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x30(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x34(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x38(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x2c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    $0x10,%esi
mov    $0xffffffff,%edx
mov    $0x1,%ecx
xor    %r9d,%r9d
mov    %r9d,%r8d
mov    %rax,(%rsp)
call   10c0 <mpz_import@plt>
mov    -0x30(%rbp),%edi
xor    %esi,%esi
call   10a0 <mpz_set_ui@plt>
mov    -0x38(%rbp),%edi
mov    $0x1,%esi
call   10a0 <mpz_set_ui@plt>
mov    -0x38(%rbp),%edi
mov    -0x38(%rbp),%esi
mov    $0x82,%edx
call   1060 <mpz_mul_2exp@plt>
mov    -0x38(%rbp),%edi
mov    -0x38(%rbp),%esi
mov    $0x5,%edx
call   1090 <mpz_sub_ui@plt>
cmpl   $0x0,-0x24(%rbp)
jbe    12f7 <poly1305_gmp+0x157>
cmpl   $0x10,-0x24(%rbp)
jae    1257 <poly1305_gmp+0xb7>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    125e <poly1305_gmp+0xbe>
movl   $0x10,-0x28(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    $0xffffffff,%edx
mov    $0x1,%ecx
xor    %r9d,%r9d
mov    %r9d,%r8d
mov    %rax,(%rsp)
call   10c0 <mpz_import@plt>
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1070 <mpz_add@plt>
mov    -0x34(%rbp),%edi
mov    $0x1,%esi
call   10a0 <mpz_set_ui@plt>
mov    -0x34(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    -0x28(%rbp),%edx
shl    $0x3,%edx
call   1060 <mpz_mul_2exp@plt>
mov    -0x30(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1070 <mpz_add@plt>
mov    -0x30(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1080 <mpz_mul@plt>
mov    -0x30(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x38(%rbp),%edx
call   1040 <mpz_tdiv_r@plt>
jmp    1238 <poly1305_gmp+0x98>
mov    -0x34(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    $0x10,%esi
mov    $0xffffffff,%edx
mov    $0x1,%ecx
xor    %r9d,%r9d
mov    %r9d,%r8d
mov    %rax,(%rsp)
call   10c0 <mpz_import@plt>
mov    -0x30(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1070 <mpz_add@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x10,-0x28(%rbp)
jae    1365 <poly1305_gmp+0x1c5>
mov    -0x30(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1331 <poly1305_gmp+0x191>
mov    -0x38(%rbp),%edi
call   10b0 <mpz_clear@plt>
mov    -0x34(%rbp),%edi
call   10b0 <mpz_clear@plt>
mov    -0x30(%rbp),%edi
call   10b0 <mpz_clear@plt>
mov    -0x2c(%rbp),%edi
call   10b0 <mpz_clear@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poly1305_gmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8d,%ebp
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
call   1050 <mpz_init@plt>
call   1050 <mpz_init@plt>
call   1050 <mpz_init@plt>
call   1050 <mpz_init@plt>
mov    %rbx,(%rsp)
mov    $0x10,%esi
mov    $0xffffffff,%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10c0 <mpz_import@plt>
xor    %esi,%esi
call   10a0 <mpz_set_ui@plt>
mov    $0x1,%esi
call   10a0 <mpz_set_ui@plt>
mov    $0x82,%edx
call   1060 <mpz_mul_2exp@plt>
mov    $0x5,%edx
call   1090 <mpz_sub_ui@plt>
test   %ebp,%ebp
je     1277 <poly1305_gmp+0xd7>
cs nopw 0x0(%rax,%rax,1)
cmp    $0x10,%ebp
mov    $0x10,%ebx
cmovb  %ebp,%ebx
mov    %r12,(%rsp)
mov    %ebx,%esi
mov    $0xffffffff,%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10c0 <mpz_import@plt>
add    %rbx,%r12
call   1070 <mpz_add@plt>
mov    $0x1,%esi
call   10a0 <mpz_set_ui@plt>
lea    0x0(,%rbx,8),%edx
call   1060 <mpz_mul_2exp@plt>
call   1070 <mpz_add@plt>
call   1080 <mpz_mul@plt>
call   1040 <mpz_tdiv_r@plt>
sub    %ebx,%ebp
jne    1220 <poly1305_gmp+0x80>
mov    %r14,(%rsp)
mov    $0x10,%esi
mov    $0xffffffff,%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10c0 <mpz_import@plt>
call   1070 <mpz_add@plt>
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,(%r15)
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,0x1(%r15)
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,0x2(%r15)
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,0x3(%r15)
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,0x4(%r15)
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,0x5(%r15)
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,0x6(%r15)
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,0x7(%r15)
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,0x8(%r15)
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,0x9(%r15)
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,0xa(%r15)
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,0xb(%r15)
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,0xc(%r15)
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,0xd(%r15)
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,0xe(%r15)
mov    $0x100,%edx
call   1030 <mpz_tdiv_q_ui@plt>
mov    %al,0xf(%r15)
call   10b0 <mpz_clear@plt>
call   10b0 <mpz_clear@plt>
call   10b0 <mpz_clear@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    10b0 <mpz_clear@plt>

LLVM IR (-O0):
define void @poly1305_gmp(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%16 = load i32, i32* %12
%17 = call i32 @mpz_init(i32 %16)
%18 = load i32, i32* %13
%19 = call i32 @mpz_init(i32 %18)
%20 = load i32, i32* %14
%21 = call i32 @mpz_init(i32 %20)
%22 = load i32, i32* %15
%23 = call i32 @mpz_init(i32 %22)
%24 = load i32, i32* %12
%25 = load i8*, i8** %7
%26 = call i32 @mpz_import(i32 %24, i32 16, i32 -1, i32 1, i32 0, i32 0, i8* %25)
%27 = load i32, i32* %13
%28 = call i32 @mpz_set_ui(i32 %27, i32 0)
%29 = load i32, i32* %15
%30 = call i32 @mpz_set_ui(i32 %29, i32 1)
%31 = load i32, i32* %15
%32 = load i32, i32* %15
%33 = call i32 @mpz_mul_2exp(i32 %31, i32 %32, i32 130)
%34 = load i32, i32* %15
%35 = load i32, i32* %15
%36 = call i32 @mpz_sub_ui(i32 %34, i32 %35, i32 5)
br label %37
37: ; preds = %46, %5
%38 = load i32, i32* %10
%39 = icmp ugt i32 %38, 0
br i1 %39, label %40, label %81
40: ; preds = %37
%41 = load i32, i32* %10
%42 = icmp ult i32 %41, 16
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = load i32, i32* %10
store i32 %44, i32* %11
br label %46
45: ; preds = %40
store i32 16, i32* %11
br label %46
46: ; preds = %45, %43
%47 = load i32, i32* %14
%48 = load i32, i32* %11
%49 = load i8*, i8** %9
%50 = call i32 @mpz_import(i32 %47, i32 %48, i32 -1, i32 1, i32 0, i32 0, i8* %49)
%51 = load i32, i32* %11
%52 = load i8*, i8** %9
%53 = zext i32 %51 to i64
%54 = getelementptr inbounds i8, i8* %52, i64 %53
store i8* %54, i8** %9
%55 = load i32, i32* %11
%56 = load i32, i32* %10
%57 = sub i32 %56, %55
store i32 %57, i32* %10
%58 = load i32, i32* %13
%59 = load i32, i32* %13
%60 = load i32, i32* %14
%61 = call i32 @mpz_add(i32 %58, i32 %59, i32 %60)
%62 = load i32, i32* %14
%63 = call i32 @mpz_set_ui(i32 %62, i32 1)
%64 = load i32, i32* %14
%65 = load i32, i32* %14
%66 = load i32, i32* %11
%67 = mul i32 8, %66
%68 = call i32 @mpz_mul_2exp(i32 %64, i32 %65, i32 %67)
%69 = load i32, i32* %13
%70 = load i32, i32* %13
%71 = load i32, i32* %14
%72 = call i32 @mpz_add(i32 %69, i32 %70, i32 %71)
%73 = load i32, i32* %13
%74 = load i32, i32* %13
%75 = load i32, i32* %12
%76 = call i32 @mpz_mul(i32 %73, i32 %74, i32 %75)
%77 = load i32, i32* %13
%78 = load i32, i32* %13
%79 = load i32, i32* %15
%80 = call i32 @mpz_tdiv_r(i32 %77, i32 %78, i32 %79)
br label %37
81: ; preds = %37
%82 = load i32, i32* %14
%83 = load i8*, i8** %8
%84 = call i32 @mpz_import(i32 %82, i32 16, i32 -1, i32 1, i32 0, i32 0, i8* %83)
%85 = load i32, i32* %13
%86 = load i32, i32* %13
%87 = load i32, i32* %14
%88 = call i32 @mpz_add(i32 %85, i32 %86, i32 %87)
store i32 0, i32* %11
br label %89
89: ; preds = %100, %81
%90 = load i32, i32* %11
%91 = icmp ult i32 %90, 16
br i1 %91, label %92, label %103
92: ; preds = %89
%93 = load i32, i32* %13
%94 = load i32, i32* %13
%95 = call zeroext i8 @mpz_tdiv_q_ui(i32 %93, i32 %94, i32 256)
%96 = load i8*, i8** %6
%97 = load i32, i32* %11
%98 = zext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %96, i64 %98
store i8 %95, i8* %99
br label %100
100: ; preds = %92
%101 = load i32, i32* %11
%102 = add i32 %101, 1
store i32 %102, i32* %11
br label %89
103: ; preds = %89
%104 = load i32, i32* %15
%105 = call i32 @mpz_clear(i32 %104)
%106 = load i32, i32* %14
%107 = call i32 @mpz_clear(i32 %106)
%108 = load i32, i32* %13
%109 = call i32 @mpz_clear(i32 %108)
%110 = load i32, i32* %12
%111 = call i32 @mpz_clear(i32 %110)
ret void
}

LLVM IR (-O2):
define void @poly1305_gmp(i8* nocapture writeonly %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = tail call i32 @mpz_init(i32 undef)
%7 = tail call i32 @mpz_init(i32 undef)
%8 = tail call i32 @mpz_init(i32 undef)
%9 = tail call i32 @mpz_init(i32 undef)
%10 = tail call i32 @mpz_import(i32 undef, i32 16, i32 -1, i32 1, i32 0, i32 0, i8* %1)
%11 = tail call i32 @mpz_set_ui(i32 undef, i32 0)
%12 = tail call i32 @mpz_set_ui(i32 undef, i32 1)
%13 = tail call i32 @mpz_mul_2exp(i32 undef, i32 undef, i32 130)
%14 = tail call i32 @mpz_sub_ui(i32 undef, i32 undef, i32 5)
%15 = icmp eq i32 %4, 0
br i1 %15, label %33, label %16
16: ; preds = %5, %16
%17 = phi i32 [ %24, %16 ], [ %4, %5 ]
%18 = phi i8* [ %23, %16 ], [ %3, %5 ]
%19 = icmp ult i32 %17, 16
%20 = select i1 %19, i32 %17, i32 16
%21 = tail call i32 @mpz_import(i32 undef, i32 %20, i32 -1, i32 1, i32 0, i32 0, i8* %18)
%22 = zext i32 %20 to i64
%23 = getelementptr inbounds i8, i8* %18, i64 %22
%24 = sub i32 %17, %20
%25 = tail call i32 @mpz_add(i32 undef, i32 undef, i32 undef)
%26 = tail call i32 @mpz_set_ui(i32 undef, i32 1)
%27 = shl nuw nsw i32 %20, 3
%28 = tail call i32 @mpz_mul_2exp(i32 undef, i32 undef, i32 %27)
%29 = tail call i32 @mpz_add(i32 undef, i32 undef, i32 undef)
%30 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
%31 = tail call i32 @mpz_tdiv_r(i32 undef, i32 undef, i32 undef)
%32 = icmp eq i32 %24, 0
br i1 %32, label %33, label %16
33: ; preds = %16, %5
%34 = tail call i32 @mpz_import(i32 undef, i32 16, i32 -1, i32 1, i32 0, i32 0, i8* %2)
%35 = tail call i32 @mpz_add(i32 undef, i32 undef, i32 undef)
%36 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
store i8 %36, i8* %0
%37 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
%38 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %37, i8* %38
%39 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
%40 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %39, i8* %40
%41 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
%42 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %41, i8* %42
%43 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
%44 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %43, i8* %44
%45 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
%46 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %45, i8* %46
%47 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
%48 = getelementptr inbounds i8, i8* %0, i64 6
store i8 %47, i8* %48
%49 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
%50 = getelementptr inbounds i8, i8* %0, i64 7
store i8 %49, i8* %50
%51 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
%52 = getelementptr inbounds i8, i8* %0, i64 8
store i8 %51, i8* %52
%53 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
%54 = getelementptr inbounds i8, i8* %0, i64 9
store i8 %53, i8* %54
%55 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
%56 = getelementptr inbounds i8, i8* %0, i64 10
store i8 %55, i8* %56
%57 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
%58 = getelementptr inbounds i8, i8* %0, i64 11
store i8 %57, i8* %58
%59 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
%60 = getelementptr inbounds i8, i8* %0, i64 12
store i8 %59, i8* %60
%61 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
%62 = getelementptr inbounds i8, i8* %0, i64 13
store i8 %61, i8* %62
%63 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
%64 = getelementptr inbounds i8, i8* %0, i64 14
store i8 %63, i8* %64
%65 = tail call zeroext i8 @mpz_tdiv_q_ui(i32 undef, i32 undef, i32 256)
%66 = getelementptr inbounds i8, i8* %0, i64 15
store i8 %65, i8* %66
%67 = tail call i32 @mpz_clear(i32 undef)
%68 = tail call i32 @mpz_clear(i32 undef)
%69 = tail call i32 @mpz_clear(i32 undef)
%70 = tail call i32 @mpz_clear(i32 undef)
ret void
}