#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_arr2poly(int const *, int /*<<< orphan*/ const *);
int BN_GF2m_mod_inv(int /*<<< orphan*/ const *, int /*<<< orphan*/ const *,
                    int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bn_check_top(int /*<<< orphan*/ const *);
int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *xx, const int p[],
                        BN_CTX *ctx) {
  BIGNUM *field;
  int ret = 0;
  bn_check_top(xx);
  BN_CTX_start(ctx);
  if ((field = BN_CTX_get(ctx)) == NULL)
    goto err;
  if (!BN_GF2m_arr2poly(p, field))
    goto err;
  ret = BN_GF2m_mod_inv(r, xx, field, ctx);
  bn_check_top(r);
err:
  BN_CTX_end(ctx);
  return ret;
}


x86 assembly (clang, -O0):
<BN_GF2m_mod_inv_arr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <bn_check_top@plt>
mov    -0x20(%rbp),%rdi
call   1070 <BN_CTX_start@plt>
mov    -0x20(%rbp),%rdi
call   1030 <BN_CTX_get@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11ad <BN_GF2m_mod_inv_arr+0x4d>
jmp    11e9 <BN_GF2m_mod_inv_arr+0x89>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <BN_GF2m_arr2poly@plt>
cmp    $0x0,%eax
jne    11c8 <BN_GF2m_mod_inv_arr+0x68>
jmp    11e9 <BN_GF2m_mod_inv_arr+0x89>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1040 <BN_GF2m_mod_inv@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <bn_check_top@plt>
mov    -0x20(%rbp),%rdi
call   1060 <BN_CTX_end@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BN_GF2m_mod_inv_arr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <bn_check_top@plt>
mov    %rbx,%rdi
call   1070 <BN_CTX_start@plt>
mov    %rbx,%rdi
call   1030 <BN_CTX_get@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     11c5 <BN_GF2m_mod_inv_arr+0x65>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %rax,%rsi
call   1080 <BN_GF2m_arr2poly@plt>
test   %eax,%eax
je     11c5 <BN_GF2m_mod_inv_arr+0x65>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
call   1040 <BN_GF2m_mod_inv@plt>
mov    %eax,%r13d
mov    %r14,%rdi
call   1050 <bn_check_top@plt>
mov    %rbx,%rdi
call   1060 <BN_CTX_end@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @BN_GF2m_mod_inv_arr(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i32 0, i32* %10
%11 = load i32*, i32** %6
%12 = call i32 @bn_check_top(i32* %11)
%13 = load i32*, i32** %8
%14 = call i32 @BN_CTX_start(i32* %13)
%15 = load i32*, i32** %8
%16 = call i32* @BN_CTX_get(i32* %15)
store i32* %16, i32** %9
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %4
br label %33
19: ; preds = %4
%20 = load i32*, i32** %7
%21 = load i32*, i32** %9
%22 = call i32 @BN_GF2m_arr2poly(i32* %20, i32* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %19
br label %33
25: ; preds = %19
%26 = load i32*, i32** %5
%27 = load i32*, i32** %6
%28 = load i32*, i32** %9
%29 = load i32*, i32** %8
%30 = call i32 @BN_GF2m_mod_inv(i32* %26, i32* %27, i32* %28, i32* %29)
store i32 %30, i32* %10
%31 = load i32*, i32** %5
%32 = call i32 @bn_check_top(i32* %31)
br label %33
33: ; preds = %25, %24, %18
%34 = load i32*, i32** %8
%35 = call i32 @BN_CTX_end(i32* %34)
%36 = load i32, i32* %10
ret i32 %36
}

LLVM IR (-O2):
define i32 @BN_GF2m_mod_inv_arr(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = tail call i32 @bn_check_top(i32* %1)
%6 = tail call i32 @BN_CTX_start(i32* %3)
%7 = tail call i32* @BN_CTX_get(i32* %3)
%8 = icmp eq i32* %7, null
br i1 %8, label %15, label %9
9: ; preds = %4
%10 = tail call i32 @BN_GF2m_arr2poly(i32* %2, i32* %7)
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @BN_GF2m_mod_inv(i32* %0, i32* %1, i32* %7, i32* %3)
%14 = tail call i32 @bn_check_top(i32* %0)
br label %15
15: ; preds = %9, %4, %12
%16 = phi i32 [ 0, %4 ], [ %13, %12 ], [ 0, %9 ]
%17 = tail call i32 @BN_CTX_end(i32* %3)
ret i32 %16
}