#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_addition(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_addition>:
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     11fb <polynomial_addition+0xdb>
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jg     11a1 <polynomial_addition+0x81>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    11e8 <polynomial_addition+0xc8>
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    11c4 <polynomial_addition+0xa4>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    11d6 <polynomial_addition+0xb6>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    11ed <polynomial_addition+0xcd>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115d <polynomial_addition+0x3d>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<polynomial_addition>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
mov    %esi,%edi
mov    %ecx,%esi
call   1040 <MINN@plt>
mov    %eax,%r13d
mov    %ebp,%edi
mov    %r12d,%esi
call   1030 <MAXN@plt>
test   %eax,%eax
js     11fb <polynomial_addition+0xdb>
cmp    %r12d,%ebp
mov    %r14,%rcx
cmovg  %r15,%rcx
movslq %r13d,%rdx
lea    0x1(%rax),%esi
test   %eax,%eax
je     11d6 <polynomial_addition+0xb6>
mov    %esi,%edi
and    $0xfffffffe,%edi
xor    %eax,%eax
jmp    1195 <polynomial_addition+0x75>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  0x8(%rcx,%rax,8),%xmm0
movsd  %xmm0,0x8(%rbx,%rax,8)
add    $0x2,%rax
cmp    %rax,%rdi
je     11d8 <polynomial_addition+0xb8>
cmp    %rdx,%rax
jle    11b0 <polynomial_addition+0x90>
movsd  (%rcx,%rax,8),%xmm0
jmp    11bc <polynomial_addition+0x9c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%r15,%rax,8),%xmm0
addsd  (%r14,%rax,8),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
cmp    %rdx,%rax
jge    1180 <polynomial_addition+0x60>
movsd  0x8(%r15,%rax,8),%xmm0
addsd  0x8(%r14,%rax,8),%xmm0
jmp    1186 <polynomial_addition+0x66>
xor    %eax,%eax
test   $0x1,%sil
je     11fb <polynomial_addition+0xdb>
cmp    %rdx,%rax
jle    11ea <polynomial_addition+0xca>
movsd  (%rcx,%rax,8),%xmm0
jmp    11f6 <polynomial_addition+0xd6>
movsd  (%r15,%rax,8),%xmm0
addsd  (%r14,%rax,8),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @polynomial_addition(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 = %67, %5
%21 = load i32, i32* %11
%22 = load i32, i32* %13
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %70
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 = fadd 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 %66
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 %60
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
br label %60
60: ; preds = %54, %48
%61 = phi double [ %53, %48 ], [ %59, %54 ]
%62 = load double*, double** %10
%63 = load i32, i32* %11
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %62, i64 %64
store double %61, double* %65
br label %66
66: ; preds = %60, %28
br label %67
67: ; preds = %66
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 1
store i32 %69, i32* %11
br label %20
70: ; preds = %20
ret void
}

LLVM IR (-O2):
define void @polynomial_addition(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 %69, label %9
9: ; preds = %5
%10 = icmp sgt i32 %1, %3
%11 = select i1 %10, double* %0, double* %2
%12 = sext i32 %6 to i64
%13 = add nuw i32 %7, 1
%14 = zext i32 %13 to i64
%15 = and i64 %14, 1
%16 = icmp eq i32 %7, 0
br i1 %16, label %52, label %17
17: ; preds = %9
%18 = and i64 %14, 4294967294
br label %19
19: ; preds = %46, %17
%20 = phi i64 [ 0, %17 ], [ %49, %46 ]
%21 = phi i64 [ 0, %17 ], [ %50, %46 ]
%22 = icmp sgt i64 %20, %12
br i1 %22, label %29, label %23
23: ; preds = %19
%24 = getelementptr inbounds double, double* %0, i64 %20
%25 = load double, double* %24
%26 = getelementptr inbounds double, double* %2, i64 %20
%27 = load double, double* %26
%28 = fadd double %25, %27
br label %32
29: ; preds = %19
%30 = getelementptr inbounds double, double* %11, i64 %20
%31 = load double, double* %30
br label %32
32: ; preds = %23, %29
%33 = phi double [ %31, %29 ], [ %28, %23 ]
%34 = getelementptr inbounds double, double* %4, i64 %20
store double %33, double* %34
%35 = or i64 %20, 1
%36 = icmp slt i64 %20, %12
br i1 %36, label %37, label %43
37: ; preds = %32
%38 = getelementptr inbounds double, double* %0, i64 %35
%39 = load double, double* %38
%40 = getelementptr inbounds double, double* %2, i64 %35
%41 = load double, double* %40
%42 = fadd double %39, %41
br label %46
43: ; preds = %32
%44 = getelementptr inbounds double, double* %11, i64 %35
%45 = load double, double* %44
br label %46
46: ; preds = %43, %37
%47 = phi double [ %45, %43 ], [ %42, %37 ]
%48 = getelementptr inbounds double, double* %4, i64 %35
store double %47, double* %48
%49 = add nuw nsw i64 %20, 2
%50 = add i64 %21, 2
%51 = icmp eq i64 %50, %18
br i1 %51, label %52, label %19
52: ; preds = %46, %9
%53 = phi i64 [ 0, %9 ], [ %49, %46 ]
%54 = icmp eq i64 %15, 0
br i1 %54, label %69, label %55
55: ; preds = %52
%56 = icmp sgt i64 %53, %12
br i1 %56, label %63, label %57
57: ; preds = %55
%58 = getelementptr inbounds double, double* %0, i64 %53
%59 = load double, double* %58
%60 = getelementptr inbounds double, double* %2, i64 %53
%61 = load double, double* %60
%62 = fadd double %59, %61
br label %66
63: ; preds = %55
%64 = getelementptr inbounds double, double* %11, i64 %53
%65 = load double, double* %64
br label %66
66: ; preds = %63, %57
%67 = phi double [ %65, %63 ], [ %62, %57 ]
%68 = getelementptr inbounds double, double* %4, i64 %53
store double %67, double* %68
br label %69
69: ; preds = %66, %52, %5
ret void
}