#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 */
double fabs(double);
int /*<<< orphan*/ printf(char *, ...);
void polyPrint(double a[], int n) {
  int first = 1;
  if (n == 0) {
    printf("0");
  } else {
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] == 0) {
        if (i == 0 && first == 1)
          printf("0");
        continue;
      }
      if (first != 1)
        printf(a[i] >= 0 ? " + " : " - ");
      else if (a[i] < 0)
        printf("-");
      a[i] = fabs(a[i]);
      if (a[i] != 1 || i == 0)
        printf("%g", a[i]);
      if (i > 1)
        printf("x^%d", i);
      if (i == 1)
        printf("x");
      first = 0;
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<polyPrint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1143 <polyPrint+0x33>
lea    0xee9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12be <polyPrint+0x1ae>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     12b9 <polyPrint+0x1a9>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    119d <polyPrint+0x8d>
jp     119d <polyPrint+0x8d>
cmpl   $0x0,-0x14(%rbp)
jne    1198 <polyPrint+0x88>
cmpl   $0x1,-0x10(%rbp)
jne    1198 <polyPrint+0x88>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ab <polyPrint+0x19b>
cmpl   $0x1,-0x10(%rbp)
je     11d9 <polyPrint+0xc9>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
lea    0xe68(%rip),%rdi
lea    0xe5d(%rip),%rax
ucomisd %xmm1,%xmm0
cmovae %rax,%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1202 <polyPrint+0xf2>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jbe    11fd <polyPrint+0xed>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1202 <polyPrint+0xf2>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xdfa(%rip),%xmm1
pand   %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xdc4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1256 <polyPrint+0x146>
jp     1256 <polyPrint+0x146>
cmpl   $0x0,-0x14(%rbp)
jne    1271 <polyPrint+0x161>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xdc2(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x14(%rbp)
jle    128c <polyPrint+0x17c>
mov    -0x14(%rbp),%esi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x14(%rbp)
jne    12a4 <polyPrint+0x194>
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    114c <polyPrint+0x3c>
jmp    12be <polyPrint+0x1ae>
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<polyPrint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1253 <polyPrint+0x133>
jle    125d <polyPrint+0x13d>
mov    %rdi,%r12
mov    %esi,%r13d
add    $0x1,%r13
mov    $0x1,%ebp
xorpd  %xmm1,%xmm1
lea    0xec9(%rip),%r15
jmp    1179 <polyPrint+0x59>
add    $0xfffffffffffffffe,%rbx
xor    %ebp,%ebp
lea    0xec1(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xorpd  %xmm1,%xmm1
cmp    $0x1,%r13
jbe    125d <polyPrint+0x13d>
mov    %r13,%rbx
add    $0xffffffffffffffff,%r13
lea    -0x2(%rbx),%r14d
movsd  (%r12,%r14,8),%xmm0
ucomisd %xmm1,%xmm0
jne    11c0 <polyPrint+0xa0>
jp     11c0 <polyPrint+0xa0>
cmp    $0x2,%ebx
jne    116f <polyPrint+0x4f>
cmp    $0x1,%ebp
jne    116f <polyPrint+0x4f>
mov    $0x30,%edi
call   1030 <putchar@plt>
xorpd  %xmm1,%xmm1
mov    $0x1,%ebp
jmp    116f <polyPrint+0x4f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x1,%ebp
jne    11d7 <polyPrint+0xb7>
ucomisd %xmm0,%xmm1
jbe    11f0 <polyPrint+0xd0>
mov    $0x2d,%edi
call   1030 <putchar@plt>
jmp    11f0 <polyPrint+0xd0>
ucomisd %xmm1,%xmm0
mov    %r15,%rdi
lea    0xe33(%rip),%rax
cmovae %rax,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  (%r12,%r14,8),%xmm0
andpd  0xe02(%rip),%xmm0
movlpd %xmm0,(%r12,%r14,8)
ucomisd 0xe04(%rip),%xmm0
jne    1221 <polyPrint+0x101>
jp     1221 <polyPrint+0x101>
cmp    $0x2,%ebx
je     1221 <polyPrint+0x101>
cmp    $0x3,%r13
jae    1155 <polyPrint+0x35>
jmp    1239 <polyPrint+0x119>
lea    0xdf8(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
cmp    $0x3,%r13
jae    1155 <polyPrint+0x35>
xor    %ebp,%ebp
cmp    $0x3,%ebx
jne    116b <polyPrint+0x4b>
mov    $0x78,%edi
call   1030 <putchar@plt>
jmp    116b <polyPrint+0x4b>
mov    $0x30,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@.str.1 = [4 x i8] c" + \00"
@.str.2 = [4 x i8] c" - \00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [3 x i8] c"%g\00"
@.str.5 = [5 x i8] c"x^%d\00"
@.str.6 = [2 x i8] c"x\00"
@.str.7 = [2 x i8] c"\0A\00"
define void @polyPrint(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
store i32 1, i32* %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %99
11: ; preds = %2
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
store i32 %13, i32* %6
br label %14
14: ; preds = %95, %11
%15 = load i32, i32* %6
%16 = icmp sge i32 %15, 0
br i1 %16, label %17, label %98
17: ; preds = %14
%18 = load double*, double** %3
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = fcmp oeq double %22, 0.000000e+00
br i1 %23, label %24, label %33
24: ; preds = %17
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %30, %27, %24
br label %95
33: ; preds = %17
%34 = load i32, i32* %5
%35 = icmp ne i32 %34, 1
br i1 %35, label %36, label %46
36: ; preds = %33
%37 = load double*, double** %3
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
%42 = fcmp oge double %41, 0.000000e+00
%43 = zext i1 %42 to i64
%44 = select i1 %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%45 = call i32 (i8*, ...) @printf(i8* %44)
br label %56
46: ; preds = %33
%47 = load double*, double** %3
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
%52 = fcmp olt double %51, 0.000000e+00
br i1 %52, label %53, label %55
53: ; preds = %46
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %55
55: ; preds = %53, %46
br label %56
56: ; preds = %55, %36
%57 = load double*, double** %3
%58 = load i32, i32* %6
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %57, i64 %59
%61 = load double, double* %60
%62 = call double @llvm.fabs.f64(double %61)
%63 = load double*, double** %3
%64 = load i32, i32* %6
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
store double %62, double* %66
%67 = load double*, double** %3
%68 = load i32, i32* %6
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds double, double* %67, i64 %69
%71 = load double, double* %70
%72 = fcmp une double %71, 1.000000e+00
br i1 %72, label %76, label %73
73: ; preds = %56
%74 = load i32, i32* %6
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %83
76: ; preds = %73, %56
%77 = load double*, double** %3
%78 = load i32, i32* %6
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds double, double* %77, i64 %79
%81 = load double, double* %80
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), double %81)
br label %83
83: ; preds = %76, %73
%84 = load i32, i32* %6
%85 = icmp sgt i32 %84, 1
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = load i32, i32* %6
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %87)
br label %89
89: ; preds = %86, %83
%90 = load i32, i32* %6
%91 = icmp eq i32 %90, 1
br i1 %91, label %92, label %94
92: ; preds = %89
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %94
94: ; preds = %92, %89
store i32 0, i32* %5
br label %95
95: ; preds = %94, %32
%96 = load i32, i32* %6
%97 = add nsw i32 %96, -1
store i32 %97, i32* %6
br label %14
98: ; preds = %14
br label %99
99: ; preds = %98, %9
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c" + \00"
@.str.2 = [4 x i8] c" - \00"
@.str.4 = [3 x i8] c"%g\00"
@.str.5 = [5 x i8] c"x^%d\00"
define void @polyPrint(double* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %54
6: ; preds = %4
%7 = zext i32 %1 to i64
br label %10
8: ; preds = %2
%9 = tail call i32 @putchar(i32 48)
br label %54
10: ; preds = %6, %51
%11 = phi i64 [ %7, %6 ], [ %13, %51 ]
%12 = phi i32 [ 1, %6 ], [ %52, %51 ]
%13 = add nsw i64 %11, -1
%14 = trunc i64 %13 to i32
%15 = and i64 %13, 4294967295
%16 = getelementptr inbounds double, double* %0, i64 %15
%17 = load double, double* %16
%18 = fcmp oeq double %17, 0.000000e+00
br i1 %18, label %19, label %25
19: ; preds = %10
%20 = icmp eq i32 %14, 0
%21 = icmp eq i32 %12, 1
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %23, label %51
23: ; preds = %19
%24 = tail call i32 @putchar(i32 48)
br label %51
25: ; preds = %10
%26 = icmp eq i32 %12, 1
br i1 %26, label %31, label %27
27: ; preds = %25
%28 = fcmp oge double %17, 0.000000e+00
%29 = select i1 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %29)
br label %35
31: ; preds = %25
%32 = fcmp olt double %17, 0.000000e+00
br i1 %32, label %33, label %35
33: ; preds = %31
%34 = tail call i32 @putchar(i32 45)
br label %35
35: ; preds = %31, %33, %27
%36 = load double, double* %16
%37 = tail call double @llvm.fabs.f64(double %36)
store double %37, double* %16
%38 = fcmp une double %37, 1.000000e+00
%39 = icmp eq i32 %14, 0
%40 = select i1 %38, i1 true, i1 %39
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), double %37)
br label %43
43: ; preds = %35, %41
%44 = icmp ugt i64 %11, 2
br i1 %44, label %45, label %47
45: ; preds = %43
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %14)
br label %51
47: ; preds = %43
%48 = icmp eq i32 %14, 1
br i1 %48, label %49, label %51
49: ; preds = %47
%50 = tail call i32 @putchar(i32 120)
br label %51
51: ; preds = %45, %47, %49, %19, %23
%52 = phi i32 [ 1, %23 ], [ %12, %19 ], [ 0, %49 ], [ 0, %47 ], [ 0, %45 ]
%53 = icmp ugt i64 %11, 1
br i1 %53, label %10, label %54
54: ; preds = %51, %4, %8
%55 = tail call i32 @putchar(i32 10)
ret void
}