#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 polynomial(int *, int *, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, vet[10], i, j, x, p[10], ind, cont;
  printf("Digite o grau do polimonio: \n");
  scanf("%d", &n);
  for (i = n; i >= 0; i--) {
    printf("Coeficiente de A[%d]: \n", i);
    scanf("%d", &vet[i]);
  }
  printf("Digite um valor para a,tal que (x-a = 0): \n");
  scanf("%d", &x);
  ind = n;
  for (j = n - 1; j >= 0; j--) {
    p[j] = polynomial(vet, p, j, x, ind);
  }
  for (i = ind - 1; i >= 0; i--) {
    printf("%dx^%d + ", p[i], i);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     11aa <main+0x7a>
mov    -0x34(%rbp),%esi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x34(%rbp),%rax
lea    -0x30(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe87(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    1166 <main+0x36>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5f(%rip),%rdi
lea    -0x3c(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jl     1210 <main+0xe0>
lea    -0x30(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    -0x38(%rbp),%edx
mov    -0x3c(%rbp),%ecx
mov    -0x74(%rbp),%r8d
call   1030 <polynomial@plt>
mov    %eax,%ecx
movslq -0x38(%rbp),%rax
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    11d7 <main+0xa7>
mov    -0x74(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     124a <main+0x11a>
movslq -0x34(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%esi
mov    -0x34(%rbp),%edx
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    1219 <main+0xe9>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x70,%rsp
lea    0xed1(%rip),%rdi
call   1040 <puts@plt>
lea    0xea0(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x8(%rsp),%r14d
test   %r14d,%r14d
js     11b2 <main+0x72>
lea    (%rsp,%r14,4),%rbx
add    $0x40,%rbx
lea    0xe80(%rip),%r15
lea    0xe76(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0xfffffffffffffffc,%rbx
add    $0xffffffffffffffff,%r14
jb     1190 <main+0x50>
lea    0xe89(%rip),%rdi
call   1040 <puts@plt>
lea    0xe3b(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x8(%rsp),%r14d
test   %r14d,%r14d
jle    1238 <main+0xf8>
lea    -0x1(%r14),%eax
mov    %eax,%r13d
lea    0x40(%rsp),%r15
lea    0x10(%rsp),%r12
mov    %r13,%rbx
nopl   (%rax)
mov    0xc(%rsp),%ecx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
mov    %r14d,%r8d
call   1030 <polynomial@plt>
mov    %eax,0x10(%rsp,%rbx,4)
add    $0xffffffffffffffff,%rbx
jb     11f0 <main+0xb0>
test   %r14d,%r14d
jle    1238 <main+0xf8>
lea    0xe01(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp,%r13,4),%esi
mov    %r14,%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffffffffffff,%r13
jb     1220 <main+0xe0>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Digite o grau do polimonio: \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [24 x i8] c"Coeficiente de A[%d]: \0A\00"
@.str.3 = [44 x i8] c"Digite um valor para a,tal que (x-a = 0): \0A\00"
@.str.4 = [10 x i8] c"%dx^%d + \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [10 x i32]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
store i32 %12, i32* %4
br label %13
13: ; preds = %23, %0
%14 = load i32, i32* %4
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i32, i32* %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %20
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %21)
br label %23
23: ; preds = %16
%24 = load i32, i32* %4
%25 = add nsw i32 %24, -1
store i32 %25, i32* %4
br label %13
26: ; preds = %13
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%29 = load i32, i32* %2
store i32 %29, i32* %8
%30 = load i32, i32* %2
%31 = sub nsw i32 %30, 1
store i32 %31, i32* %5
br label %32
32: ; preds = %45, %26
%33 = load i32, i32* %5
%34 = icmp sge i32 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %32
%36 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%37 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 0
%38 = load i32, i32* %5
%39 = load i32, i32* %6
%40 = load i32, i32* %8
%41 = call i32 @polynomial(i32* %36, i32* %37, i32 %38, i32 %39, i32 %40)
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 %43
store i32 %41, i32* %44
br label %45
45: ; preds = %35
%46 = load i32, i32* %5
%47 = add nsw i32 %46, -1
store i32 %47, i32* %5
br label %32
48: ; preds = %32
%49 = load i32, i32* %8
%50 = sub nsw i32 %49, 1
store i32 %50, i32* %4
br label %51
51: ; preds = %61, %48
%52 = load i32, i32* %4
%53 = icmp sge i32 %52, 0
br i1 %53, label %54, label %64
54: ; preds = %51
%55 = load i32, i32* %4
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 %56
%58 = load i32, i32* %57
%59 = load i32, i32* %4
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %58, i32 %59)
br label %61
61: ; preds = %54
%62 = load i32, i32* %4
%63 = add nsw i32 %62, -1
store i32 %63, i32* %4
br label %51
64: ; preds = %51
%65 = load i32, i32* %1
ret i32 %65
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [24 x i8] c"Coeficiente de A[%d]: \0A\00"
@.str.4 = [10 x i8] c"%dx^%d + \00"
@str = [29 x i8] c"Digite o grau do polimonio: \00"
@str.5 = [43 x i8] c"Digite um valor para a,tal que (x-a = 0): \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = alloca [10 x i32]
%5 = bitcast i32* %1 to i8*
%6 = bitcast [10 x i32]* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast [10 x i32]* %4 to i8*
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, -1
br i1 %12, label %13, label %23
13: ; preds = %0
%14 = zext i32 %11 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ %14, %13 ], [ %21, %15 ]
%17 = trunc i64 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %16
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %19)
%21 = add nsw i64 %16, -1
%22 = icmp eq i64 %16, 0
br i1 %22, label %23, label %15
23: ; preds = %15, %0
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.5, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%26 = load i32, i32* %1
%27 = add i32 %26, -1
%28 = icmp sgt i32 %26, 0
br i1 %28, label %29, label %52
29: ; preds = %23
%30 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%31 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 0
%32 = zext i32 %27 to i64
br label %36
33: ; preds = %36
br i1 %28, label %34, label %52
34: ; preds = %33
%35 = zext i32 %27 to i64
br label %44
36: ; preds = %29, %36
%37 = phi i64 [ %32, %29 ], [ %42, %36 ]
%38 = load i32, i32* %3
%39 = trunc i64 %37 to i32
%40 = call i32 @polynomial(i32* %30, i32* %31, i32 %39, i32 %38, i32 %26)
%41 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 %37
store i32 %40, i32* %41
%42 = add nsw i64 %37, -1
%43 = icmp eq i64 %37, 0
br i1 %43, label %33, label %36
44: ; preds = %34, %44
%45 = phi i64 [ %35, %34 ], [ %50, %44 ]
%46 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = trunc i64 %45 to i32
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %47, i32 %48)
%50 = add nsw i64 %45, -1
%51 = icmp eq i64 %45, 0
br i1 %51, label %52, label %44
52: ; preds = %44, %23, %33
ret i32 0
}