#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 */

/* Variables and functions */
unsigned char *cvector(int, int);
int /*<<< orphan*/ free_cvector(unsigned char *, int, int);
int /*<<< orphan*/ nrerror(char *);
void mpdiv(unsigned char q[], unsigned char r[], unsigned char u[],
           unsigned char v[], int n, int m) {
  void mpinv(unsigned char u[], unsigned char v[], int n, int m);
  void mpmov(unsigned char u[], unsigned char v[], int n);
  void mpmul(unsigned char w[], unsigned char u[], unsigned char v[], int n,
             int m);
  void mpsad(unsigned char w[], unsigned char u[], int n, int iv);
  void mpsub(int *is, unsigned char w[], unsigned char u[], unsigned char v[],
             int n);
  int is;
  unsigned char *rr, *s;
  rr = cvector(1, (n + 6) << 1);
  s = cvector(1, (n + 6) << 1);
  mpinv(s, v, n + 6, m);
  mpmul(rr, s, u, n + 6, n);
  mpsad(s, rr, n + 6 - 1, 1);
  mpmov(q, &s[2], n - m + 1);
  mpmul(rr, q, v, n - m + 1, m);
  mpsub(&is, &rr[1], u, &rr[1], n);
  if (is)
    nrerror("MACC too small in mpdiv");
  mpmov(r, &rr[n - m + 1], m);
  free_cvector(s, 1, (n + 6) << 1);
  free_cvector(rr, 1, (n + 6) << 1);
}


x86 assembly (clang, -O0):
<mpdiv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x24(%rbp),%esi
add    $0x6,%esi
shl    $0x1,%esi
mov    $0x1,%edi
call   1060 <cvector@plt>
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%esi
add    $0x6,%esi
shl    $0x1,%esi
mov    $0x1,%edi
call   1060 <cvector@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
add    $0x6,%edx
mov    -0x28(%rbp),%ecx
call   1070 <mpinv@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
add    $0x6,%ecx
mov    -0x24(%rbp),%r8d
call   1030 <mpmul@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x24(%rbp),%edx
add    $0x6,%edx
sub    $0x1,%edx
mov    $0x1,%ecx
call   1050 <mpsad@plt>
mov    -0x8(%rbp),%rdi
mov    -0x40(%rbp),%rsi
add    $0x2,%rsi
mov    -0x24(%rbp),%edx
sub    -0x28(%rbp),%edx
add    $0x1,%edx
call   1090 <mpmov@plt>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
sub    -0x28(%rbp),%ecx
add    $0x1,%ecx
mov    -0x28(%rbp),%r8d
call   1030 <mpmul@plt>
mov    -0x38(%rbp),%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
mov    -0x24(%rbp),%r8d
lea    -0x2c(%rbp),%rdi
call   10a0 <mpsub@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1289 <mpdiv+0x109>
lea    0xd7c(%rip),%rdi
call   1040 <nrerror@plt>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x24(%rbp),%eax
sub    -0x28(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%rsi
mov    -0x28(%rbp),%edx
call   1090 <mpmov@plt>
mov    -0x40(%rbp),%rdi
mov    -0x24(%rbp),%edx
add    $0x6,%edx
shl    $0x1,%edx
mov    $0x1,%esi
call   1080 <free_cvector@plt>
mov    -0x38(%rbp),%rdi
mov    -0x24(%rbp),%edx
add    $0x6,%edx
shl    $0x1,%edx
mov    $0x1,%esi
call   1080 <free_cvector@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpdiv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r13d
mov    %r8d,%ebp
mov    %rcx,%r14
mov    %rcx,0x10(%rsp)
mov    %rdx,0x8(%rsp)
mov    %rsi,0x20(%rsp)
mov    %rdi,0x18(%rsp)
lea    0x6(%rbp),%r15d
lea    0xc(%rbp,%rbp,1),%ebx
mov    $0x1,%edi
mov    %ebx,%esi
call   1060 <cvector@plt>
mov    %rax,%r12
mov    $0x1,%edi
mov    %ebx,(%rsp)
mov    %ebx,%esi
call   1060 <cvector@plt>
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rax,%r14
mov    %r15d,%edx
mov    %r13d,%ecx
call   1070 <mpinv@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    0x8(%rsp),%rdx
mov    %r15d,%ecx
mov    %ebp,%r8d
call   1030 <mpmul@plt>
lea    0x5(%rbp),%edx
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x1,%ecx
call   1050 <mpsad@plt>
mov    %r14,%rsi
add    $0x2,%rsi
mov    %ebp,%r15d
sub    %r13d,%r15d
add    $0x1,%r15d
mov    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15d,%edx
call   1090 <mpmov@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    0x10(%rsp),%rdx
mov    %r15d,%ecx
mov    %r13d,%ebx
mov    %r13d,%r8d
call   1030 <mpmul@plt>
lea    0x1(%r12),%rcx
lea    0x4(%rsp),%rdi
mov    %rcx,%rsi
mov    0x8(%rsp),%rdx
mov    %ebp,%r8d
call   10a0 <mpsub@plt>
cmpl   $0x0,0x4(%rsp)
je     1275 <mpdiv+0xf5>
lea    0xd90(%rip),%rdi
call   1040 <nrerror@plt>
movslq %r15d,%rax
mov    %r12,%rsi
add    %rax,%rsi
mov    0x20(%rsp),%rdi
mov    %ebx,%edx
call   1090 <mpmov@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    (%rsp),%ebx
mov    %ebx,%edx
call   1080 <free_cvector@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
call   1080 <free_cvector@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"MACC too small in mpdiv\00"
define void @mpdiv(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%16 = load i32, i32* %11
%17 = add nsw i32 %16, 6
%18 = shl i32 %17, 1
%19 = call i8* @cvector(i32 1, i32 %18)
store i8* %19, i8** %14
%20 = load i32, i32* %11
%21 = add nsw i32 %20, 6
%22 = shl i32 %21, 1
%23 = call i8* @cvector(i32 1, i32 %22)
store i8* %23, i8** %15
%24 = load i8*, i8** %15
%25 = load i8*, i8** %10
%26 = load i32, i32* %11
%27 = add nsw i32 %26, 6
%28 = load i32, i32* %12
%29 = load i8*, i8** %14
%30 = load i8*, i8** %15
%31 = load i8*, i8** %9
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 6
%34 = load i32, i32* %11
%35 = load i8*, i8** %15
%36 = load i8*, i8** %14
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 6
%39 = sub nsw i32 %38, 1
%40 = load i8*, i8** %7
%41 = load i8*, i8** %15
%42 = getelementptr inbounds i8, i8* %41, i64 2
%43 = load i32, i32* %11
%44 = load i32, i32* %12
%45 = sub nsw i32 %43, %44
%46 = add nsw i32 %45, 1
%47 = load i8*, i8** %14
%48 = load i8*, i8** %7
%49 = load i8*, i8** %10
%50 = load i32, i32* %11
%51 = load i32, i32* %12
%52 = sub nsw i32 %50, %51
%53 = add nsw i32 %52, 1
%54 = load i32, i32* %12
%55 = load i8*, i8** %14
%56 = getelementptr inbounds i8, i8* %55, i64 1
%57 = load i8*, i8** %9
%58 = load i8*, i8** %14
%59 = getelementptr inbounds i8, i8* %58, i64 1
%60 = load i32, i32* %11
%61 = load i32, i32* %13
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %6
%64 = call i32 @nrerror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %65
65: ; preds = %63, %6
%66 = load i8*, i8** %8
%67 = load i8*, i8** %14
%68 = load i32, i32* %11
%69 = load i32, i32* %12
%70 = sub nsw i32 %68, %69
%71 = add nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %67, i64 %72
%74 = load i32, i32* %12
%75 = load i8*, i8** %15
%76 = load i32, i32* %11
%77 = add nsw i32 %76, 6
%78 = shl i32 %77, 1
%79 = call i32 @free_cvector(i8* %75, i32 1, i32 %78)
%80 = load i8*, i8** %14
%81 = load i32, i32* %11
%82 = add nsw i32 %81, 6
%83 = shl i32 %82, 1
%84 = call i32 @free_cvector(i8* %80, i32 1, i32 %83)
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"MACC too small in mpdiv\00"
define void @mpdiv(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = bitcast i32* %7 to i8*
%9 = add nsw i32 %4, 6
%10 = shl i32 %9, 1
%11 = tail call i8* @cvector(i32 1, i32 %10)
%12 = tail call i8* @cvector(i32 1, i32 %10)
tail call void @mpinv(i8* %12, i8* %3, i32 %9, i32 %5)
tail call void @mpmul(i8* %11, i8* %12, i8* %2, i32 %9, i32 %4)
%13 = add nsw i32 %4, 5
tail call void @mpsad(i8* %12, i8* %11, i32 %13, i32 1)
%14 = getelementptr inbounds i8, i8* %12, i64 2
%15 = sub nsw i32 %4, %5
%16 = add nsw i32 %15, 1
tail call void @mpmov(i8* %0, i8* %14, i32 %16)
tail call void @mpmul(i8* %11, i8* %0, i8* %3, i32 %16, i32 %5)
%17 = getelementptr inbounds i8, i8* %11, i64 1
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %6
%21 = call i32 @nrerror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %6
%23 = sext i32 %16 to i64
%24 = getelementptr inbounds i8, i8* %11, i64 %23
%25 = call i32 @free_cvector(i8* %12, i32 1, i32 %10)
%26 = call i32 @free_cvector(i8* %11, i32 1, i32 %10)
ret void
}