#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_FLG_CONSTTIME;
int BN_div_internal(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                    int /*<<< orphan*/ const *, int /*<<< orphan*/ const *,
                    int /*<<< orphan*/ *, int);
scalar_t__ BN_get_flags(int /*<<< orphan*/ const *, int /*<<< orphan*/);
int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
           BN_CTX *ctx) {
  int ct = ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) ||
            (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0));
  return BN_div_internal(dv, rm, num, divisor, ctx, ct);
}


x86 assembly (clang, -O0):
<BN_div>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
call   1040 <BN_get_flags@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x2d(%rbp)
jne    117c <BN_div+0x5c>
mov    -0x20(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
call   1040 <BN_get_flags@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
call   1030 <BN_div_internal@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BN_div>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r13
mov    0x2ea7(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %rdx,%rdi
call   1040 <BN_get_flags@plt>
mov    $0x1,%r9d
test   %rax,%rax
jne    116c <BN_div+0x4c>
mov    0x0(%rbp),%esi
mov    %r15,%rdi
call   1040 <BN_get_flags@plt>
xor    %r9d,%r9d
test   %rax,%rax
setne  %r9b
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <BN_div_internal@plt>

LLVM IR (-O0):
@BN_FLG_CONSTTIME = global i32 0
define i32 @BN_div(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
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
%12 = load i32*, i32** %8
%13 = load i32, i32* @BN_FLG_CONSTTIME
%14 = call i64 @BN_get_flags(i32* %12, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %5
%17 = load i32*, i32** %9
%18 = load i32, i32* @BN_FLG_CONSTTIME
%19 = call i64 @BN_get_flags(i32* %17, i32 %18)
%20 = icmp ne i64 %19, 0
br label %21
21: ; preds = %16, %5
%22 = phi i1 [ true, %5 ], [ %20, %16 ]
%23 = zext i1 %22 to i32
store i32 %23, i32* %11
%24 = load i32*, i32** %6
%25 = load i32*, i32** %7
%26 = load i32*, i32** %8
%27 = load i32*, i32** %9
%28 = load i32*, i32** %10
%29 = load i32, i32* %11
%30 = call i32 @BN_div_internal(i32* %24, i32* %25, i32* %26, i32* %27, i32* %28, i32 %29)
ret i32 %30
}

LLVM IR (-O2):
@BN_FLG_CONSTTIME = global i32 0
define i32 @BN_div(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = load i32, i32* @BN_FLG_CONSTTIME
%7 = tail call i64 @BN_get_flags(i32* %2, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %5
%10 = load i32, i32* @BN_FLG_CONSTTIME
%11 = tail call i64 @BN_get_flags(i32* %3, i32 %10)
%12 = icmp ne i64 %11, 0
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %9, %5
%15 = phi i32 [ 1, %5 ], [ %13, %9 ]
%16 = tail call i32 @BN_div_internal(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4, i32 %15)
ret i32 %16
}