#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*/ const BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BN_bin2bn(unsigned char *, int, int /*<<< orphan*/ const *);
int /*<<< orphan*/ BN_copy(int /*<<< orphan*/ const *,
                           int /*<<< orphan*/ const *);
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ const *);
int /*<<< orphan*/ BN_mod_add(int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod_mul(int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod_sqr(int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ const *BN_new();
int /*<<< orphan*/ BN_num_bits(int /*<<< orphan*/ const *);
int /*<<< orphan*/ BN_rand(int /*<<< orphan*/ const *, int /*<<< orphan*/, int,
                           int /*<<< orphan*/);
int /*<<< orphan*/ get_jacobi(struct symbols_lst *, int /*<<< orphan*/ const **,
                              int /*<<< orphan*/ const **, int,
                              int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ poly_mul(int /*<<< orphan*/ const **,
                            int /*<<< orphan*/ const **,
                            int /*<<< orphan*/ const *const *,
                            int /*<<< orphan*/ const *,
                            int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int encrypt_component(BIGNUM **enc, const BIGNUM *N, const BIGNUM *a,
                      BIGNUM *const *g, int bit, int coin,
                      struct symbols_lst *jacobis, BN_CTX *ctx) {
  BIGNUM *t;
  BIGNUM *it;
  BIGNUM *two;
  BIGNUM *h;
  BIGNUM *hsqr;
  BIGNUM *tmp[2];
  if (bit != 1 && bit != -1)
    return -1;
  two = BN_new();
  BN_bin2bn((unsigned char *)"\x2", 1, two);
  get_jacobi(jacobis, &t, &it, bit, N, ctx);
  h = BN_new();
  hsqr = BN_new();
  BN_rand(h, BN_num_bits(N), -1, 0);
  BN_mod_sqr(hsqr, h, N, ctx);
  BN_mod_mul(enc[0], a, hsqr, N, ctx);
  tmp[0] = BN_new();
  tmp[1] = BN_new();
  BN_mod_mul(tmp[1], enc[0], it, N, ctx);
  BN_mod_add(enc[0], tmp[1], t, N, ctx);
  BN_mod_mul(enc[1], h, two, N, ctx);
  if (coin == 0) {
    poly_mul(tmp, enc, g, a, N, ctx);
    BN_copy(enc[0], tmp[0]);
    BN_copy(enc[1], tmp[1]);
  }
  BN_free(tmp[0]);
  BN_free(tmp[1]);
  BN_free(t);
  BN_free(it);
  BN_free(h);
  BN_free(hsqr);
  BN_free(two);
}


x86 assembly (clang, -O0):
<encrypt_component>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9d,-0x30(%rbp)
cmpl   $0x1,-0x2c(%rbp)
je     11fb <encrypt_component+0x4b>
cmpl   $0xffffffff,-0x2c(%rbp)
je     11fb <encrypt_component+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1393 <encrypt_component+0x1e3>
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdx
lea    0xdef(%rip),%rdi
mov    $0x1,%esi
call   1070 <BN_bin2bn@plt>
mov    0x10(%rbp),%rdi
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    0x18(%rbp),%r9
lea    -0x38(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1040 <get_jacobi@plt>
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <BN_num_bits@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%esi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    0x18(%rbp),%rcx
call   10c0 <BN_mod_sqr@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    0x18(%rbp),%r8
call   10a0 <BN_mod_mul@plt>
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x70(%rbp)
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    0x18(%rbp),%r8
call   10a0 <BN_mod_mul@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    0x18(%rbp),%r8
call   10d0 <BN_mod_add@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    0x18(%rbp),%r8
call   10a0 <BN_mod_mul@plt>
cmpl   $0x0,-0x30(%rbp)
jne    1354 <encrypt_component+0x1a4>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    0x18(%rbp),%r9
call   10b0 <poly_mul@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x70(%rbp),%rsi
call   1090 <BN_copy@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x68(%rbp),%rsi
call   1090 <BN_copy@plt>
mov    -0x70(%rbp),%rdi
call   1080 <BN_free@plt>
mov    -0x68(%rbp),%rdi
call   1080 <BN_free@plt>
mov    -0x38(%rbp),%rdi
call   1080 <BN_free@plt>
mov    -0x40(%rbp),%rdi
call   1080 <BN_free@plt>
mov    -0x50(%rbp),%rdi
call   1080 <BN_free@plt>
mov    -0x58(%rbp),%rdi
call   1080 <BN_free@plt>
mov    -0x48(%rbp),%rdi
call   1080 <BN_free@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encrypt_component>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r8d,%ebp
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r15
cmp    $0x1,%r8d
je     11d9 <encrypt_component+0x29>
cmp    $0xffffffff,%ebp
jne    1377 <encrypt_component+0x1c7>
mov    %rcx,0x40(%rsp)
mov    0x98(%rsp),%r13
mov    0x90(%rsp),%r14
xor    %eax,%eax
mov    %r9d,0xc(%rsp)
call   1050 <BN_new@plt>
mov    %rax,0x48(%rsp)
lea    0xdfa(%rip),%rdi
mov    $0x1,%esi
mov    %rax,%rdx
call   1070 <BN_bin2bn@plt>
lea    0x30(%rsp),%rsi
lea    0x28(%rsp),%rdx
mov    %r14,%rdi
mov    %ebp,%ecx
mov    %rbx,%r8
mov    %r13,%r9
mov    %r13,%r14
call   1040 <get_jacobi@plt>
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1060 <BN_num_bits@plt>
mov    %r13,%rdi
mov    %eax,%esi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   10c0 <BN_mod_sqr@plt>
mov    (%r15),%rdi
mov    %r12,%rsi
mov    %rbp,0x50(%rsp)
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %r14,%rbp
mov    %r14,%r8
call   10a0 <BN_mod_mul@plt>
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%r14
mov    %rax,0x10(%rsp)
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %r12,0x38(%rsp)
mov    %rax,%r12
mov    %rax,0x18(%rsp)
mov    (%r15),%rsi
mov    0x28(%rsp),%rdx
mov    %rax,%rdi
mov    %rbx,%rcx
mov    %rbp,%r8
call   10a0 <BN_mod_mul@plt>
mov    (%r15),%rdi
mov    0x30(%rsp),%rdx
mov    %r12,%rsi
mov    0x48(%rsp),%r12
mov    %rbx,%rcx
mov    %rbp,%r8
call   10d0 <BN_mod_add@plt>
mov    0x8(%r15),%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %rbp,%r8
call   10a0 <BN_mod_mul@plt>
cmpl   $0x0,0xc(%rsp)
jne    1337 <encrypt_component+0x187>
lea    0x10(%rsp),%rdi
mov    %r15,%rsi
mov    0x40(%rsp),%rdx
mov    0x38(%rsp),%rcx
mov    %rbx,%r8
mov    %rbp,%r9
call   10b0 <poly_mul@plt>
mov    (%r15),%rdi
mov    0x10(%rsp),%rsi
call   1090 <BN_copy@plt>
mov    0x8(%r15),%rdi
mov    0x18(%rsp),%rsi
call   1090 <BN_copy@plt>
mov    0x10(%rsp),%r14
mov    %r14,%rdi
call   1080 <BN_free@plt>
mov    0x18(%rsp),%rdi
call   1080 <BN_free@plt>
mov    0x30(%rsp),%rdi
call   1080 <BN_free@plt>
mov    0x28(%rsp),%rdi
call   1080 <BN_free@plt>
mov    %r13,%rdi
call   1080 <BN_free@plt>
mov    0x50(%rsp),%rdi
call   1080 <BN_free@plt>
mov    %r12,%rdi
call   1080 <BN_free@plt>
mov    $0xffffffff,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.symbols_lst = type { i32 }
@.str = [2 x i8] c"\02\00"
define i32 @encrypt_component(i32** %0, i32* %1, i32* %2, i32** %3, i32 %4, i32 %5, %struct.symbols_lst* %6, i32* %7) {
%9 = alloca i32
%10 = alloca i32**
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32**
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.symbols_lst*
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i32*
%20 = alloca i32*
%21 = alloca i32*
%22 = alloca i32*
%23 = alloca [2 x i32*]
store i32** %0, i32*** %10
store i32* %1, i32** %11
store i32* %2, i32** %12
store i32** %3, i32*** %13
store i32 %4, i32* %14
store i32 %5, i32* %15
store %struct.symbols_lst* %6, %struct.symbols_lst** %16
store i32* %7, i32** %17
%24 = load i32, i32* %14
%25 = icmp ne i32 %24, 1
br i1 %25, label %26, label %30
26: ; preds = %8
%27 = load i32, i32* %14
%28 = icmp ne i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 -1, i32* %9
br label %127
30: ; preds = %26, %8
%31 = call i32* (...) @BN_new()
store i32* %31, i32** %20
%32 = load i32*, i32** %20
%33 = call i32 @BN_bin2bn(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i32* %32)
%34 = load %struct.symbols_lst*, %struct.symbols_lst** %16
%35 = load i32, i32* %14
%36 = load i32*, i32** %11
%37 = load i32*, i32** %17
%38 = call i32 @get_jacobi(%struct.symbols_lst* %34, i32** %18, i32** %19, i32 %35, i32* %36, i32* %37)
%39 = call i32* (...) @BN_new()
store i32* %39, i32** %21
%40 = call i32* (...) @BN_new()
store i32* %40, i32** %22
%41 = load i32*, i32** %21
%42 = load i32*, i32** %11
%43 = call i32 @BN_num_bits(i32* %42)
%44 = call i32 @BN_rand(i32* %41, i32 %43, i32 -1, i32 0)
%45 = load i32*, i32** %22
%46 = load i32*, i32** %21
%47 = load i32*, i32** %11
%48 = load i32*, i32** %17
%49 = call i32 @BN_mod_sqr(i32* %45, i32* %46, i32* %47, i32* %48)
%50 = load i32**, i32*** %10
%51 = getelementptr inbounds i32*, i32** %50, i64 0
%52 = load i32*, i32** %51
%53 = load i32*, i32** %12
%54 = load i32*, i32** %22
%55 = load i32*, i32** %11
%56 = load i32*, i32** %17
%57 = call i32 @BN_mod_mul(i32* %52, i32* %53, i32* %54, i32* %55, i32* %56)
%58 = call i32* (...) @BN_new()
%59 = getelementptr inbounds [2 x i32*], [2 x i32*]* %23, i64 0, i64 0
store i32* %58, i32** %59
%60 = call i32* (...) @BN_new()
%61 = getelementptr inbounds [2 x i32*], [2 x i32*]* %23, i64 0, i64 1
store i32* %60, i32** %61
%62 = getelementptr inbounds [2 x i32*], [2 x i32*]* %23, i64 0, i64 1
%63 = load i32*, i32** %62
%64 = load i32**, i32*** %10
%65 = getelementptr inbounds i32*, i32** %64, i64 0
%66 = load i32*, i32** %65
%67 = load i32*, i32** %19
%68 = load i32*, i32** %11
%69 = load i32*, i32** %17
%70 = call i32 @BN_mod_mul(i32* %63, i32* %66, i32* %67, i32* %68, i32* %69)
%71 = load i32**, i32*** %10
%72 = getelementptr inbounds i32*, i32** %71, i64 0
%73 = load i32*, i32** %72
%74 = getelementptr inbounds [2 x i32*], [2 x i32*]* %23, i64 0, i64 1
%75 = load i32*, i32** %74
%76 = load i32*, i32** %18
%77 = load i32*, i32** %11
%78 = load i32*, i32** %17
%79 = call i32 @BN_mod_add(i32* %73, i32* %75, i32* %76, i32* %77, i32* %78)
%80 = load i32**, i32*** %10
%81 = getelementptr inbounds i32*, i32** %80, i64 1
%82 = load i32*, i32** %81
%83 = load i32*, i32** %21
%84 = load i32*, i32** %20
%85 = load i32*, i32** %11
%86 = load i32*, i32** %17
%87 = call i32 @BN_mod_mul(i32* %82, i32* %83, i32* %84, i32* %85, i32* %86)
%88 = load i32, i32* %15
%89 = icmp eq i32 %88, 0
br i1 %89, label %90, label %110
90: ; preds = %30
%91 = getelementptr inbounds [2 x i32*], [2 x i32*]* %23, i64 0, i64 0
%92 = load i32**, i32*** %10
%93 = load i32**, i32*** %13
%94 = load i32*, i32** %12
%95 = load i32*, i32** %11
%96 = load i32*, i32** %17
%97 = call i32 @poly_mul(i32** %91, i32** %92, i32** %93, i32* %94, i32* %95, i32* %96)
%98 = load i32**, i32*** %10
%99 = getelementptr inbounds i32*, i32** %98, i64 0
%100 = load i32*, i32** %99
%101 = getelementptr inbounds [2 x i32*], [2 x i32*]* %23, i64 0, i64 0
%102 = load i32*, i32** %101
%103 = call i32 @BN_copy(i32* %100, i32* %102)
%104 = load i32**, i32*** %10
%105 = getelementptr inbounds i32*, i32** %104, i64 1
%106 = load i32*, i32** %105
%107 = getelementptr inbounds [2 x i32*], [2 x i32*]* %23, i64 0, i64 1
%108 = load i32*, i32** %107
%109 = call i32 @BN_copy(i32* %106, i32* %108)
br label %110
110: ; preds = %90, %30
%111 = getelementptr inbounds [2 x i32*], [2 x i32*]* %23, i64 0, i64 0
%112 = load i32*, i32** %111
%113 = call i32 @BN_free(i32* %112)
%114 = getelementptr inbounds [2 x i32*], [2 x i32*]* %23, i64 0, i64 1
%115 = load i32*, i32** %114
%116 = call i32 @BN_free(i32* %115)
%117 = load i32*, i32** %18
%118 = call i32 @BN_free(i32* %117)
%119 = load i32*, i32** %19
%120 = call i32 @BN_free(i32* %119)
%121 = load i32*, i32** %21
%122 = call i32 @BN_free(i32* %121)
%123 = load i32*, i32** %22
%124 = call i32 @BN_free(i32* %123)
%125 = load i32*, i32** %20
%126 = call i32 @BN_free(i32* %125)
br label %127
127: ; preds = %110, %29
%128 = load i32, i32* %9
ret i32 %128
}

LLVM IR (-O2):
%struct.symbols_lst = type { i32 }
@.str = [2 x i8] c"\02\00"
define i32 @encrypt_component(i32** %0, i32* %1, i32* %2, i32** %3, i32 %4, i32 %5, %struct.symbols_lst* %6, i32* %7) {
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca [2 x i32*]
%12 = bitcast i32** %9 to i8*
%13 = bitcast i32** %10 to i8*
%14 = bitcast [2 x i32*]* %11 to i8*
switch i32 %4, label %61 [
i32 -1, label %15
i32 1, label %15
]
15: ; preds = %8, %8
%16 = tail call i32* (...) @BN_new()
%17 = tail call i32 @BN_bin2bn(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i32* %16)
%18 = call i32 @get_jacobi(%struct.symbols_lst* %6, i32** %9, i32** %10, i32 %4, i32* %1, i32* %7)
%19 = call i32* (...) @BN_new()
%20 = call i32* (...) @BN_new()
%21 = call i32 @BN_num_bits(i32* %1)
%22 = call i32 @BN_rand(i32* %19, i32 %21, i32 -1, i32 0)
%23 = call i32 @BN_mod_sqr(i32* %20, i32* %19, i32* %1, i32* %7)
%24 = load i32*, i32** %0
%25 = call i32 @BN_mod_mul(i32* %24, i32* %2, i32* %20, i32* %1, i32* %7)
%26 = call i32* (...) @BN_new()
%27 = getelementptr inbounds [2 x i32*], [2 x i32*]* %11, i64 0, i64 0
store i32* %26, i32** %27
%28 = call i32* (...) @BN_new()
%29 = getelementptr inbounds [2 x i32*], [2 x i32*]* %11, i64 0, i64 1
store i32* %28, i32** %29
%30 = load i32*, i32** %0
%31 = load i32*, i32** %10
%32 = call i32 @BN_mod_mul(i32* %28, i32* %30, i32* %31, i32* %1, i32* %7)
%33 = load i32*, i32** %0
%34 = load i32*, i32** %9
%35 = call i32 @BN_mod_add(i32* %33, i32* %28, i32* %34, i32* %1, i32* %7)
%36 = getelementptr inbounds i32*, i32** %0, i64 1
%37 = load i32*, i32** %36
%38 = call i32 @BN_mod_mul(i32* %37, i32* %19, i32* %16, i32* %1, i32* %7)
%39 = icmp eq i32 %5, 0
br i1 %39, label %40, label %49
40: ; preds = %15
%41 = call i32 @poly_mul(i32** %27, i32** %0, i32** %3, i32* %2, i32* %1, i32* %7)
%42 = load i32*, i32** %0
%43 = load i32*, i32** %27
%44 = call i32 @BN_copy(i32* %42, i32* %43)
%45 = load i32*, i32** %36
%46 = load i32*, i32** %29
%47 = call i32 @BN_copy(i32* %45, i32* %46)
%48 = load i32*, i32** %27
br label %49
49: ; preds = %40, %15
%50 = phi i32* [ %48, %40 ], [ %26, %15 ]
%51 = call i32 @BN_free(i32* %50)
%52 = load i32*, i32** %29
%53 = call i32 @BN_free(i32* %52)
%54 = load i32*, i32** %9
%55 = call i32 @BN_free(i32* %54)
%56 = load i32*, i32** %10
%57 = call i32 @BN_free(i32* %56)
%58 = call i32 @BN_free(i32* %19)
%59 = call i32 @BN_free(i32* %20)
%60 = call i32 @BN_free(i32* %16)
br label %61
61: ; preds = %8, %49
ret i32 -1
}