#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();
int /*<<< orphan*/ BN_bin2bn(unsigned char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ *);
int BN_kronecker(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                 int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod_add(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod_mul(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_new();
int cocks_decrypt_bit(const BIGNUM *s, const BIGNUM *r, const BIGNUM *N) {
  BN_CTX *ctx = BN_CTX_new();
  BIGNUM *two, *tmp, *tmp2;
  int ret;
  two = BN_new();
  tmp = BN_new();
  tmp2 = BN_new();
  BN_bin2bn((unsigned char *)"\x2", 1, two);
  BN_mod_mul(tmp, r, two, N, ctx);
  BN_mod_add(tmp2, tmp, s, N, ctx);
  ret = BN_kronecker(tmp2, N, ctx);
  BN_free(tmp);
  BN_free(two);
  BN_CTX_free(ctx);
  return ret;
}


x86 assembly (clang, -O0):
<cocks_decrypt_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1080 <BN_CTX_new@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <BN_new@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <BN_new@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <BN_new@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdx
lea    0xe35(%rip),%rdi
mov    $0x1,%esi
call   1050 <BN_bin2bn@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1090 <BN_mod_mul@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   10a0 <BN_mod_add@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <BN_kronecker@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <BN_free@plt>
mov    -0x28(%rbp),%rdi
call   1070 <BN_free@plt>
mov    -0x20(%rbp),%rdi
call   1060 <BN_CTX_free@plt>
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cocks_decrypt_bit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,(%rsp)
xor    %eax,%eax
call   1080 <BN_CTX_new@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1040 <BN_new@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1040 <BN_new@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <BN_new@plt>
mov    %rax,%r12
lea    0xe3c(%rip),%rdi
mov    $0x1,%esi
mov    %r15,%rdx
call   1050 <BN_bin2bn@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %r13,%r8
call   1090 <BN_mod_mul@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    (%rsp),%rdx
mov    %r14,%rcx
mov    %r13,%r8
call   10a0 <BN_mod_add@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1030 <BN_kronecker@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <BN_free@plt>
mov    %r15,%rdi
call   1070 <BN_free@plt>
mov    %r13,%rdi
call   1060 <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):
@.str = [2 x i8] c"\02\00"
define i32 @cocks_decrypt_bit(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%12 = call i32* (...) @BN_CTX_new()
store i32* %12, i32** %7
%13 = call i32* (...) @BN_new()
store i32* %13, i32** %8
%14 = call i32* (...) @BN_new()
store i32* %14, i32** %9
%15 = call i32* (...) @BN_new()
store i32* %15, i32** %10
%16 = load i32*, i32** %8
%17 = call i32 @BN_bin2bn(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i32* %16)
%18 = load i32*, i32** %9
%19 = load i32*, i32** %5
%20 = load i32*, i32** %8
%21 = load i32*, i32** %6
%22 = load i32*, i32** %7
%23 = call i32 @BN_mod_mul(i32* %18, i32* %19, i32* %20, i32* %21, i32* %22)
%24 = load i32*, i32** %10
%25 = load i32*, i32** %9
%26 = load i32*, i32** %4
%27 = load i32*, i32** %6
%28 = load i32*, i32** %7
%29 = call i32 @BN_mod_add(i32* %24, i32* %25, i32* %26, i32* %27, i32* %28)
%30 = load i32*, i32** %10
%31 = load i32*, i32** %6
%32 = load i32*, i32** %7
%33 = call i32 @BN_kronecker(i32* %30, i32* %31, i32* %32)
store i32 %33, i32* %11
%34 = load i32*, i32** %9
%35 = call i32 @BN_free(i32* %34)
%36 = load i32*, i32** %8
%37 = call i32 @BN_free(i32* %36)
%38 = load i32*, i32** %7
%39 = call i32 @BN_CTX_free(i32* %38)
%40 = load i32, i32* %11
ret i32 %40
}

LLVM IR (-O2):
@.str = [2 x i8] c"\02\00"
define i32 @cocks_decrypt_bit(i32* %0, i32* %1, i32* %2) {
%4 = tail call i32* (...) @BN_CTX_new()
%5 = tail call i32* (...) @BN_new()
%6 = tail call i32* (...) @BN_new()
%7 = tail call i32* (...) @BN_new()
%8 = tail call i32 @BN_bin2bn(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i32* %5)
%9 = tail call i32 @BN_mod_mul(i32* %6, i32* %1, i32* %5, i32* %2, i32* %4)
%10 = tail call i32 @BN_mod_add(i32* %7, i32* %6, i32* %0, i32* %2, i32* %4)
%11 = tail call i32 @BN_kronecker(i32* %7, i32* %2, i32* %4)
%12 = tail call i32 @BN_free(i32* %6)
%13 = tail call i32 @BN_free(i32* %5)
%14 = tail call i32 @BN_CTX_free(i32* %4)
ret i32 %11
}