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

/* Variables and functions */
int /*<<< orphan*/ BN_bin2bn(unsigned char *, int, int /*<<< orphan*/ const *);
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ const *);
int BN_kronecker(int /*<<< orphan*/ const *, int /*<<< orphan*/ const *,
                 int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod_add(int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod_inverse(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*/ const *BN_new();
int decrypt_component(int c, int j, int kappa, const BIGNUM *R,
                      BIGNUM *const *xs, const BIGNUM *r, const BIGNUM *N,
                      BN_CTX *ctx) {
  BIGNUM *one;
  BIGNUM *tmp1;
  BIGNUM *tmp2;
  BIGNUM *tmp3;
  int j1;
  int j2;
  int bit;
  one = BN_new();
  BN_bin2bn((unsigned char *)"\x1", 1, one);
  tmp1 = BN_new();
  tmp2 = BN_new();
  tmp3 = BN_new();
  if (j < kappa) {
    BN_mod_mul(tmp1, xs[j], r, N, ctx);
    BN_mod_add(tmp2, tmp1, one, N, ctx);
    bit = c * BN_kronecker(tmp2, N, ctx);
  } else {
    j1 = j / kappa;
    j2 = j % kappa;
    BN_mod_mul(tmp1, xs[j1], xs[j2], N, ctx);
    BN_mod_mul(tmp2, R, tmp1, N, ctx);
    BN_mod_add(tmp1, tmp2, one, N, ctx);
    BN_mod_inverse(tmp2, tmp1, N, ctx);
    BN_mod_add(tmp1, xs[j1], xs[j2], N, ctx);
    BN_mod_mul(tmp3, tmp1, tmp2, N, ctx);
    BN_mod_mul(tmp1, tmp3, r, N, ctx);
    BN_mod_add(tmp2, tmp1, one, N, ctx);
    bit = c * BN_kronecker(tmp2, N, ctx);
  }
  BN_free(tmp1);
  BN_free(tmp2);
  BN_free(tmp3);
  BN_free(one);
  return bit;
}


x86 assembly (clang, -O0):
<decrypt_component>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdx
lea    0xe55(%rip),%rdi
mov    $0x1,%esi
call   1060 <BN_bin2bn@plt>
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1243 <decrypt_component+0xd3>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x28(%rbp),%rdx
mov    0x10(%rbp),%rcx
mov    0x18(%rbp),%r8
call   1080 <BN_mod_mul@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    0x10(%rbp),%rcx
mov    0x18(%rbp),%r8
call   1090 <BN_mod_add@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x10(%rbp),%rsi
mov    0x18(%rbp),%rdx
call   1030 <BN_kronecker@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x54(%rbp)
jmp    135d <decrypt_component+0x1ed>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x4c(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x50(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x20(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    0x10(%rbp),%rcx
mov    0x18(%rbp),%r8
call   1080 <BN_mod_mul@plt>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    0x10(%rbp),%rcx
mov    0x18(%rbp),%r8
call   1080 <BN_mod_mul@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    0x10(%rbp),%rcx
mov    0x18(%rbp),%r8
call   1090 <BN_mod_add@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x10(%rbp),%rdx
mov    0x18(%rbp),%rcx
call   1040 <BN_mod_inverse@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x20(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    0x10(%rbp),%rcx
mov    0x18(%rbp),%r8
call   1090 <BN_mod_add@plt>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    0x10(%rbp),%rcx
mov    0x18(%rbp),%r8
call   1080 <BN_mod_mul@plt>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    0x10(%rbp),%rcx
mov    0x18(%rbp),%r8
call   1080 <BN_mod_mul@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    0x10(%rbp),%rcx
mov    0x18(%rbp),%r8
call   1090 <BN_mod_add@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x10(%rbp),%rsi
mov    0x18(%rbp),%rdx
call   1030 <BN_kronecker@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x38(%rbp),%rdi
call   1070 <BN_free@plt>
mov    -0x40(%rbp),%rdi
call   1070 <BN_free@plt>
mov    -0x48(%rbp),%rdi
call   1070 <BN_free@plt>
mov    -0x30(%rbp),%rdi
call   1070 <BN_free@plt>
mov    -0x54(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decrypt_component>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,0x30(%rsp)
mov    %r8,%rbp
mov    %rcx,0x28(%rsp)
mov    %edx,%r15d
mov    %esi,%r13d
mov    %edi,0xc(%rsp)
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%rbx
lea    0xe5a(%rip),%rdi
mov    $0x1,%esi
mov    %rax,%rdx
call   1060 <BN_bin2bn@plt>
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%rcx
cmp    %r15d,%r13d
jge    11f3 <decrypt_component+0x83>
movslq %r13d,%rax
mov    0x0(%rbp,%rax,8),%rsi
mov    %rbx,%r15
mov    0x78(%rsp),%rbx
mov    0x70(%rsp),%rbp
mov    %rcx,%r13
jmp    12ba <decrypt_component+0x14a>
mov    %r13d,%eax
cltd
idiv   %r15d
cltq
mov    %rax,0x18(%rsp)
mov    0x0(%rbp,%rax,8),%rsi
movslq %edx,%rax
mov    %rax,0x10(%rsp)
mov    0x0(%rbp,%rax,8),%rdx
mov    %rcx,0x20(%rsp)
mov    %r12,%rdi
mov    0x70(%rsp),%r15
mov    %r15,%rcx
mov    0x78(%rsp),%r13
mov    %r13,%r8
call   1080 <BN_mod_mul@plt>
mov    %r14,%rdi
mov    0x28(%rsp),%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r13,%r8
call   1080 <BN_mod_mul@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r13,%r8
call   1090 <BN_mod_add@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r13,%rcx
call   1040 <BN_mod_inverse@plt>
mov    0x18(%rsp),%rax
mov    0x0(%rbp,%rax,8),%rsi
mov    0x10(%rsp),%rax
mov    0x0(%rbp,%rax,8),%rdx
mov    %r12,%rdi
mov    %r15,%rcx
mov    %r13,%r8
call   1090 <BN_mod_add@plt>
mov    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r13,%r8
call   1080 <BN_mod_mul@plt>
mov    %rbp,%rsi
mov    %rbp,%rax
mov    %rbx,%r15
mov    %r13,%rbx
mov    0x70(%rsp),%rbp
mov    %rax,%r13
mov    %r12,%rdi
mov    0x30(%rsp),%rdx
mov    %rbp,%rcx
mov    %rbx,%r8
call   1080 <BN_mod_mul@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
mov    %rbx,%r8
call   1090 <BN_mod_add@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <BN_kronecker@plt>
mov    %eax,%ebx
imul   0xc(%rsp),%ebx
mov    %r12,%rdi
call   1070 <BN_free@plt>
mov    %r14,%rdi
call   1070 <BN_free@plt>
mov    %r13,%rdi
call   1070 <BN_free@plt>
mov    %r15,%rdi
call   1070 <BN_free@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\01\00"
define i32 @decrypt_component(i32 %0, i32 %1, i32 %2, i32* %3, i32** %4, i32* %5, i32* %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 i32*
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i32*
%20 = alloca i32*
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
store i32 %0, i32* %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32* %3, i32** %12
store i32** %4, i32*** %13
store i32* %5, i32** %14
store i32* %6, i32** %15
store i32* %7, i32** %16
%24 = call i32* (...) @BN_new()
store i32* %24, i32** %17
%25 = load i32*, i32** %17
%26 = call i32 @BN_bin2bn(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i32* %25)
%27 = call i32* (...) @BN_new()
store i32* %27, i32** %18
%28 = call i32* (...) @BN_new()
store i32* %28, i32** %19
%29 = call i32* (...) @BN_new()
store i32* %29, i32** %20
%30 = load i32, i32* %10
%31 = load i32, i32* %11
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %56
33: ; preds = %8
%34 = load i32*, i32** %18
%35 = load i32**, i32*** %13
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32*, i32** %35, i64 %37
%39 = load i32*, i32** %38
%40 = load i32*, i32** %14
%41 = load i32*, i32** %15
%42 = load i32*, i32** %16
%43 = call i32 @BN_mod_mul(i32* %34, i32* %39, i32* %40, i32* %41, i32* %42)
%44 = load i32*, i32** %19
%45 = load i32*, i32** %18
%46 = load i32*, i32** %17
%47 = load i32*, i32** %15
%48 = load i32*, i32** %16
%49 = call i32 @BN_mod_add(i32* %44, i32* %45, i32* %46, i32* %47, i32* %48)
%50 = load i32, i32* %9
%51 = load i32*, i32** %19
%52 = load i32*, i32** %15
%53 = load i32*, i32** %16
%54 = call i32 @BN_kronecker(i32* %51, i32* %52, i32* %53)
%55 = mul nsw i32 %50, %54
store i32 %55, i32* %23
br label %132
56: ; preds = %8
%57 = load i32, i32* %10
%58 = load i32, i32* %11
%59 = sdiv i32 %57, %58
store i32 %59, i32* %21
%60 = load i32, i32* %10
%61 = load i32, i32* %11
%62 = srem i32 %60, %61
store i32 %62, i32* %22
%63 = load i32*, i32** %18
%64 = load i32**, i32*** %13
%65 = load i32, i32* %21
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32*, i32** %64, i64 %66
%68 = load i32*, i32** %67
%69 = load i32**, i32*** %13
%70 = load i32, i32* %22
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i32*, i32** %69, i64 %71
%73 = load i32*, i32** %72
%74 = load i32*, i32** %15
%75 = load i32*, i32** %16
%76 = call i32 @BN_mod_mul(i32* %63, i32* %68, i32* %73, i32* %74, i32* %75)
%77 = load i32*, i32** %19
%78 = load i32*, i32** %12
%79 = load i32*, i32** %18
%80 = load i32*, i32** %15
%81 = load i32*, i32** %16
%82 = call i32 @BN_mod_mul(i32* %77, i32* %78, i32* %79, i32* %80, i32* %81)
%83 = load i32*, i32** %18
%84 = load i32*, i32** %19
%85 = load i32*, i32** %17
%86 = load i32*, i32** %15
%87 = load i32*, i32** %16
%88 = call i32 @BN_mod_add(i32* %83, i32* %84, i32* %85, i32* %86, i32* %87)
%89 = load i32*, i32** %19
%90 = load i32*, i32** %18
%91 = load i32*, i32** %15
%92 = load i32*, i32** %16
%93 = call i32 @BN_mod_inverse(i32* %89, i32* %90, i32* %91, i32* %92)
%94 = load i32*, i32** %18
%95 = load i32**, i32*** %13
%96 = load i32, i32* %21
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i32*, i32** %95, i64 %97
%99 = load i32*, i32** %98
%100 = load i32**, i32*** %13
%101 = load i32, i32* %22
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i32*, i32** %100, i64 %102
%104 = load i32*, i32** %103
%105 = load i32*, i32** %15
%106 = load i32*, i32** %16
%107 = call i32 @BN_mod_add(i32* %94, i32* %99, i32* %104, i32* %105, i32* %106)
%108 = load i32*, i32** %20
%109 = load i32*, i32** %18
%110 = load i32*, i32** %19
%111 = load i32*, i32** %15
%112 = load i32*, i32** %16
%113 = call i32 @BN_mod_mul(i32* %108, i32* %109, i32* %110, i32* %111, i32* %112)
%114 = load i32*, i32** %18
%115 = load i32*, i32** %20
%116 = load i32*, i32** %14
%117 = load i32*, i32** %15
%118 = load i32*, i32** %16
%119 = call i32 @BN_mod_mul(i32* %114, i32* %115, i32* %116, i32* %117, i32* %118)
%120 = load i32*, i32** %19
%121 = load i32*, i32** %18
%122 = load i32*, i32** %17
%123 = load i32*, i32** %15
%124 = load i32*, i32** %16
%125 = call i32 @BN_mod_add(i32* %120, i32* %121, i32* %122, i32* %123, i32* %124)
%126 = load i32, i32* %9
%127 = load i32*, i32** %19
%128 = load i32*, i32** %15
%129 = load i32*, i32** %16
%130 = call i32 @BN_kronecker(i32* %127, i32* %128, i32* %129)
%131 = mul nsw i32 %126, %130
store i32 %131, i32* %23
br label %132
132: ; preds = %56, %33
%133 = load i32*, i32** %18
%134 = call i32 @BN_free(i32* %133)
%135 = load i32*, i32** %19
%136 = call i32 @BN_free(i32* %135)
%137 = load i32*, i32** %20
%138 = call i32 @BN_free(i32* %137)
%139 = load i32*, i32** %17
%140 = call i32 @BN_free(i32* %139)
%141 = load i32, i32* %23
ret i32 %141
}

LLVM IR (-O2):
@.str = [2 x i8] c"\01\00"
define i32 @decrypt_component(i32 %0, i32 %1, i32 %2, i32* %3, i32** nocapture %4, i32* %5, i32* %6, i32* %7) {
%9 = tail call i32* (...) @BN_new()
%10 = tail call i32 @BN_bin2bn(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i32* %9)
%11 = tail call i32* (...) @BN_new()
%12 = tail call i32* (...) @BN_new()
%13 = tail call i32* (...) @BN_new()
%14 = icmp slt i32 %1, %2
br i1 %14, label %15, label %19
15: ; preds = %8
%16 = sext i32 %1 to i64
%17 = getelementptr inbounds i32*, i32** %4, i64 %16
%18 = load i32*, i32** %17
br label %36
19: ; preds = %8
%20 = sdiv i32 %1, %2
%21 = srem i32 %1, %2
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i32*, i32** %4, i64 %22
%24 = load i32*, i32** %23
%25 = sext i32 %21 to i64
%26 = getelementptr inbounds i32*, i32** %4, i64 %25
%27 = load i32*, i32** %26
%28 = tail call i32 @BN_mod_mul(i32* %11, i32* %24, i32* %27, i32* %6, i32* %7)
%29 = tail call i32 @BN_mod_mul(i32* %12, i32* %3, i32* %11, i32* %6, i32* %7)
%30 = tail call i32 @BN_mod_add(i32* %11, i32* %12, i32* %9, i32* %6, i32* %7)
%31 = tail call i32 @BN_mod_inverse(i32* %12, i32* %11, i32* %6, i32* %7)
%32 = load i32*, i32** %23
%33 = load i32*, i32** %26
%34 = tail call i32 @BN_mod_add(i32* %11, i32* %32, i32* %33, i32* %6, i32* %7)
%35 = tail call i32 @BN_mod_mul(i32* %13, i32* %11, i32* %12, i32* %6, i32* %7)
br label %36
36: ; preds = %19, %15
%37 = phi i32* [ %13, %19 ], [ %18, %15 ]
%38 = tail call i32 @BN_mod_mul(i32* %11, i32* %37, i32* %5, i32* %6, i32* %7)
%39 = tail call i32 @BN_mod_add(i32* %12, i32* %11, i32* %9, i32* %6, i32* %7)
%40 = tail call i32 @BN_kronecker(i32* %12, i32* %6, i32* %7)
%41 = mul nsw i32 %40, %0
%42 = tail call i32 @BN_free(i32* %11)
%43 = tail call i32 @BN_free(i32* %12)
%44 = tail call i32 @BN_free(i32* %13)
%45 = tail call i32 @BN_free(i32* %9)
ret i32 %41
}