#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_CTX_end(int /*<<< orphan*/ *);
int /*<<< orphan*/ const *BN_CTX_get(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_CTX_start(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_GF2m_mod_arr(int /*<<< orphan*/ const *,
                                   int /*<<< orphan*/ const *, int const *);
int /*<<< orphan*/ BN_GF2m_mod_mul_arr(int /*<<< orphan*/ const *,
                                       int /*<<< orphan*/ const *,
                                       int /*<<< orphan*/ const *, int const *,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_GF2m_mod_sqr_arr(int /*<<< orphan*/ const *,
                                       int /*<<< orphan*/ const *, int const *,
                                       int /*<<< orphan*/ *);
scalar_t__ BN_abs_is_word(int /*<<< orphan*/ const *, int);
int /*<<< orphan*/ *BN_copy(int /*<<< orphan*/ const *,
                            int /*<<< orphan*/ const *);
scalar_t__ BN_is_bit_set(int /*<<< orphan*/ const *, int);
scalar_t__ BN_is_zero(int /*<<< orphan*/ const *);
int BN_num_bits(int /*<<< orphan*/ const *);
int BN_one(int /*<<< orphan*/ const *);
int /*<<< orphan*/ bn_check_top(int /*<<< orphan*/ const *);
int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
                        const int p[], BN_CTX *ctx) {
  int ret = 0, i, n;
  BIGNUM *u;
  bn_check_top(a);
  bn_check_top(b);
  if (BN_is_zero(b))
    return (BN_one(r));
  if (BN_abs_is_word(b, 1))
    return (BN_copy(r, a) != NULL);
  BN_CTX_start(ctx);
  if ((u = BN_CTX_get(ctx)) == NULL)
    goto err;
  if (!BN_GF2m_mod_arr(u, a, p))
    goto err;
  n = BN_num_bits(b) - 1;
  for (i = n - 1; i >= 0; i--) {
    if (!BN_GF2m_mod_sqr_arr(u, u, p, ctx))
      goto err;
    if (BN_is_bit_set(b, i)) {
      if (!BN_GF2m_mod_mul_arr(u, u, a, p, ctx))
        goto err;
    }
  }
  if (!BN_copy(r, u))
    goto err;
  bn_check_top(r);
  ret = 1;
err:
  BN_CTX_end(ctx);
  return ret;
}


x86 assembly (clang, -O0):
<BN_GF2m_mod_exp_arr>:
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    %r8,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <bn_check_top@plt>
mov    -0x20(%rbp),%rdi
call   1070 <bn_check_top@plt>
mov    -0x20(%rbp),%rdi
call   10c0 <BN_is_zero@plt>
cmp    $0x0,%rax
je     1229 <BN_GF2m_mod_exp_arr+0x59>
mov    -0x10(%rbp),%rdi
call   10e0 <BN_one@plt>
mov    %eax,-0x4(%rbp)
jmp    137b <BN_GF2m_mod_exp_arr+0x1ab>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   10d0 <BN_abs_is_word@plt>
cmp    $0x0,%rax
je     1262 <BN_GF2m_mod_exp_arr+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <BN_copy@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    137b <BN_GF2m_mod_exp_arr+0x1ab>
mov    -0x30(%rbp),%rdi
call   1090 <BN_CTX_start@plt>
mov    -0x30(%rbp),%rdi
call   1030 <BN_CTX_get@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    1287 <BN_GF2m_mod_exp_arr+0xb7>
jmp    136c <BN_GF2m_mod_exp_arr+0x19c>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <BN_GF2m_mod_arr@plt>
cmp    $0x0,%eax
jne    12a6 <BN_GF2m_mod_exp_arr+0xd6>
jmp    136c <BN_GF2m_mod_exp_arr+0x19c>
mov    -0x20(%rbp),%rdi
call   1060 <BN_num_bits@plt>
sub    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jl     1340 <BN_GF2m_mod_exp_arr+0x170>
mov    -0x48(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   10f0 <BN_GF2m_mod_sqr_arr@plt>
cmp    $0x0,%eax
jne    12eb <BN_GF2m_mod_exp_arr+0x11b>
jmp    136c <BN_GF2m_mod_exp_arr+0x19c>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   10a0 <BN_is_bit_set@plt>
cmp    $0x0,%rax
je     132d <BN_GF2m_mod_exp_arr+0x15d>
mov    -0x48(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1050 <BN_GF2m_mod_mul_arr@plt>
cmp    $0x0,%eax
jne    1328 <BN_GF2m_mod_exp_arr+0x158>
jmp    136c <BN_GF2m_mod_exp_arr+0x19c>
jmp    132d <BN_GF2m_mod_exp_arr+0x15d>
jmp    1332 <BN_GF2m_mod_exp_arr+0x162>
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    12be <BN_GF2m_mod_exp_arr+0xee>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   10b0 <BN_copy@plt>
cmp    $0x0,%rax
jne    135c <BN_GF2m_mod_exp_arr+0x18c>
jmp    136c <BN_GF2m_mod_exp_arr+0x19c>
mov    -0x10(%rbp),%rdi
call   1070 <bn_check_top@plt>
movl   $0x1,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1080 <BN_CTX_end@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BN_GF2m_mod_exp_arr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r12
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1070 <bn_check_top@plt>
mov    %rbp,%rdi
call   1070 <bn_check_top@plt>
mov    %rbp,%rdi
call   10c0 <BN_is_zero@plt>
test   %rax,%rax
je     121d <BN_GF2m_mod_exp_arr+0x4d>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10e0 <BN_one@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
call   10d0 <BN_abs_is_word@plt>
test   %rax,%rax
je     1247 <BN_GF2m_mod_exp_arr+0x77>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10b0 <BN_copy@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
jmp    12e6 <BN_GF2m_mod_exp_arr+0x116>
mov    %r14,%rdi
call   1090 <BN_CTX_start@plt>
mov    %r14,%rdi
call   1030 <BN_CTX_get@plt>
test   %rax,%rax
je     12dc <BN_GF2m_mod_exp_arr+0x10c>
mov    %rax,%r13
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <BN_GF2m_mod_arr@plt>
test   %eax,%eax
je     12dc <BN_GF2m_mod_exp_arr+0x10c>
mov    %r14,(%rsp)
mov    %rbp,%rdi
call   1060 <BN_num_bits@plt>
cmp    $0x2,%eax
jl     12f7 <BN_GF2m_mod_exp_arr+0x127>
mov    %eax,%r14d
add    $0xffffffff,%r14d
jmp    1295 <BN_GF2m_mod_exp_arr+0xc5>
nop
test   %r14d,%r14d
jle    12f7 <BN_GF2m_mod_exp_arr+0x127>
mov    %r13,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    (%rsp),%rcx
call   10f0 <BN_GF2m_mod_sqr_arr@plt>
test   %eax,%eax
je     12d8 <BN_GF2m_mod_exp_arr+0x108>
add    $0xffffffff,%r14d
mov    %rbp,%rdi
mov    %r14d,%esi
call   10a0 <BN_is_bit_set@plt>
test   %rax,%rax
je     1290 <BN_GF2m_mod_exp_arr+0xc0>
mov    %r13,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    (%rsp),%r8
call   1050 <BN_GF2m_mod_mul_arr@plt>
test   %eax,%eax
jne    1290 <BN_GF2m_mod_exp_arr+0xc0>
mov    (%rsp),%r14
xor    %ebx,%ebx
mov    %r14,%rdi
call   1080 <BN_CTX_end@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
mov    %r13,%rsi
call   10b0 <BN_copy@plt>
test   %rax,%rax
mov    (%rsp),%r14
mov    $0x0,%ebx
je     12de <BN_GF2m_mod_exp_arr+0x10e>
mov    %r15,%rdi
call   1070 <bn_check_top@plt>
mov    $0x1,%ebx
jmp    12de <BN_GF2m_mod_exp_arr+0x10e>

LLVM IR (-O0):
define i32 @BN_GF2m_mod_exp_arr(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32*
%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 i32* %0, i32** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32 0, i32* %12
%16 = load i32*, i32** %8
%17 = call i32 @bn_check_top(i32* %16)
%18 = load i32*, i32** %9
%19 = call i32 @bn_check_top(i32* %18)
%20 = load i32*, i32** %9
%21 = call i64 @BN_is_zero(i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %5
%24 = load i32*, i32** %7
%25 = call i32 @BN_one(i32* %24)
store i32 %25, i32* %6
br label %99
26: ; preds = %5
%27 = load i32*, i32** %9
%28 = call i64 @BN_abs_is_word(i32* %27, i32 1)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load i32*, i32** %7
%32 = load i32*, i32** %8
%33 = call i32* @BN_copy(i32* %31, i32* %32)
%34 = icmp ne i32* %33, null
%35 = zext i1 %34 to i32
store i32 %35, i32* %6
br label %99
36: ; preds = %26
%37 = load i32*, i32** %11
%38 = call i32 @BN_CTX_start(i32* %37)
%39 = load i32*, i32** %11
%40 = call i32* @BN_CTX_get(i32* %39)
store i32* %40, i32** %15
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %43
42: ; preds = %36
br label %95
43: ; preds = %36
%44 = load i32*, i32** %15
%45 = load i32*, i32** %8
%46 = load i32*, i32** %10
%47 = call i32 @BN_GF2m_mod_arr(i32* %44, i32* %45, i32* %46)
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %43
br label %95
50: ; preds = %43
%51 = load i32*, i32** %9
%52 = call i32 @BN_num_bits(i32* %51)
%53 = sub nsw i32 %52, 1
store i32 %53, i32* %14
%54 = load i32, i32* %14
%55 = sub nsw i32 %54, 1
store i32 %55, i32* %13
br label %56
56: ; preds = %83, %50
%57 = load i32, i32* %13
%58 = icmp sge i32 %57, 0
br i1 %58, label %59, label %86
59: ; preds = %56
%60 = load i32*, i32** %15
%61 = load i32*, i32** %15
%62 = load i32*, i32** %10
%63 = load i32*, i32** %11
%64 = call i32 @BN_GF2m_mod_sqr_arr(i32* %60, i32* %61, i32* %62, i32* %63)
%65 = icmp ne i32 %64, 0
br i1 %65, label %67, label %66
66: ; preds = %59
br label %95
67: ; preds = %59
%68 = load i32*, i32** %9
%69 = load i32, i32* %13
%70 = call i64 @BN_is_bit_set(i32* %68, i32 %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %82
72: ; preds = %67
%73 = load i32*, i32** %15
%74 = load i32*, i32** %15
%75 = load i32*, i32** %8
%76 = load i32*, i32** %10
%77 = load i32*, i32** %11
%78 = call i32 @BN_GF2m_mod_mul_arr(i32* %73, i32* %74, i32* %75, i32* %76, i32* %77)
%79 = icmp ne i32 %78, 0
br i1 %79, label %81, label %80
80: ; preds = %72
br label %95
81: ; preds = %72
br label %82
82: ; preds = %81, %67
br label %83
83: ; preds = %82
%84 = load i32, i32* %13
%85 = add nsw i32 %84, -1
store i32 %85, i32* %13
br label %56
86: ; preds = %56
%87 = load i32*, i32** %7
%88 = load i32*, i32** %15
%89 = call i32* @BN_copy(i32* %87, i32* %88)
%90 = icmp ne i32* %89, null
br i1 %90, label %92, label %91
91: ; preds = %86
br label %95
92: ; preds = %86
%93 = load i32*, i32** %7
%94 = call i32 @bn_check_top(i32* %93)
store i32 1, i32* %12
br label %95
95: ; preds = %92, %91, %80, %66, %49, %42
%96 = load i32*, i32** %11
%97 = call i32 @BN_CTX_end(i32* %96)
%98 = load i32, i32* %12
store i32 %98, i32* %6
br label %99
99: ; preds = %95, %30, %23
%100 = load i32, i32* %6
ret i32 %100
}

LLVM IR (-O2):
define i32 @BN_GF2m_mod_exp_arr(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = tail call i32 @bn_check_top(i32* %1)
%7 = tail call i32 @bn_check_top(i32* %2)
%8 = tail call i64 @BN_is_zero(i32* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %5
%11 = tail call i32 @BN_one(i32* %0)
br label %52
12: ; preds = %5
%13 = tail call i64 @BN_abs_is_word(i32* %2, i32 1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = tail call i32* @BN_copy(i32* %0, i32* %1)
%17 = icmp ne i32* %16, null
%18 = zext i1 %17 to i32
br label %52
19: ; preds = %12
%20 = tail call i32 @BN_CTX_start(i32* %4)
%21 = tail call i32* @BN_CTX_get(i32* %4)
%22 = icmp eq i32* %21, null
br i1 %22, label %49, label %23
23: ; preds = %19
%24 = tail call i32 @BN_GF2m_mod_arr(i32* %21, i32* %1, i32* %3)
%25 = icmp eq i32 %24, 0
br i1 %25, label %49, label %26
26: ; preds = %23
%27 = tail call i32 @BN_num_bits(i32* %2)
%28 = icmp sgt i32 %27, 1
br i1 %28, label %29, label %44
29: ; preds = %26
%30 = add nsw i32 %27, -2
br label %31
31: ; preds = %29, %41
%32 = phi i32 [ %42, %41 ], [ %30, %29 ]
%33 = tail call i32 @BN_GF2m_mod_sqr_arr(i32* %21, i32* %21, i32* %3, i32* %4)
%34 = icmp eq i32 %33, 0
br i1 %34, label %49, label %35
35: ; preds = %31
%36 = tail call i64 @BN_is_bit_set(i32* %2, i32 %32)
%37 = icmp eq i64 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %35
%39 = tail call i32 @BN_GF2m_mod_mul_arr(i32* %21, i32* %21, i32* %1, i32* %3, i32* %4)
%40 = icmp eq i32 %39, 0
br i1 %40, label %49, label %41
41: ; preds = %35, %38
%42 = add nsw i32 %32, -1
%43 = icmp sgt i32 %32, 0
br i1 %43, label %31, label %44
44: ; preds = %41, %26
%45 = tail call i32* @BN_copy(i32* %0, i32* %21)
%46 = icmp eq i32* %45, null
br i1 %46, label %49, label %47
47: ; preds = %44
%48 = tail call i32 @bn_check_top(i32* %0)
br label %49
49: ; preds = %38, %31, %44, %23, %19, %47
%50 = phi i32 [ 0, %19 ], [ 1, %47 ], [ 0, %44 ], [ 0, %23 ], [ 0, %31 ], [ 0, %38 ]
%51 = tail call i32 @BN_CTX_end(i32* %4)
br label %52
52: ; preds = %49, %15, %10
%53 = phi i32 [ %11, %10 ], [ %18, %15 ], [ %50, %49 ]
ret i32 %53
}