#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_mod_mul(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_sqr(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *);
void sqrN(BIGNUM *r, BIGNUM *bn, BIGNUM *modulus, int a, BN_CTX *bnctx) {
  int i;
  BN_sqr(r, bn, bnctx);
  for (i = 0; i < a; i++)
    BN_mod_mul(r, r, r, modulus, bnctx);
}


x86 assembly (clang, -O0):
<sqrN>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <BN_sqr@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1186 <sqrN+0x66>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1040 <BN_mod_mul@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1153 <sqrN+0x33>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqrN>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8,%r15
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %r8,%rdx
call   1030 <BN_sqr@plt>
test   %ebp,%ebp
jle    1159 <sqrN+0x39>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1040 <BN_mod_mul@plt>
add    $0xffffffff,%ebp
jne    1140 <sqrN+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @sqrN(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** %6
%13 = load i32*, i32** %7
%14 = load i32*, i32** %10
%15 = call i32 @BN_sqr(i32* %12, i32* %13, i32* %14)
store i32 0, i32* %11
br label %16
16: ; preds = %27, %5
%17 = load i32, i32* %11
%18 = load i32, i32* %9
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = load i32*, i32** %6
%22 = load i32*, i32** %6
%23 = load i32*, i32** %6
%24 = load i32*, i32** %8
%25 = load i32*, i32** %10
%26 = call i32 @BN_mod_mul(i32* %21, i32* %22, i32* %23, i32* %24, i32* %25)
br label %27
27: ; preds = %20
%28 = load i32, i32* %11
%29 = add nsw i32 %28, 1
store i32 %29, i32* %11
br label %16
30: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @sqrN(i32* %0, i32* %1, i32* %2, i32 %3, i32* %4) {
%6 = tail call i32 @BN_sqr(i32* %0, i32* %1, i32* %4)
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %13
8: ; preds = %5, %8
%9 = phi i32 [ %11, %8 ], [ 0, %5 ]
%10 = tail call i32 @BN_mod_mul(i32* %0, i32* %0, i32* %0, i32* %2, i32* %4)
%11 = add nuw nsw i32 %9, 1
%12 = icmp eq i32 %11, %3
br i1 %12, label %13, label %8
13: ; preds = %8, %5
ret void
}