#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 power(int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int n, x, i, sum = 0;
  scanf("%d%d", &n, &x);
  int arr[n + 1];
  for (i = 0; i <= n; i++)
    scanf("%d", &arr[i]);
  for (i = n; i >= 0; i--)
    sum = sum + arr[i] * power(x, n - i);
  printf("%d", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeb3(%rip),%rdi
xor    %eax,%eax
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11c4 <main+0x94>
mov    -0x30(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118d <main+0x5d>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1214 <main+0xe4>
mov    -0x30(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,-0x34(%rbp)
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x38(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
sub    -0x10(%rbp),%esi
call   1030 <power@plt>
mov    -0x38(%rbp),%ecx
mov    %eax,%edx
mov    -0x34(%rbp),%eax
imul   %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    11ca <main+0x9a>
mov    -0x14(%rbp),%esi
lea    0xde4(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeb8(%rip),%rdi
xor    %r14d,%r14d
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %rsp,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmpl   $0x0,-0x2c(%rbp)
js     121d <main+0xed>
mov    $0xffffffffffffffff,%r13
lea    0xe71(%rip),%r14
mov    %r12,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movslq -0x2c(%rbp),%rax
add    $0x1,%r13
add    $0x4,%rbx
cmp    %rax,%r13
jl     11a0 <main+0x70>
mov    %eax,%r15d
test   %r15d,%r15d
js     121a <main+0xea>
mov    (%r12,%r15,4),%ebx
mov    -0x30(%rbp),%edi
xor    %esi,%esi
call   1030 <power@plt>
mov    %eax,%r14d
imul   %ebx,%r14d
test   %r15,%r15
je     121d <main+0xed>
mov    %r15,%rbx
add    $0x1,%rbx
mov    $0x1,%r13d
sub    %r15d,%r13d
mov    -0x8(%r12,%rbx,4),%r15d
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%esi
add    %r13d,%esi
call   1030 <power@plt>
imul   %r15d,%eax
add    %eax,%r14d
add    $0xffffffffffffffff,%rbx
add    $0x1,%r13d
cmp    $0x1,%rbx
jg     11f0 <main+0xc0>
jmp    121d <main+0xed>
xor    %r14d,%r14d
lea    0xdde(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d%d\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %5
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%9 = load i32, i32* %2
%10 = add nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i32, i64 %11
store i64 %11, i64* %7
store i32 0, i32* %4
br label %14
14: ; preds = %23, %0
%15 = load i32, i32* %4
%16 = load i32, i32* %2
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %13, i64 %20
%22 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %21)
br label %23
23: ; preds = %18
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %14
26: ; preds = %14
%27 = load i32, i32* %2
store i32 %27, i32* %4
br label %28
28: ; preds = %44, %26
%29 = load i32, i32* %4
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %47
31: ; preds = %28
%32 = load i32, i32* %5
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %13, i64 %34
%36 = load i32, i32* %35
%37 = load i32, i32* %3
%38 = load i32, i32* %2
%39 = load i32, i32* %4
%40 = sub nsw i32 %38, %39
%41 = call i32 @power(i32 %37, i32 %40)
%42 = mul nsw i32 %36, %41
%43 = add nsw i32 %32, %42
store i32 %43, i32* %5
br label %44
44: ; preds = %31
%45 = load i32, i32* %4
%46 = add nsw i32 %45, -1
store i32 %46, i32* %4
br label %28
47: ; preds = %28
%48 = load i32, i32* %5
%49 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %48)
store i32 0, i32* %1
%50 = load i8*, i8** %6
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d%d\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, 1
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
%10 = alloca i32, i64 %8
%11 = load i32, i32* %1
%12 = icmp slt i32 %11, 0
br i1 %12, label %45, label %23
13: ; preds = %23
%14 = icmp sgt i32 %28, -1
br i1 %14, label %15, label %45
15: ; preds = %13
%16 = zext i32 %28 to i64
%17 = getelementptr inbounds i32, i32* %10, i64 %16
%18 = load i32, i32* %17
%19 = load i32, i32* %2
%20 = call i32 @power(i32 %19, i32 0)
%21 = mul nsw i32 %20, %18
%22 = icmp eq i32 %28, 0
br i1 %22, label %45, label %31
23: ; preds = %0, %23
%24 = phi i64 [ %27, %23 ], [ 0, %0 ]
%25 = getelementptr inbounds i32, i32* %10, i64 %24
%26 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %25)
%27 = add nuw nsw i64 %24, 1
%28 = load i32, i32* %1
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %24, %29
br i1 %30, label %23, label %13
31: ; preds = %15, %31
%32 = phi i32 [ %43, %31 ], [ %21, %15 ]
%33 = phi i64 [ %34, %31 ], [ %16, %15 ]
%34 = add nsw i64 %33, -1
%35 = load i32, i32* %1
%36 = getelementptr inbounds i32, i32* %10, i64 %34
%37 = load i32, i32* %36
%38 = load i32, i32* %2
%39 = trunc i64 %34 to i32
%40 = sub nsw i32 %35, %39
%41 = call i32 @power(i32 %38, i32 %40)
%42 = mul nsw i32 %41, %37
%43 = add nsw i32 %42, %32
%44 = icmp sgt i64 %33, 1
br i1 %44, label %31, label %45
45: ; preds = %31, %15, %0, %13
%46 = phi i32 [ 0, %13 ], [ 0, %0 ], [ %21, %15 ], [ %43, %31 ]
%47 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %46)
ret i32 0
}