#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 */
typedef int /*<<< orphan*/ mpz_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ mpz_cmp_si(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_cmp_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_out_str(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int mpz_sgn(int /*<<< orphan*/);
void mug_pretty_print_polynomial(FILE *stream, mpz_t *p, int deg_p) {
  int coef_sign, i;
  for (i = deg_p; 0 <= i; --i) {
    coef_sign = mpz_sgn(p[i]);
    if (coef_sign > 0 && i != deg_p) {
      fprintf(stream, "+");
    }
    if (coef_sign) {
      if (!mpz_cmp_ui(p[i], 1)) {
        if (i != deg_p)
          fprintf(stream, "+");
      } else {
        if (!mpz_cmp_si(p[i], -1) && i > 0) {
          fprintf(stream, "-");
        } else {
          mpz_out_str(stream, 10, p[i]);
          if (i)
            fprintf(stream, "*");
        }
      }
      switch (i) {
      case 0:
        break;
      case 1:
        fprintf(stream, "x");
        break;
      default:
        fprintf(stream, "x^%d", i);
        break;
      }
    }
  }
  return;
}


x86 assembly (clang, -O0):
<mug_pretty_print_polynomial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmp    -0x1c(%rbp),%eax
jg     12e5 <mug_pretty_print_polynomial+0x195>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1070 <mpz_sgn@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11af <mug_pretty_print_polynomial+0x5f>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11af <mug_pretty_print_polynomial+0x5f>
mov    -0x8(%rbp),%rdi
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cmpl   $0x0,-0x18(%rbp)
je     12d2 <mug_pretty_print_polynomial+0x182>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    $0x1,%esi
call   1050 <mpz_cmp_ui@plt>
cmp    $0x0,%eax
jne    11fa <mug_pretty_print_polynomial+0xaa>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11f5 <mug_pretty_print_polynomial+0xa5>
mov    -0x8(%rbp),%rdi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1278 <mug_pretty_print_polynomial+0x128>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    $0xffffffff,%esi
call   1060 <mpz_cmp_si@plt>
cmp    $0x0,%eax
jne    1239 <mug_pretty_print_polynomial+0xe9>
cmpl   $0x0,-0x1c(%rbp)
jle    1239 <mug_pretty_print_polynomial+0xe9>
mov    -0x8(%rbp),%rdi
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1273 <mug_pretty_print_polynomial+0x123>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    $0xa,%esi
call   1040 <mpz_out_str@plt>
cmpl   $0x0,-0x1c(%rbp)
je     126e <mug_pretty_print_polynomial+0x11e>
mov    -0x8(%rbp),%rdi
lea    0xd9d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1273 <mug_pretty_print_polynomial+0x123>
jmp    1278 <mug_pretty_print_polynomial+0x128>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
test   %eax,%eax
je     129c <mug_pretty_print_polynomial+0x14c>
jmp    128b <mug_pretty_print_polynomial+0x13b>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
je     12a1 <mug_pretty_print_polynomial+0x151>
jmp    12b8 <mug_pretty_print_polynomial+0x168>
jmp    12cd <mug_pretty_print_polynomial+0x17d>
mov    -0x8(%rbp),%rdi
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12cd <mug_pretty_print_polynomial+0x17d>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xd42(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12d2 <mug_pretty_print_polynomial+0x182>
jmp    12d7 <mug_pretty_print_polynomial+0x187>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1169 <mug_pretty_print_polynomial+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mug_pretty_print_polynomial>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
js     11f3 <mug_pretty_print_polynomial+0x93>
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,%ebp
mov    (%rsi,%rbp,4),%edi
call   1080 <mpz_sgn@plt>
test   %eax,%eax
je     11ee <mug_pretty_print_polynomial+0x8e>
mov    (%rbx,%rbp,4),%edi
mov    $0x1,%esi
call   1060 <mpz_cmp_ui@plt>
test   %eax,%eax
je     11d4 <mug_pretty_print_polynomial+0x74>
mov    (%rbx,%rbp,4),%edi
mov    $0xffffffff,%esi
call   1070 <mpz_cmp_si@plt>
test   %eax,%eax
jne    11b2 <mug_pretty_print_polynomial+0x52>
mov    $0x2d,%edi
test   %r15d,%r15d
jne    11cc <mug_pretty_print_polynomial+0x6c>
mov    (%rbx,%rbp,4),%edx
mov    %r14,%rdi
mov    $0xa,%esi
call   1050 <mpz_out_str@plt>
mov    $0x2a,%edi
test   %r15d,%r15d
je     11f3 <mug_pretty_print_polynomial+0x93>
mov    %r14,%rsi
call   1030 <fputc@plt>
test   %r15d,%r15d
je     11f3 <mug_pretty_print_polynomial+0x93>
cmp    $0x1,%r15d
jne    11fe <mug_pretty_print_polynomial+0x9e>
mov    $0x78,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
jmp    1212 <mug_pretty_print_polynomial+0xb2>
test   %r15d,%r15d
jne    1212 <mug_pretty_print_polynomial+0xb2>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfb(%rip),%rsi
mov    %r14,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xde7(%rip),%r15
jmp    123b <mug_pretty_print_polynomial+0xdb>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0xffffffffffffffff,%rbp
lea    0x1(%rbp),%rax
cmp    $0x1,%rax
jbe    11f3 <mug_pretty_print_polynomial+0x93>
mov    -0x4(%rbx,%rbp,4),%edi
call   1080 <mpz_sgn@plt>
test   %eax,%eax
jle    1260 <mug_pretty_print_polynomial+0x100>
mov    $0x2b,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
jmp    1262 <mug_pretty_print_polynomial+0x102>
nopw   0x0(%rax,%rax,1)
je     122d <mug_pretty_print_polynomial+0xcd>
mov    -0x4(%rbx,%rbp,4),%edi
mov    $0x1,%esi
call   1060 <mpz_cmp_ui@plt>
test   %eax,%eax
je     12c0 <mug_pretty_print_polynomial+0x160>
mov    -0x4(%rbx,%rbp,4),%edi
mov    $0xffffffff,%esi
call   1070 <mpz_cmp_si@plt>
test   %eax,%eax
jne    1291 <mug_pretty_print_polynomial+0x131>
mov    $0x2d,%edi
cmp    $0x1,%rbp
jne    12c5 <mug_pretty_print_polynomial+0x165>
mov    -0x4(%rbx,%rbp,4),%edx
mov    %r14,%rdi
mov    $0xa,%esi
call   1050 <mpz_out_str@plt>
mov    $0x2a,%edi
cmp    $0x1,%rbp
jne    12c5 <mug_pretty_print_polynomial+0x165>
jmp    11f3 <mug_pretty_print_polynomial+0x93>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x2b,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
lea    -0x1(%rbp),%rdx
test   %edx,%edx
je     122d <mug_pretty_print_polynomial+0xcd>
cmp    $0x1,%edx
jne    1220 <mug_pretty_print_polynomial+0xc0>
mov    $0x78,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
jmp    122d <mug_pretty_print_polynomial+0xcd>

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

LLVM IR (-O2):
@.str.4 = [5 x i8] c"x^%d\00"
define void @mug_pretty_print_polynomial(i32* %0, i32* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, -1
br i1 %4, label %5, label %71
5: ; preds = %3
%6 = zext i32 %2 to i64
%7 = getelementptr inbounds i32, i32* %1, i64 %6
%8 = load i32, i32* %7
%9 = tail call i32 @mpz_sgn(i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %33, label %11
11: ; preds = %5
%12 = load i32, i32* %7
%13 = tail call i32 @mpz_cmp_ui(i32 %12, i32 1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %28, label %15
15: ; preds = %11
%16 = load i32, i32* %7
%17 = tail call i32 @mpz_cmp_si(i32 %16, i32 -1)
%18 = icmp eq i32 %17, 0
%19 = icmp ne i32 %2, 0
%20 = and i1 %18, %19
br i1 %20, label %25, label %21
21: ; preds = %15
%22 = load i32, i32* %7
%23 = tail call i32 @mpz_out_str(i32* %0, i32 10, i32 %22)
%24 = icmp eq i32 %2, 0
br i1 %24, label %71, label %25
25: ; preds = %15, %21
%26 = phi i32 [ 42, %21 ], [ 45, %15 ]
%27 = tail call i32 @fputc(i32 %26, i32* %0)
br label %28
28: ; preds = %25, %11
switch i32 %2, label %31 [
i32 0, label %71
i32 1, label %29
]
29: ; preds = %28
%30 = tail call i32 @fputc(i32 120, i32* %0)
br label %35
31: ; preds = %28
%32 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %2)
br label %35
33: ; preds = %5
%34 = icmp eq i32 %2, 0
br i1 %34, label %71, label %35
35: ; preds = %29, %31, %33
br label %36
36: ; preds = %35, %69
%37 = phi i64 [ %38, %69 ], [ %6, %35 ]
%38 = add nsw i64 %37, -1
%39 = getelementptr inbounds i32, i32* %1, i64 %38
%40 = load i32, i32* %39
%41 = tail call i32 @mpz_sgn(i32 %40)
%42 = icmp slt i32 %41, 1
br i1 %42, label %45, label %43
43: ; preds = %36
%44 = tail call i32 @fputc(i32 43, i32* %0)
br label %47
45: ; preds = %36
%46 = icmp eq i32 %41, 0
br i1 %46, label %69, label %47
47: ; preds = %43, %45
%48 = load i32, i32* %39
%49 = tail call i32 @mpz_cmp_ui(i32 %48, i32 1)
%50 = icmp eq i32 %49, 0
br i1 %50, label %61, label %51
51: ; preds = %47
%52 = load i32, i32* %39
%53 = tail call i32 @mpz_cmp_si(i32 %52, i32 -1)
%54 = icmp eq i32 %53, 0
%55 = icmp ne i64 %38, 0
%56 = select i1 %54, i1 %55, i1 false
br i1 %56, label %61, label %57
57: ; preds = %51
%58 = load i32, i32* %39
%59 = tail call i32 @mpz_out_str(i32* %0, i32 10, i32 %58)
%60 = icmp eq i64 %38, 0
br i1 %60, label %71, label %61
61: ; preds = %57, %51, %47
%62 = phi i32 [ 43, %47 ], [ 45, %51 ], [ 42, %57 ]
%63 = tail call i32 @fputc(i32 %62, i32* %0)
%64 = trunc i64 %38 to i32
switch i32 %64, label %67 [
i32 0, label %69
i32 1, label %65
]
65: ; preds = %61
%66 = tail call i32 @fputc(i32 120, i32* %0)
br label %69
67: ; preds = %61
%68 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %64)
br label %69
69: ; preds = %45, %67, %65, %61
%70 = icmp ugt i64 %37, 1
br i1 %70, label %36, label %71
71: ; preds = %57, %69, %21, %28, %33, %3
ret void
}