#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 */
int MAXN(int, int);
int MINN(int, int);
void polynomial_subtraction(double *a, int adeg, double *b, int bdeg,
                            double *c) {
  int i, mindeg = MINN(adeg, bdeg), maxdeg = MAXN(adeg, bdeg);
  for (i = 0; i <= maxdeg; i++) {
    if (i <= mindeg)
      c[i] = a[i] - b[i];
    else
      c[i] = (adeg > bdeg) ? a[i] : -b[i];
  }
}


x86 assembly (clang, -O0):
<polynomial_subtraction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <MINN@plt>
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <MAXN@plt>
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jg     1212 <polynomial_subtraction+0xf2>
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jg     11a1 <polynomial_subtraction+0x81>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    11ff <polynomial_subtraction+0xdf>
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    11c4 <polynomial_subtraction+0xa4>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    11ed <polynomial_subtraction+0xcd>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1204 <polynomial_subtraction+0xe4>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115d <polynomial_subtraction+0x3d>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<polynomial_subtraction>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %ecx,%r14d
mov    %rdx,%r12
mov    %esi,%r15d
mov    %rdi,%rbp
mov    %esi,%edi
mov    %ecx,%esi
call   1040 <MINN@plt>
mov    %eax,%r13d
mov    %r15d,%edi
mov    %r14d,%esi
call   1030 <MAXN@plt>
test   %eax,%eax
js     11ac <polynomial_subtraction+0x8c>
movslq %r13d,%rcx
add    $0x1,%eax
xor    %edx,%edx
movapd 0xe9b(%rip),%xmm0
jmp    118a <polynomial_subtraction+0x6a>
nopw   0x0(%rax,%rax,1)
movsd  0x0(%rbp,%rdx,8),%xmm1
subsd  (%r12,%rdx,8),%xmm1
movsd  %xmm1,(%rbx,%rdx,8)
add    $0x1,%rdx
cmp    %rdx,%rax
je     11ac <polynomial_subtraction+0x8c>
cmp    %rcx,%rdx
jle    1170 <polynomial_subtraction+0x50>
cmp    %r14d,%r15d
jle    11a0 <polynomial_subtraction+0x80>
movsd  0x0(%rbp,%rdx,8),%xmm1
jmp    117c <polynomial_subtraction+0x5c>
nopl   0x0(%rax)
movsd  (%r12,%rdx,8),%xmm1
xorpd  %xmm0,%xmm1
jmp    117c <polynomial_subtraction+0x5c>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @polynomial_subtraction(double* %0, i32 %1, double* %2, i32 %3, double* %4) {
%6 = alloca double*
%7 = alloca i32
%8 = alloca double*
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store double* %0, double** %6
store i32 %1, i32* %7
store double* %2, double** %8
store i32 %3, i32* %9
store double* %4, double** %10
%14 = load i32, i32* %7
%15 = load i32, i32* %9
%16 = call i32 @MINN(i32 %14, i32 %15)
store i32 %16, i32* %12
%17 = load i32, i32* %7
%18 = load i32, i32* %9
%19 = call i32 @MAXN(i32 %17, i32 %18)
store i32 %19, i32* %13
store i32 0, i32* %11
br label %20
20: ; preds = %68, %5
%21 = load i32, i32* %11
%22 = load i32, i32* %13
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %71
24: ; preds = %20
%25 = load i32, i32* %11
%26 = load i32, i32* %12
%27 = icmp sle i32 %25, %26
br i1 %27, label %28, label %44
28: ; preds = %24
%29 = load double*, double** %6
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = load double*, double** %8
%35 = load i32, i32* %11
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
%38 = load double, double* %37
%39 = fsub double %33, %38
%40 = load double*, double** %10
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
store double %39, double* %43
br label %67
44: ; preds = %24
%45 = load i32, i32* %7
%46 = load i32, i32* %9
%47 = icmp sgt i32 %45, %46
br i1 %47, label %48, label %54
48: ; preds = %44
%49 = load double*, double** %6
%50 = load i32, i32* %11
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %49, i64 %51
%53 = load double, double* %52
br label %61
54: ; preds = %44
%55 = load double*, double** %8
%56 = load i32, i32* %11
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = load double, double* %58
%60 = fneg double %59
br label %61
61: ; preds = %54, %48
%62 = phi double [ %53, %48 ], [ %60, %54 ]
%63 = load double*, double** %10
%64 = load i32, i32* %11
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
store double %62, double* %66
br label %67
67: ; preds = %61, %28
br label %68
68: ; preds = %67
%69 = load i32, i32* %11
%70 = add nsw i32 %69, 1
store i32 %70, i32* %11
br label %20
71: ; preds = %20
ret void
}

LLVM IR (-O2):
define void @polynomial_subtraction(double* nocapture %0, i32 %1, double* nocapture %2, i32 %3, double* nocapture writeonly %4) {
%6 = tail call i32 @MINN(i32 %1, i32 %3)
%7 = tail call i32 @MAXN(i32 %1, i32 %3)
%8 = icmp slt i32 %7, 0
br i1 %8, label %36, label %9
9: ; preds = %5
%10 = icmp sgt i32 %1, %3
%11 = sext i32 %6 to i64
%12 = add nuw i32 %7, 1
%13 = zext i32 %12 to i64
br label %14
14: ; preds = %9, %31
%15 = phi i64 [ 0, %9 ], [ %34, %31 ]
%16 = icmp sgt i64 %15, %11
br i1 %16, label %23, label %17
17: ; preds = %14
%18 = getelementptr inbounds double, double* %0, i64 %15
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %2, i64 %15
%21 = load double, double* %20
%22 = fsub double %19, %21
br label %31
23: ; preds = %14
br i1 %10, label %24, label %27
24: ; preds = %23
%25 = getelementptr inbounds double, double* %0, i64 %15
%26 = load double, double* %25
br label %31
27: ; preds = %23
%28 = getelementptr inbounds double, double* %2, i64 %15
%29 = load double, double* %28
%30 = fneg double %29
br label %31
31: ; preds = %24, %27, %17
%32 = phi double [ %22, %17 ], [ %26, %24 ], [ %30, %27 ]
%33 = getelementptr inbounds double, double* %4, i64 %15
store double %32, double* %33
%34 = add nuw nsw i64 %15, 1
%35 = icmp eq i64 %34, %13
br i1 %35, label %36, label %14
36: ; preds = %31, %5
ret void
}