// File: /workspace/github_c_makefile_star2_O0/an4[P]Applied-Security-Mod/modmul.c
// Function: CRT
void CRT(mpz_t c,
         mpz_t i_q,
         mpz_t i_p,
         mpz_t d_q,
         mpz_t d_p,
         mpz_t q,
         mpz_t p,
         mpz_t d,
         mpz_t N,
         mpz_t m) {

     mpz_t m_p;
     mpz_t m_q;
     mpz_init(m_p);
     mpz_init(m_q);

     sliding_window_exponentiation(m_p, c, d_p, p);
     sliding_window_exponentiation(m_q, c, d_q, q);

     /** MONTGOMERY */

     // Calculate BASE value
     // BASE = 2^64
     mpz_t BASE;
     mpz_init_set_ui(BASE, 2);
     mpz_pow_ui(BASE, BASE, W);

     // Montgomery parameters
     mpz_t Mp;
     mpz_t Mw;
     mpz_t Mp_sq;

     mpz_t one;
     mpz_init_set_ui(one, 1);

     // Compute Montgomery parameters.
     montgomery_Mp(Mp, N, BASE);
     montgomery_Mw(Mw, N, BASE);
     montgomery_Mp_sq(Mp_sq, N);

     // Transform all variables in montgomery form.
     // m_p, q, i_q, m_q, p, i_p

     montgomery_multiplication(m_p, m_p,    Mp_sq, BASE, N, Mw);
     montgomery_multiplication(q,   q,      Mp_sq, BASE, N, Mw);
     montgomery_multiplication(i_q, i_q,    Mp_sq, BASE, N, Mw);
     montgomery_multiplication(m_q, m_q,    Mp_sq, BASE, N, Mw);
     montgomery_multiplication(p,   p,      Mp_sq, BASE, N, Mw);
     montgomery_multiplication(i_p, i_p,    Mp_sq, BASE, N, Mw);

     // Do the modular multiplications
     montgomery_multiplication(m_p, m_p, q, BASE, N, Mw);
     montgomery_multiplication(m_p, m_p, i_q, BASE, N, Mw);
     montgomery_multiplication(m_q, m_q, p, BASE, N, Mw);
     montgomery_multiplication(m_q, m_q, i_p, BASE, N, Mw);

     // Convert to normal form
     // m_p, m_q
     montgomery_multiplication(m_p, m_p, one, BASE, N, Mw);
     montgomery_multiplication(m_q, m_q, one, BASE, N, Mw);

     mpz_clear(Mp);
     mpz_clear(Mw);
     mpz_clear(Mp_sq);
     mpz_clear(one);
     mpz_clear(BASE);
     /** END MONTGOMERY */

     mpz_add(m, m_p, m_q);
     mpz_mod(m, m, N);

     mpz_clear(m_p);
     mpz_clear(m_q);
}

// Assembly:
subq $0xa8, %rsp
movq 0xc8(%rsp), %rax
movq 0xc0(%rsp), %rax
movq 0xb8(%rsp), %rax
movq 0xb0(%rsp), %rax
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movq %rdx, 0x90(%rsp)
movq %rcx, 0x88(%rsp)
movq %r8, 0x80(%rsp)
movq %r9, 0x78(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x4a80
leaq 0x50(%rsp), %rdi
callq 0x4a80
leaq 0x60(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq 0xb0(%rsp), %rcx
callq 0x23a0
leaq 0x50(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq 0x78(%rsp), %rcx
callq 0x23a0
leaq 0x40(%rsp), %rdi
movl $0x2, %esi
callq 0x4d20
leaq 0x40(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movl $0x40, %edx
callq 0x5410
movq %rsp, %rdi
movl $0x1, %esi
callq 0x4d20
leaq 0x30(%rsp), %rdi
movq 0xc0(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x2760
leaq 0x20(%rsp), %rdi
movq 0xc0(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x27c0
leaq 0x10(%rsp), %rdi
movq 0xc0(%rsp), %rsi
callq 0x2890
leaq 0x60(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq 0xc0(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x2930
movq 0x78(%rsp), %rdi
movq 0x78(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq 0xc0(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x2930
movq 0x98(%rsp), %rdi
movq 0x98(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq 0xc0(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x2930
leaq 0x50(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq 0xc0(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x2930
movq 0xb0(%rsp), %rdi
movq 0xb0(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq 0xc0(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x2930
movq 0x90(%rsp), %rdi
movq 0x90(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq 0xc0(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x2930
leaq 0x60(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movq 0x78(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq 0xc0(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x2930
leaq 0x60(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movq 0x98(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq 0xc0(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x2930
leaq 0x50(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movq 0xb0(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq 0xc0(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x2930
leaq 0x50(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movq 0x90(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq 0xc0(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x2930
leaq 0x60(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movq %rsp, %rdx
leaq 0x40(%rsp), %rcx
movq 0xc0(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x2930
leaq 0x50(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movq %rsp, %rdx
leaq 0x40(%rsp), %rcx
movq 0xc0(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x2930
leaq 0x30(%rsp), %rdi
callq 0x4460
leaq 0x20(%rsp), %rdi
callq 0x4460
leaq 0x10(%rsp), %rdi
callq 0x4460
movq %rsp, %rdi
callq 0x4460
leaq 0x40(%rsp), %rdi
callq 0x4460
movq 0xc8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x40c0
movq 0xc8(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movq 0xc0(%rsp), %rdx
callq 0x4d60
leaq 0x60(%rsp), %rdi
callq 0x4460
leaq 0x50(%rsp), %rdi
callq 0x4460
addq $0xa8, %rsp
retq
nopl (%rax,%rax)