#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_RECP_CTX;
typedef int /*<<< orphan*/ BN_CTX;
typedef int /*<<< orphan*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BN_CTX_end(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_CTX_get(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_CTX_start(int /*<<< orphan*/ *);
int BN_div_recp(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                int /*<<< orphan*/ const *, int /*<<< orphan*/ *,
                int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mul(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                          int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_sqr(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ bn_check_top(int /*<<< orphan*/ *);
int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,
                          BN_RECP_CTX *recp, BN_CTX *ctx) {
  int ret = 0;
  BIGNUM *a;
  const BIGNUM *ca;
  BN_CTX_start(ctx);
  if ((a = BN_CTX_get(ctx)) == NULL)
    goto err;
  if (y != NULL) {
    if (x == y) {
      if (!BN_sqr(a, x, ctx))
        goto err;
    } else {
      if (!BN_mul(a, x, y, ctx))
        goto err;
    }
    ca = a;
  } else
    ca = x;
  ret = BN_div_recp(NULL, r, ca, recp, ctx);
err:
  BN_CTX_end(ctx);
  bn_check_top(r);
  return (ret);
}


x86 assembly (clang, -O0):
<BN_mod_mul_reciprocal>:
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,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <BN_CTX_start@plt>
mov    -0x28(%rbp),%rdi
call   1030 <BN_CTX_get@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11b8 <BN_mod_mul_reciprocal+0x48>
jmp    124e <BN_mod_mul_reciprocal+0xde>
cmpq   $0x0,-0x18(%rbp)
je     122a <BN_mod_mul_reciprocal+0xba>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11f5 <BN_mod_mul_reciprocal+0x85>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <BN_sqr@plt>
cmp    $0x0,%eax
jne    11f0 <BN_mod_mul_reciprocal+0x80>
jmp    124e <BN_mod_mul_reciprocal+0xde>
jmp    121d <BN_mod_mul_reciprocal+0xad>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1060 <BN_mul@plt>
cmp    $0x0,%eax
jne    1218 <BN_mod_mul_reciprocal+0xa8>
jmp    124e <BN_mod_mul_reciprocal+0xde>
jmp    121d <BN_mod_mul_reciprocal+0xad>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1232 <BN_mod_mul_reciprocal+0xc2>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edi
call   1090 <BN_div_recp@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <BN_CTX_end@plt>
mov    -0x8(%rbp),%rdi
call   1050 <bn_check_top@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BN_mod_mul_reciprocal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %rcx,(%rsp)
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %r8,%rdi
call   1080 <BN_CTX_start@plt>
mov    %rbx,%rdi
call   1030 <BN_CTX_get@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     11f2 <BN_mod_mul_reciprocal+0x82>
test   %rbp,%rbp
je     11c7 <BN_mod_mul_reciprocal+0x57>
mov    %rax,%r13
mov    %rax,%rdi
cmp    %rbp,%r15
je     11cc <BN_mod_mul_reciprocal+0x5c>
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
call   1060 <BN_mul@plt>
test   %eax,%eax
jne    11db <BN_mod_mul_reciprocal+0x6b>
jmp    11f2 <BN_mod_mul_reciprocal+0x82>
mov    %r15,%r13
jmp    11db <BN_mod_mul_reciprocal+0x6b>
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1040 <BN_sqr@plt>
test   %eax,%eax
je     11f2 <BN_mod_mul_reciprocal+0x82>
xor    %edi,%edi
mov    %r14,%rsi
mov    %r13,%rdx
mov    (%rsp),%rcx
mov    %rbx,%r8
call   1090 <BN_div_recp@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1070 <BN_CTX_end@plt>
mov    %r14,%rdi
call   1050 <bn_check_top@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @BN_mod_mul_reciprocal(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*
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* %11
%14 = load i32*, i32** %10
%15 = call i32 @BN_CTX_start(i32* %14)
%16 = load i32*, i32** %10
%17 = call i32* @BN_CTX_get(i32* %16)
store i32* %17, i32** %12
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %5
br label %54
20: ; preds = %5
%21 = load i32*, i32** %8
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %46
23: ; preds = %20
%24 = load i32*, i32** %7
%25 = load i32*, i32** %8
%26 = icmp eq i32* %24, %25
br i1 %26, label %27, label %35
27: ; preds = %23
%28 = load i32*, i32** %12
%29 = load i32*, i32** %7
%30 = load i32*, i32** %10
%31 = call i32 @BN_sqr(i32* %28, i32* %29, i32* %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %27
br label %54
34: ; preds = %27
br label %44
35: ; preds = %23
%36 = load i32*, i32** %12
%37 = load i32*, i32** %7
%38 = load i32*, i32** %8
%39 = load i32*, i32** %10
%40 = call i32 @BN_mul(i32* %36, i32* %37, i32* %38, i32* %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %35
br label %54
43: ; preds = %35
br label %44
44: ; preds = %43, %34
%45 = load i32*, i32** %12
store i32* %45, i32** %13
br label %48
46: ; preds = %20
%47 = load i32*, i32** %7
store i32* %47, i32** %13
br label %48
48: ; preds = %46, %44
%49 = load i32*, i32** %6
%50 = load i32*, i32** %13
%51 = load i32*, i32** %9
%52 = load i32*, i32** %10
%53 = call i32 @BN_div_recp(i32* null, i32* %49, i32* %50, i32* %51, i32* %52)
store i32 %53, i32* %11
br label %54
54: ; preds = %48, %42, %33, %19
%55 = load i32*, i32** %10
%56 = call i32 @BN_CTX_end(i32* %55)
%57 = load i32*, i32** %6
%58 = call i32 @bn_check_top(i32* %57)
%59 = load i32, i32* %11
ret i32 %59
}

LLVM IR (-O2):
define i32 @BN_mod_mul_reciprocal(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = tail call i32 @BN_CTX_start(i32* %4)
%7 = tail call i32* @BN_CTX_get(i32* %4)
%8 = icmp eq i32* %7, null
br i1 %8, label %22, label %9
9: ; preds = %5
%10 = icmp eq i32* %2, null
br i1 %10, label %19, label %11
11: ; preds = %9
%12 = icmp eq i32* %1, %2
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = tail call i32 @BN_sqr(i32* %7, i32* %2, i32* %4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %22, label %19
16: ; preds = %11
%17 = tail call i32 @BN_mul(i32* %7, i32* %1, i32* %2, i32* %4)
%18 = icmp eq i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %9, %13, %16
%20 = phi i32* [ %7, %16 ], [ %7, %13 ], [ %1, %9 ]
%21 = tail call i32 @BN_div_recp(i32* null, i32* %0, i32* %20, i32* %3, i32* %4)
br label %22
22: ; preds = %16, %13, %5, %19
%23 = phi i32 [ 0, %5 ], [ %21, %19 ], [ 0, %13 ], [ 0, %16 ]
%24 = tail call i32 @BN_CTX_end(i32* %4)
%25 = tail call i32 @bn_check_top(i32* %0)
ret i32 %23
}