#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 */
struct symbols_lst {
  int dummy;
};
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_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod_add(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/ *, 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 /*<<< orphan*/ get_jacobi(struct symbols_lst *, int /*<<< orphan*/ **,
                              int /*<<< orphan*/ **, int,
                              int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int cocks_encrypt_bit(struct symbols_lst *jacobis, BIGNUM *enc, const BIGNUM *N,
                      const BIGNUM *a, int bit) {
  BN_CTX *ctx = BN_CTX_new();
  BIGNUM *t, *it, *tmp;
  if (bit != 1 && bit != -1)
    return 1;
  get_jacobi(jacobis, &t, &it, bit, N, ctx);
  tmp = BN_new();
  BN_mod_mul(tmp, a, it, N, ctx);
  BN_mod_add(enc, tmp, t, N, ctx);
  BN_free(tmp);
  BN_free(t);
  BN_free(it);
  BN_CTX_free(ctx);
  return 0;
}


x86 assembly (clang, -O0):
<cocks_encrypt_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    $0x0,%al
call   1070 <BN_CTX_new@plt>
mov    %rax,-0x38(%rbp)
cmpl   $0x1,-0x2c(%rbp)
je     11b7 <cocks_encrypt_bit+0x47>
cmpl   $0xffffffff,-0x2c(%rbp)
je     11b7 <cocks_encrypt_bit+0x47>
movl   $0x1,-0x4(%rbp)
jmp    123b <cocks_encrypt_bit+0xcb>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x38(%rbp),%r9
lea    -0x40(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   1030 <get_jacobi@plt>
mov    $0x0,%al
call   1040 <BN_new@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%r8
call   1080 <BN_mod_mul@plt>
mov    -0x18(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%r8
call   1090 <BN_mod_add@plt>
mov    -0x50(%rbp),%rdi
call   1060 <BN_free@plt>
mov    -0x40(%rbp),%rdi
call   1060 <BN_free@plt>
mov    -0x48(%rbp),%rdi
call   1060 <BN_free@plt>
mov    -0x38(%rbp),%rdi
call   1050 <BN_CTX_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cocks_encrypt_bit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%ebp
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
xor    %eax,%eax
call   1070 <BN_CTX_new@plt>
mov    %rax,%rbx
cmp    $0x1,%ebp
je     11a6 <cocks_encrypt_bit+0x36>
mov    $0x1,%eax
cmp    $0xffffffff,%ebp
jne    121c <cocks_encrypt_bit+0xac>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r13,%rdi
mov    %ebp,%ecx
mov    %r14,%r8
mov    %rbx,%r9
call   1030 <get_jacobi@plt>
xor    %eax,%eax
call   1040 <BN_new@plt>
mov    %rax,%rbp
mov    0x8(%rsp),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r14,%rcx
mov    %rbx,%r8
call   1080 <BN_mod_mul@plt>
mov    0x10(%rsp),%rdx
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r14,%rcx
mov    %rbx,%r8
call   1090 <BN_mod_add@plt>
mov    %rbp,%rdi
call   1060 <BN_free@plt>
mov    0x10(%rsp),%rdi
call   1060 <BN_free@plt>
mov    0x8(%rsp),%rdi
call   1060 <BN_free@plt>
mov    %rbx,%rdi
call   1050 <BN_CTX_free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.symbols_lst = type { i32 }
define i32 @cocks_encrypt_bit(%struct.symbols_lst* %0, i32* %1, i32* %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca %struct.symbols_lst*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
store %struct.symbols_lst* %0, %struct.symbols_lst** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
%16 = call i32* (...) @BN_CTX_new()
store i32* %16, i32** %12
%17 = load i32, i32* %11
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %5
%20 = load i32, i32* %11
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 1, i32* %6
br label %50
23: ; preds = %19, %5
%24 = load %struct.symbols_lst*, %struct.symbols_lst** %7
%25 = load i32, i32* %11
%26 = load i32*, i32** %9
%27 = load i32*, i32** %12
%28 = call i32 @get_jacobi(%struct.symbols_lst* %24, i32** %13, i32** %14, i32 %25, i32* %26, i32* %27)
%29 = call i32* (...) @BN_new()
store i32* %29, i32** %15
%30 = load i32*, i32** %15
%31 = load i32*, i32** %10
%32 = load i32*, i32** %14
%33 = load i32*, i32** %9
%34 = load i32*, i32** %12
%35 = call i32 @BN_mod_mul(i32* %30, i32* %31, i32* %32, i32* %33, i32* %34)
%36 = load i32*, i32** %8
%37 = load i32*, i32** %15
%38 = load i32*, i32** %13
%39 = load i32*, i32** %9
%40 = load i32*, i32** %12
%41 = call i32 @BN_mod_add(i32* %36, i32* %37, i32* %38, i32* %39, i32* %40)
%42 = load i32*, i32** %15
%43 = call i32 @BN_free(i32* %42)
%44 = load i32*, i32** %13
%45 = call i32 @BN_free(i32* %44)
%46 = load i32*, i32** %14
%47 = call i32 @BN_free(i32* %46)
%48 = load i32*, i32** %12
%49 = call i32 @BN_CTX_free(i32* %48)
store i32 0, i32* %6
br label %50
50: ; preds = %23, %22
%51 = load i32, i32* %6
ret i32 %51
}

LLVM IR (-O2):
%struct.symbols_lst = type { i32 }
define i32 @cocks_encrypt_bit(%struct.symbols_lst* %0, i32* %1, i32* %2, i32* %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = tail call i32* (...) @BN_CTX_new()
%9 = bitcast i32** %6 to i8*
%10 = bitcast i32** %7 to i8*
switch i32 %4, label %24 [
i32 -1, label %11
i32 1, label %11
]
11: ; preds = %5, %5
%12 = call i32 @get_jacobi(%struct.symbols_lst* %0, i32** %6, i32** %7, i32 %4, i32* %2, i32* %8)
%13 = call i32* (...) @BN_new()
%14 = load i32*, i32** %7
%15 = call i32 @BN_mod_mul(i32* %13, i32* %3, i32* %14, i32* %2, i32* %8)
%16 = load i32*, i32** %6
%17 = call i32 @BN_mod_add(i32* %1, i32* %13, i32* %16, i32* %2, i32* %8)
%18 = call i32 @BN_free(i32* %13)
%19 = load i32*, i32** %6
%20 = call i32 @BN_free(i32* %19)
%21 = load i32*, i32** %7
%22 = call i32 @BN_free(i32* %21)
%23 = call i32 @BN_CTX_free(i32* %8)
br label %24
24: ; preds = %5, %11
%25 = phi i32 [ 0, %11 ], [ 1, %5 ]
ret i32 %25
}