#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_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_CTX_new();
int BN_mod_mul(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
               int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_new();
int /*<<< orphan*/ printf(char *, int);
BIGNUM *mulm(BIGNUM *x, BIGNUM *y, BIGNUM *mod_param) {
  BN_CTX *ctx = BN_CTX_new();
  BIGNUM *multMod = BN_new();
  int ret = BN_mod_mul(multMod, x, y, mod_param, ctx);
  if (ret != 1) {
    printf("mulm: BN_mod_mul failed: %d", ret);
  }
  BN_CTX_free(ctx);
  return multMod;
}


x86 assembly (clang, -O0):
<mulm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1060 <BN_CTX_new@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <BN_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1070 <BN_mod_mul@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
je     11af <mulm+0x5f>
mov    -0x2c(%rbp),%esi
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <BN_CTX_free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mulm>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
xor    %eax,%eax
call   1060 <BN_CTX_new@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <BN_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1070 <BN_mod_mul@plt>
cmp    $0x1,%eax
je     119d <mulm+0x4d>
lea    0xe6a(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1050 <BN_CTX_free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"mulm: BN_mod_mul failed: %d\00"
define i32* @mulm(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%10 = call i32* (...) @BN_CTX_new()
store i32* %10, i32** %7
%11 = call i32* (...) @BN_new()
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = load i32*, i32** %4
%14 = load i32*, i32** %5
%15 = load i32*, i32** %6
%16 = load i32*, i32** %7
%17 = call i32 @BN_mod_mul(i32* %12, i32* %13, i32* %14, i32* %15, i32* %16)
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %3
%21 = load i32, i32* %9
%22 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %20, %3
%24 = load i32*, i32** %7
%25 = call i32 @BN_CTX_free(i32* %24)
%26 = load i32*, i32** %8
ret i32* %26
}

LLVM IR (-O2):
@.str = [28 x i8] c"mulm: BN_mod_mul failed: %d\00"
define i32* @mulm(i32* %0, i32* %1, i32* %2) {
%4 = tail call i32* (...) @BN_CTX_new()
%5 = tail call i32* (...) @BN_new()
%6 = tail call i32 @BN_mod_mul(i32* %5, i32* %0, i32* %1, i32* %2, i32* %4)
%7 = icmp eq i32 %6, 1
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %10
10: ; preds = %8, %3
%11 = tail call i32 @BN_CTX_free(i32* %4)
ret i32* %5
}