#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_div(int /*<<< orphan*/ const *, int /*<<< orphan*/ const *,
                    int /*<<< orphan*/ const *, int /*<<< orphan*/ const *,
                    int /*<<< orphan*/ *);
int /*<<< orphan*/ bn_check_top(int /*<<< orphan*/ const *);
int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *yy, const BIGNUM *xx,
                        const int p[], BN_CTX *ctx) {
  BIGNUM *field;
  int ret = 0;
  bn_check_top(yy);
  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_div(r, yy, xx, field, ctx);
  bn_check_top(r);
err:
  BN_CTX_end(ctx);
  return ret;
}


x86 assembly (clang, -O0):
<BN_GF2m_mod_div_arr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <bn_check_top@plt>
mov    -0x18(%rbp),%rdi
call   1040 <bn_check_top@plt>
mov    -0x28(%rbp),%rdi
call   1060 <BN_CTX_start@plt>
mov    -0x28(%rbp),%rdi
call   1030 <BN_CTX_get@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11ba <BN_GF2m_mod_div_arr+0x5a>
jmp    11fa <BN_GF2m_mod_div_arr+0x9a>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1080 <BN_GF2m_arr2poly@plt>
cmp    $0x0,%eax
jne    11d5 <BN_GF2m_mod_div_arr+0x75>
jmp    11fa <BN_GF2m_mod_div_arr+0x9a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1070 <BN_GF2m_mod_div@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <bn_check_top@plt>
mov    -0x28(%rbp),%rdi
call   1050 <BN_CTX_end@plt>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BN_GF2m_mod_div_arr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %rcx,%r13
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,(%rsp)
mov    %rsi,%rdi
call   1040 <bn_check_top@plt>
mov    %r15,%rdi
call   1040 <bn_check_top@plt>
mov    %rbx,%rdi
call   1060 <BN_CTX_start@plt>
mov    %rbx,%rdi
call   1030 <BN_CTX_get@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11d6 <BN_GF2m_mod_div_arr+0x76>
mov    %rax,%r14
mov    %r13,%rdi
mov    %rax,%rsi
call   1080 <BN_GF2m_arr2poly@plt>
test   %eax,%eax
je     11d6 <BN_GF2m_mod_div_arr+0x76>
mov    (%rsp),%r13
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
call   1070 <BN_GF2m_mod_div@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1040 <bn_check_top@plt>
mov    %rbx,%rdi
call   1050 <BN_CTX_end@plt>
mov    %ebp,%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_div_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
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
store i32 0, i32* %12
%13 = load i32*, i32** %7
%14 = call i32 @bn_check_top(i32* %13)
%15 = load i32*, i32** %8
%16 = call i32 @bn_check_top(i32* %15)
%17 = load i32*, i32** %10
%18 = call i32 @BN_CTX_start(i32* %17)
%19 = load i32*, i32** %10
%20 = call i32* @BN_CTX_get(i32* %19)
store i32* %20, i32** %11
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %23
22: ; preds = %5
br label %38
23: ; preds = %5
%24 = load i32*, i32** %9
%25 = load i32*, i32** %11
%26 = call i32 @BN_GF2m_arr2poly(i32* %24, i32* %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %23
br label %38
29: ; preds = %23
%30 = load i32*, i32** %6
%31 = load i32*, i32** %7
%32 = load i32*, i32** %8
%33 = load i32*, i32** %11
%34 = load i32*, i32** %10
%35 = call i32 @BN_GF2m_mod_div(i32* %30, i32* %31, i32* %32, i32* %33, i32* %34)
store i32 %35, i32* %12
%36 = load i32*, i32** %6
%37 = call i32 @bn_check_top(i32* %36)
br label %38
38: ; preds = %29, %28, %22
%39 = load i32*, i32** %10
%40 = call i32 @BN_CTX_end(i32* %39)
%41 = load i32, i32* %12
ret i32 %41
}

LLVM IR (-O2):
define i32 @BN_GF2m_mod_div_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 i32 @BN_CTX_start(i32* %4)
%9 = tail call i32* @BN_CTX_get(i32* %4)
%10 = icmp eq i32* %9, null
br i1 %10, label %17, label %11
11: ; preds = %5
%12 = tail call i32 @BN_GF2m_arr2poly(i32* %3, i32* %9)
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = tail call i32 @BN_GF2m_mod_div(i32* %0, i32* %1, i32* %2, i32* %9, i32* %4)
%16 = tail call i32 @bn_check_top(i32* %0)
br label %17
17: ; preds = %11, %5, %14
%18 = phi i32 [ 0, %5 ], [ %15, %14 ], [ 0, %11 ]
%19 = tail call i32 @BN_CTX_end(i32* %4)
ret i32 %18
}