#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*/ const BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ const *);
int /*<<< orphan*/ BN_mod_add(int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod_mul(int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *const,
                              int /*<<< orphan*/ const *const,
                              int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ const *BN_new();
int poly_mul(BIGNUM **z, BIGNUM *const *x, BIGNUM *const *y, const BIGNUM *a,
             const BIGNUM *m, BN_CTX *ctx) {
  BIGNUM *t1 = BN_new();
  BIGNUM *t2 = BN_new();
  BIGNUM *t3 = BN_new();
  BN_mod_mul(t1, x[0], y[0], m, ctx);
  BN_mod_mul(t2, x[1], y[1], m, ctx);
  BN_mod_mul(t3, t2, a, m, ctx);
  BN_mod_add(z[0], t1, t3, m, ctx);
  BN_mod_mul(t1, x[0], y[1], m, ctx);
  BN_mod_mul(t2, x[1], y[0], m, ctx);
  BN_mod_add(z[1], t1, t2, m, ctx);
  BN_free(t1);
  BN_free(t2);
  BN_free(t3);
  return 0;
}


x86 assembly (clang, -O0):
<poly_mul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    $0x0,%al
call   1030 <BN_new@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <BN_new@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1030 <BN_new@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1050 <BN_mod_mul@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1050 <BN_mod_mul@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1050 <BN_mod_mul@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1060 <BN_mod_add@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1050 <BN_mod_mul@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1050 <BN_mod_mul@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1060 <BN_mod_add@plt>
mov    -0x38(%rbp),%rdi
call   1040 <BN_free@plt>
mov    -0x40(%rbp),%rdi
call   1040 <BN_free@plt>
mov    -0x48(%rbp),%rdi
call   1040 <BN_free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poly_mul>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r14
mov    %r8,%rbx
mov    %rcx,0x20(%rsp)
mov    %rdx,%rbp
mov    %rsi,%r13
mov    %rdi,0x10(%rsp)
xor    %eax,%eax
call   1030 <BN_new@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1030 <BN_new@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1030 <BN_new@plt>
mov    %rax,0x8(%rsp)
mov    0x0(%r13),%rsi
mov    %rbp,0x18(%rsp)
mov    0x0(%rbp),%rdx
mov    %r15,%rdi
mov    %rbx,%rcx
mov    %r14,%r8
call   1050 <BN_mod_mul@plt>
mov    0x8(%r13),%rsi
mov    0x8(%rbp),%rdx
mov    %r12,%rdi
mov    %rbx,%rcx
mov    %r14,%r8
call   1050 <BN_mod_mul@plt>
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
mov    0x20(%rsp),%rdx
mov    %rbx,%rcx
mov    %r14,%r8
call   1050 <BN_mod_mul@plt>
mov    0x10(%rsp),%rax
mov    (%rax),%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %r14,%r8
call   1060 <BN_mod_add@plt>
mov    0x0(%r13),%rsi
mov    0x18(%rsp),%rbp
mov    0x8(%rbp),%rdx
mov    %r15,%rdi
mov    %rbx,%rcx
mov    %r14,%r8
call   1050 <BN_mod_mul@plt>
mov    0x8(%r13),%rsi
mov    0x0(%rbp),%rdx
mov    %r12,%rdi
mov    %rbx,%rcx
mov    %r14,%r8
call   1050 <BN_mod_mul@plt>
mov    0x10(%rsp),%rax
mov    0x8(%rax),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %r14,%r8
call   1060 <BN_mod_add@plt>
mov    %r15,%rdi
call   1040 <BN_free@plt>
mov    %r12,%rdi
call   1040 <BN_free@plt>
mov    0x8(%rsp),%rdi
call   1040 <BN_free@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @poly_mul(i32** %0, i32** %1, i32** %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32**
%8 = alloca i32**
%9 = alloca i32**
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
store i32** %0, i32*** %7
store i32** %1, i32*** %8
store i32** %2, i32*** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32* %5, i32** %12
%16 = call i32* (...) @BN_new()
store i32* %16, i32** %13
%17 = call i32* (...) @BN_new()
store i32* %17, i32** %14
%18 = call i32* (...) @BN_new()
store i32* %18, i32** %15
%19 = load i32*, i32** %13
%20 = load i32**, i32*** %8
%21 = getelementptr inbounds i32*, i32** %20, i64 0
%22 = load i32*, i32** %21
%23 = load i32**, i32*** %9
%24 = getelementptr inbounds i32*, i32** %23, i64 0
%25 = load i32*, i32** %24
%26 = load i32*, i32** %11
%27 = load i32*, i32** %12
%28 = call i32 @BN_mod_mul(i32* %19, i32* %22, i32* %25, i32* %26, i32* %27)
%29 = load i32*, i32** %14
%30 = load i32**, i32*** %8
%31 = getelementptr inbounds i32*, i32** %30, i64 1
%32 = load i32*, i32** %31
%33 = load i32**, i32*** %9
%34 = getelementptr inbounds i32*, i32** %33, i64 1
%35 = load i32*, i32** %34
%36 = load i32*, i32** %11
%37 = load i32*, i32** %12
%38 = call i32 @BN_mod_mul(i32* %29, i32* %32, i32* %35, i32* %36, i32* %37)
%39 = load i32*, i32** %15
%40 = load i32*, i32** %14
%41 = load i32*, i32** %10
%42 = load i32*, i32** %11
%43 = load i32*, i32** %12
%44 = call i32 @BN_mod_mul(i32* %39, i32* %40, i32* %41, i32* %42, i32* %43)
%45 = load i32**, i32*** %7
%46 = getelementptr inbounds i32*, i32** %45, i64 0
%47 = load i32*, i32** %46
%48 = load i32*, i32** %13
%49 = load i32*, i32** %15
%50 = load i32*, i32** %11
%51 = load i32*, i32** %12
%52 = call i32 @BN_mod_add(i32* %47, i32* %48, i32* %49, i32* %50, i32* %51)
%53 = load i32*, i32** %13
%54 = load i32**, i32*** %8
%55 = getelementptr inbounds i32*, i32** %54, i64 0
%56 = load i32*, i32** %55
%57 = load i32**, i32*** %9
%58 = getelementptr inbounds i32*, i32** %57, i64 1
%59 = load i32*, i32** %58
%60 = load i32*, i32** %11
%61 = load i32*, i32** %12
%62 = call i32 @BN_mod_mul(i32* %53, i32* %56, i32* %59, i32* %60, i32* %61)
%63 = load i32*, i32** %14
%64 = load i32**, i32*** %8
%65 = getelementptr inbounds i32*, i32** %64, i64 1
%66 = load i32*, i32** %65
%67 = load i32**, i32*** %9
%68 = getelementptr inbounds i32*, i32** %67, i64 0
%69 = load i32*, i32** %68
%70 = load i32*, i32** %11
%71 = load i32*, i32** %12
%72 = call i32 @BN_mod_mul(i32* %63, i32* %66, i32* %69, i32* %70, i32* %71)
%73 = load i32**, i32*** %7
%74 = getelementptr inbounds i32*, i32** %73, i64 1
%75 = load i32*, i32** %74
%76 = load i32*, i32** %13
%77 = load i32*, i32** %14
%78 = load i32*, i32** %11
%79 = load i32*, i32** %12
%80 = call i32 @BN_mod_add(i32* %75, i32* %76, i32* %77, i32* %78, i32* %79)
%81 = load i32*, i32** %13
%82 = call i32 @BN_free(i32* %81)
%83 = load i32*, i32** %14
%84 = call i32 @BN_free(i32* %83)
%85 = load i32*, i32** %15
%86 = call i32 @BN_free(i32* %85)
ret i32 0
}

LLVM IR (-O2):
define i32 @poly_mul(i32** nocapture %0, i32** nocapture %1, i32** nocapture %2, i32* %3, i32* %4, i32* %5) {
%7 = tail call i32* (...) @BN_new()
%8 = tail call i32* (...) @BN_new()
%9 = tail call i32* (...) @BN_new()
%10 = load i32*, i32** %1
%11 = load i32*, i32** %2
%12 = tail call i32 @BN_mod_mul(i32* %7, i32* %10, i32* %11, i32* %4, i32* %5)
%13 = getelementptr inbounds i32*, i32** %1, i64 1
%14 = load i32*, i32** %13
%15 = getelementptr inbounds i32*, i32** %2, i64 1
%16 = load i32*, i32** %15
%17 = tail call i32 @BN_mod_mul(i32* %8, i32* %14, i32* %16, i32* %4, i32* %5)
%18 = tail call i32 @BN_mod_mul(i32* %9, i32* %8, i32* %3, i32* %4, i32* %5)
%19 = load i32*, i32** %0
%20 = tail call i32 @BN_mod_add(i32* %19, i32* %7, i32* %9, i32* %4, i32* %5)
%21 = load i32*, i32** %1
%22 = load i32*, i32** %15
%23 = tail call i32 @BN_mod_mul(i32* %7, i32* %21, i32* %22, i32* %4, i32* %5)
%24 = load i32*, i32** %13
%25 = load i32*, i32** %2
%26 = tail call i32 @BN_mod_mul(i32* %8, i32* %24, i32* %25, i32* %4, i32* %5)
%27 = getelementptr inbounds i32*, i32** %0, i64 1
%28 = load i32*, i32** %27
%29 = tail call i32 @BN_mod_add(i32* %28, i32* %7, i32* %8, i32* %4, i32* %5)
%30 = tail call i32 @BN_free(i32* %7)
%31 = tail call i32 @BN_free(i32* %8)
%32 = tail call i32 @BN_free(i32* %9)
ret i32 0
}