#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*/);
scalar_t__ mpz_cmp_si(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_invert(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mod(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_set_si(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_sub(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
void ecn_square(mpz_t t1, mpz_t t2, mpz_t s, mpz_t rx, mpz_t ry, mpz_t modulus,
                mpz_t a, mpz_t b, mpz_t x, mpz_t y) {
  if (mpz_cmp_si(x, -1) == 0 || mpz_cmp_si(y, 0) == 0) {
    mpz_set_si(rx, -1);
    mpz_set_si(ry, -1);
    return;
  }
  mpz_mul(t1, x, x);
  mpz_mod(t1, t1, modulus);
  mpz_mul_ui(t1, t1, 3);
  mpz_add(t1, t1, a);
  mpz_mod(t1, t1, modulus);
  mpz_add(t2, y, y);
  mpz_invert(t2, t2, modulus);
  mpz_mul(s, t1, t2);
  mpz_mod(s, s, modulus);
  mpz_mul(t1, s, s);
  mpz_mul_ui(t2, x, 2);
  mpz_sub(t1, t1, t2);
  mpz_sub(t2, x, t1);
  mpz_mul(t2, s, t2);
  mpz_sub(t2, t2, y);
  mpz_mod(rx, t1, modulus);
  mpz_mod(ry, t2, modulus);
  return;
}


x86 assembly (clang, -O0):
<ecn_square>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    %r9d,-0x18(%rbp)
mov    0x20(%rbp),%edi
mov    $0xffffffff,%esi
call   1080 <mpz_cmp_si@plt>
cmp    $0x0,%rax
je     11d3 <ecn_square+0x53>
mov    0x28(%rbp),%edi
xor    %esi,%esi
call   1080 <mpz_cmp_si@plt>
cmp    $0x0,%rax
jne    11f2 <ecn_square+0x72>
mov    -0x10(%rbp),%edi
mov    $0xffffffff,%esi
call   1030 <mpz_set_si@plt>
mov    -0x14(%rbp),%edi
mov    $0xffffffff,%esi
call   1030 <mpz_set_si@plt>
jmp    12e4 <ecn_square+0x164>
mov    -0x4(%rbp),%edi
mov    0x20(%rbp),%esi
mov    0x20(%rbp),%edx
call   1070 <mpz_mul@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1090 <mpz_mod@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    $0x3,%edx
call   10a0 <mpz_mul_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    0x10(%rbp),%edx
call   1060 <mpz_add@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1090 <mpz_mod@plt>
mov    -0x8(%rbp),%edi
mov    0x28(%rbp),%esi
mov    0x28(%rbp),%edx
call   1060 <mpz_add@plt>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <mpz_invert@plt>
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1070 <mpz_mul@plt>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1090 <mpz_mod@plt>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1070 <mpz_mul@plt>
mov    -0x8(%rbp),%edi
mov    0x20(%rbp),%esi
mov    $0x2,%edx
call   10a0 <mpz_mul_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1040 <mpz_sub@plt>
mov    -0x8(%rbp),%edi
mov    0x20(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1040 <mpz_sub@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1070 <mpz_mul@plt>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x28(%rbp),%edx
call   1040 <mpz_sub@plt>
mov    -0x10(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1090 <mpz_mod@plt>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1090 <mpz_mod@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecn_square>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r12d
mov    %r8d,0x10(%rsp)
mov    %ecx,0xc(%rsp)
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x68(%rsp),%r13d
mov    0x60(%rsp),%r15d
mov    0x50(%rsp),%eax
mov    %eax,0x14(%rsp)
mov    %r15d,%edi
mov    $0xffffffff,%esi
call   1080 <mpz_cmp_si@plt>
test   %rax,%rax
je     12c4 <ecn_square+0x144>
mov    %r13d,%edi
xor    %esi,%esi
call   1080 <mpz_cmp_si@plt>
test   %rax,%rax
je     12c4 <ecn_square+0x144>
mov    %ebp,%edi
mov    %r15d,%esi
mov    %r15d,%edx
call   1070 <mpz_mul@plt>
mov    %ebp,%edi
mov    %ebp,%esi
mov    %r12d,%edx
call   1090 <mpz_mod@plt>
mov    %ebp,%edi
mov    %ebp,%esi
mov    $0x3,%edx
call   10a0 <mpz_mul_ui@plt>
mov    %ebp,%edi
mov    %ebp,%esi
mov    0x14(%rsp),%edx
call   1060 <mpz_add@plt>
mov    %ebp,%edi
mov    %ebp,%esi
mov    %r12d,%edx
call   1090 <mpz_mod@plt>
mov    %ebx,%edi
mov    %r13d,%esi
mov    %r13d,%edx
call   1060 <mpz_add@plt>
mov    %ebx,%edi
mov    %ebx,%esi
mov    %r12d,%edx
call   1050 <mpz_invert@plt>
mov    %r14d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1070 <mpz_mul@plt>
mov    %r14d,%edi
mov    %r14d,%esi
mov    %r12d,%edx
call   1090 <mpz_mod@plt>
mov    %ebp,%edi
mov    %r14d,%esi
mov    %r14d,%edx
call   1070 <mpz_mul@plt>
mov    %ebx,%edi
mov    %r15d,%esi
mov    $0x2,%edx
call   10a0 <mpz_mul_ui@plt>
mov    %ebp,%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <mpz_sub@plt>
mov    %ebx,%edi
mov    %r15d,%esi
mov    %ebp,%edx
call   1040 <mpz_sub@plt>
mov    %ebx,%edi
mov    %r14d,%esi
mov    %ebx,%edx
call   1070 <mpz_mul@plt>
mov    %ebx,%edi
mov    %ebx,%esi
mov    %r13d,%edx
call   1040 <mpz_sub@plt>
mov    0xc(%rsp),%edi
mov    %ebp,%esi
mov    %r12d,%edx
call   1090 <mpz_mod@plt>
mov    0x10(%rsp),%edi
mov    %ebx,%esi
mov    %r12d,%edx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <mpz_mod@plt>
mov    0xc(%rsp),%edi
mov    $0xffffffff,%esi
call   1030 <mpz_set_si@plt>
mov    0x10(%rsp),%edi
mov    $0xffffffff,%esi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <mpz_set_si@plt>

LLVM IR (-O0):
define void @ecn_square(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9) {
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i32 %0, i32* %11
store i32 %1, i32* %12
store i32 %2, i32* %13
store i32 %3, i32* %14
store i32 %4, i32* %15
store i32 %5, i32* %16
store i32 %6, i32* %17
store i32 %7, i32* %18
store i32 %8, i32* %19
store i32 %9, i32* %20
%21 = load i32, i32* %19
%22 = call i64 @mpz_cmp_si(i32 %21, i32 -1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %10
%25 = load i32, i32* %20
%26 = call i64 @mpz_cmp_si(i32 %25, i32 0)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %24, %10
%29 = load i32, i32* %14
%30 = call i32 @mpz_set_si(i32 %29, i32 -1)
%31 = load i32, i32* %15
%32 = call i32 @mpz_set_si(i32 %31, i32 -1)
br label %100
33: ; preds = %24
%34 = load i32, i32* %11
%35 = load i32, i32* %19
%36 = load i32, i32* %19
%37 = call i32 @mpz_mul(i32 %34, i32 %35, i32 %36)
%38 = load i32, i32* %11
%39 = load i32, i32* %11
%40 = load i32, i32* %16
%41 = call i32 @mpz_mod(i32 %38, i32 %39, i32 %40)
%42 = load i32, i32* %11
%43 = load i32, i32* %11
%44 = call i32 @mpz_mul_ui(i32 %42, i32 %43, i32 3)
%45 = load i32, i32* %11
%46 = load i32, i32* %11
%47 = load i32, i32* %17
%48 = call i32 @mpz_add(i32 %45, i32 %46, i32 %47)
%49 = load i32, i32* %11
%50 = load i32, i32* %11
%51 = load i32, i32* %16
%52 = call i32 @mpz_mod(i32 %49, i32 %50, i32 %51)
%53 = load i32, i32* %12
%54 = load i32, i32* %20
%55 = load i32, i32* %20
%56 = call i32 @mpz_add(i32 %53, i32 %54, i32 %55)
%57 = load i32, i32* %12
%58 = load i32, i32* %12
%59 = load i32, i32* %16
%60 = call i32 @mpz_invert(i32 %57, i32 %58, i32 %59)
%61 = load i32, i32* %13
%62 = load i32, i32* %11
%63 = load i32, i32* %12
%64 = call i32 @mpz_mul(i32 %61, i32 %62, i32 %63)
%65 = load i32, i32* %13
%66 = load i32, i32* %13
%67 = load i32, i32* %16
%68 = call i32 @mpz_mod(i32 %65, i32 %66, i32 %67)
%69 = load i32, i32* %11
%70 = load i32, i32* %13
%71 = load i32, i32* %13
%72 = call i32 @mpz_mul(i32 %69, i32 %70, i32 %71)
%73 = load i32, i32* %12
%74 = load i32, i32* %19
%75 = call i32 @mpz_mul_ui(i32 %73, i32 %74, i32 2)
%76 = load i32, i32* %11
%77 = load i32, i32* %11
%78 = load i32, i32* %12
%79 = call i32 @mpz_sub(i32 %76, i32 %77, i32 %78)
%80 = load i32, i32* %12
%81 = load i32, i32* %19
%82 = load i32, i32* %11
%83 = call i32 @mpz_sub(i32 %80, i32 %81, i32 %82)
%84 = load i32, i32* %12
%85 = load i32, i32* %13
%86 = load i32, i32* %12
%87 = call i32 @mpz_mul(i32 %84, i32 %85, i32 %86)
%88 = load i32, i32* %12
%89 = load i32, i32* %12
%90 = load i32, i32* %20
%91 = call i32 @mpz_sub(i32 %88, i32 %89, i32 %90)
%92 = load i32, i32* %14
%93 = load i32, i32* %11
%94 = load i32, i32* %16
%95 = call i32 @mpz_mod(i32 %92, i32 %93, i32 %94)
%96 = load i32, i32* %15
%97 = load i32, i32* %12
%98 = load i32, i32* %16
%99 = call i32 @mpz_mod(i32 %96, i32 %97, i32 %98)
br label %100
100: ; preds = %33, %28
ret void
}

LLVM IR (-O2):
define void @ecn_square(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9) {
%11 = tail call i64 @mpz_cmp_si(i32 %8, i32 -1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = tail call i64 @mpz_cmp_si(i32 %9, i32 0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13, %10
%17 = tail call i32 @mpz_set_si(i32 %3, i32 -1)
%18 = tail call i32 @mpz_set_si(i32 %4, i32 -1)
br label %37
19: ; preds = %13
%20 = tail call i32 @mpz_mul(i32 %0, i32 %8, i32 %8)
%21 = tail call i32 @mpz_mod(i32 %0, i32 %0, i32 %5)
%22 = tail call i32 @mpz_mul_ui(i32 %0, i32 %0, i32 3)
%23 = tail call i32 @mpz_add(i32 %0, i32 %0, i32 %6)
%24 = tail call i32 @mpz_mod(i32 %0, i32 %0, i32 %5)
%25 = tail call i32 @mpz_add(i32 %1, i32 %9, i32 %9)
%26 = tail call i32 @mpz_invert(i32 %1, i32 %1, i32 %5)
%27 = tail call i32 @mpz_mul(i32 %2, i32 %0, i32 %1)
%28 = tail call i32 @mpz_mod(i32 %2, i32 %2, i32 %5)
%29 = tail call i32 @mpz_mul(i32 %0, i32 %2, i32 %2)
%30 = tail call i32 @mpz_mul_ui(i32 %1, i32 %8, i32 2)
%31 = tail call i32 @mpz_sub(i32 %0, i32 %0, i32 %1)
%32 = tail call i32 @mpz_sub(i32 %1, i32 %8, i32 %0)
%33 = tail call i32 @mpz_mul(i32 %1, i32 %2, i32 %1)
%34 = tail call i32 @mpz_sub(i32 %1, i32 %1, i32 %9)
%35 = tail call i32 @mpz_mod(i32 %3, i32 %0, i32 %5)
%36 = tail call i32 @mpz_mod(i32 %4, i32 %1, i32 %5)
br label %37
37: ; preds = %19, %16
ret void
}