#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*/ BN_CTX;
typedef int /*<<< orphan*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BN_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_CTX_new();
scalar_t__ BN_cmp(int /*<<< orphan*/ *, int /*<<< orphan*/ const *);
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod_sqr(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_new();
int id_sign(const BIGNUM *id, const BIGNUM *r, const BIGNUM *N) {
  BN_CTX *ctx = BN_CTX_new();
  BIGNUM *t;
  int ret;
  t = BN_new();
  BN_mod_sqr(t, r, N, ctx);
  if (BN_cmp(t, id))
    ret = -1;
  else
    ret = 1;
  BN_free(t);
  BN_CTX_free(ctx);
  return ret;
}


x86 assembly (clang, -O0):
<id_sign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1060 <BN_CTX_new@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <BN_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1070 <BN_mod_sqr@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <BN_cmp@plt>
cmp    $0x0,%rax
je     11c2 <id_sign+0x62>
movl   $0xffffffff,-0x2c(%rbp)
jmp    11c9 <id_sign+0x69>
movl   $0x1,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <BN_free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <BN_CTX_free@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<id_sign>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
xor    %eax,%eax
call   1060 <BN_CTX_new@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1030 <BN_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r13,%rcx
call   1070 <BN_mod_sqr@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <BN_cmp@plt>
neg    %rax
sbb    %ebp,%ebp
or     $0x1,%ebp
mov    %rbx,%rdi
call   1050 <BN_free@plt>
mov    %r13,%rdi
call   1040 <BN_CTX_free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @id_sign(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%10 = call i32* (...) @BN_CTX_new()
store i32* %10, i32** %7
%11 = call i32* (...) @BN_new()
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = load i32*, i32** %5
%14 = load i32*, i32** %6
%15 = load i32*, i32** %7
%16 = call i32 @BN_mod_sqr(i32* %12, i32* %13, i32* %14, i32* %15)
%17 = load i32*, i32** %8
%18 = load i32*, i32** %4
%19 = call i64 @BN_cmp(i32* %17, i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %3
store i32 -1, i32* %9
br label %23
22: ; preds = %3
store i32 1, i32* %9
br label %23
23: ; preds = %22, %21
%24 = load i32*, i32** %8
%25 = call i32 @BN_free(i32* %24)
%26 = load i32*, i32** %7
%27 = call i32 @BN_CTX_free(i32* %26)
%28 = load i32, i32* %9
ret i32 %28
}

LLVM IR (-O2):
define i32 @id_sign(i32* %0, i32* %1, i32* %2) {
%4 = tail call i32* (...) @BN_CTX_new()
%5 = tail call i32* (...) @BN_new()
%6 = tail call i32 @BN_mod_sqr(i32* %5, i32* %1, i32* %2, i32* %4)
%7 = tail call i64 @BN_cmp(i32* %5, i32* %0)
%8 = icmp eq i64 %7, 0
%9 = select i1 %8, i32 1, i32 -1
%10 = tail call i32 @BN_free(i32* %5)
%11 = tail call i32 @BN_CTX_free(i32* %4)
ret i32 %9
}