#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*/ 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 /*<<< orphan*/ BN_div(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_set_bit(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ bn_check_top(int /*<<< orphan*/ *);
int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx) {
  int ret = -1;
  BIGNUM *t;
  BN_CTX_start(ctx);
  if ((t = BN_CTX_get(ctx)) == NULL)
    goto err;
  if (!BN_set_bit(t, len))
    goto err;
  if (!BN_div(r, NULL, t, m, ctx))
    goto err;
  ret = len;
err:
  bn_check_top(r);
  BN_CTX_end(ctx);
  return (ret);
}


x86 assembly (clang, -O0):
<BN_reciprocal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <BN_CTX_start@plt>
mov    -0x20(%rbp),%rdi
call   1030 <BN_CTX_get@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11a3 <BN_reciprocal+0x43>
jmp    11ea <BN_reciprocal+0x8a>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <BN_set_bit@plt>
cmp    $0x0,%eax
jne    11bd <BN_reciprocal+0x5d>
jmp    11ea <BN_reciprocal+0x8a>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%r8
xor    %eax,%eax
mov    %eax,%esi
call   1080 <BN_div@plt>
cmp    $0x0,%eax
jne    11e4 <BN_reciprocal+0x84>
jmp    11ea <BN_reciprocal+0x8a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <bn_check_top@plt>
mov    -0x20(%rbp),%rdi
call   1050 <BN_CTX_end@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BN_reciprocal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r13
mov    %edx,%r12d
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rcx,%rdi
call   1060 <BN_CTX_start@plt>
mov    %r13,%rdi
call   1030 <BN_CTX_get@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     11be <BN_reciprocal+0x5e>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12d,%esi
call   1070 <BN_set_bit@plt>
test   %eax,%eax
je     11be <BN_reciprocal+0x5e>
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r13,%r8
call   1080 <BN_div@plt>
cmp    $0x1,%eax
sbb    %ebp,%ebp
or     %r12d,%ebp
mov    %r14,%rdi
call   1040 <bn_check_top@plt>
mov    %r13,%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_reciprocal(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 -1, i32* %9
%11 = load i32*, i32** %8
%12 = call i32 @BN_CTX_start(i32* %11)
%13 = load i32*, i32** %8
%14 = call i32* @BN_CTX_get(i32* %13)
store i32* %14, i32** %10
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %4
br label %33
17: ; preds = %4
%18 = load i32*, i32** %10
%19 = load i32, i32* %7
%20 = call i32 @BN_set_bit(i32* %18, i32 %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %17
br label %33
23: ; preds = %17
%24 = load i32*, i32** %5
%25 = load i32*, i32** %10
%26 = load i32*, i32** %6
%27 = load i32*, i32** %8
%28 = call i32 @BN_div(i32* %24, i32* null, i32* %25, i32* %26, i32* %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %23
br label %33
31: ; preds = %23
%32 = load i32, i32* %7
store i32 %32, i32* %9
br label %33
33: ; preds = %31, %30, %22, %16
%34 = load i32*, i32** %5
%35 = call i32 @bn_check_top(i32* %34)
%36 = load i32*, i32** %8
%37 = call i32 @BN_CTX_end(i32* %36)
%38 = load i32, i32* %9
ret i32 %38
}

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