#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 /*<<< orphan*/ calculate_values(long *, int *, int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
long lagrange_poly_val(long *, int, int);
int /*<<< orphan*/ load_coefficients(int *, char **);
int /*<<< orphan*/ printf(char *, long);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "usage: %s a_0 a_1 a_2...\n", argv[0]);
    return 1;
  }
  int poly_terms = argc - 1;
  int poly_coeffs[poly_terms];
  long poly_vals[poly_terms];
  load_coefficients(poly_coeffs, argv + 1);
  calculate_values(poly_vals, poly_coeffs, poly_terms, poly_terms);
  long bop_sum = 0;
  for (int i = 1; i < poly_terms; i++) {
    long extrapolated_val = lagrange_poly_val(poly_vals, i, i + 1);
    if (extrapolated_val != poly_vals[i])
      bop_sum += extrapolated_val;
  }
  printf("%ld\n", bop_sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1198 <main+0x48>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    128c <main+0x13c>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1060 <load_coefficients@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <calculate_values@plt>
movq   $0x0,-0x38(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    126e <main+0x11e>
mov    -0x58(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x3c(%rbp),%edx
add    $0x1,%edx
call   1070 <lagrange_poly_val@plt>
mov    -0x58(%rbp),%rcx
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movslq -0x3c(%rbp),%rdx
cmp    (%rcx,%rdx,8),%rax
je     125b <main+0x10b>
mov    -0x48(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1260 <main+0x110>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1217 <main+0xc7>
mov    -0x38(%rbp),%rsi
lea    0xda1(%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
cmp    $0x1,%edi
jg     1185 <main+0x35>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe87(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    11f9 <main+0xa9>
mov    %edi,%r13d
mov    %rsp,-0x30(%rbp)
lea    -0x1(%r13),%r14d
mov    %rsp,%rbx
lea    0xf(,%r14,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r12
lea    0xf(,%r14,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
add    $0x8,%rsi
mov    %rbx,%rdi
call   1060 <load_coefficients@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
mov    %r14,-0x38(%rbp)
mov    %r14d,%ecx
call   1030 <calculate_values@plt>
cmp    $0x2,%r13d
jne    1208 <main+0xb8>
xor    %r13d,%r13d
lea    0xe2f(%rip),%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r15d
mov    $0x2,%ebx
xor    %r13d,%r13d
jmp    122c <main+0xdc>
nopl   0x0(%rax,%rax,1)
add    %rax,%r13
add    $0x1,%ebx
cmp    %r15,-0x38(%rbp)
je     11e4 <main+0x94>
mov    %r15,%r14
add    $0x1,%r15
mov    %r12,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
call   1070 <lagrange_poly_val@plt>
cmp    (%r12,%r14,8),%rax
jne    1220 <main+0xd0>
xor    %eax,%eax
jmp    1220 <main+0xd0>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"usage: %s a_0 a_1 a_2...\0A\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
br label %64
21: ; preds = %2
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 1
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = zext i32 %24 to i64
%26 = call i8* @llvm.stacksave()
store i8* %26, i8** %7
%27 = alloca i32, i64 %25
store i64 %25, i64* %8
%28 = load i32, i32* %6
%29 = zext i32 %28 to i64
%30 = alloca i64, i64 %29
store i64 %29, i64* %9
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = call i32 @load_coefficients(i32* %27, i8** %32)
%34 = load i32, i32* %6
%35 = load i32, i32* %6
%36 = call i32 @calculate_values(i64* %30, i32* %27, i32 %34, i32 %35)
store i64 0, i64* %10
store i32 1, i32* %11
br label %37
37: ; preds = %57, %21
%38 = load i32, i32* %11
%39 = load i32, i32* %6
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %60
41: ; preds = %37
%42 = load i32, i32* %11
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
%45 = call i64 @lagrange_poly_val(i64* %30, i32 %42, i32 %44)
store i64 %45, i64* %12
%46 = load i64, i64* %12
%47 = load i32, i32* %11
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i64, i64* %30, i64 %48
%50 = load i64, i64* %49
%51 = icmp ne i64 %46, %50
br i1 %51, label %52, label %56
52: ; preds = %41
%53 = load i64, i64* %12
%54 = load i64, i64* %10
%55 = add nsw i64 %54, %53
store i64 %55, i64* %10
br label %56
56: ; preds = %52, %41
br label %57
57: ; preds = %56
%58 = load i32, i32* %11
%59 = add nsw i32 %58, 1
store i32 %59, i32* %11
br label %37
60: ; preds = %37
%61 = load i64, i64* %10
%62 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %61)
store i32 0, i32* %3
%63 = load i8*, i8** %7
br label %64
64: ; preds = %60, %15
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"usage: %s a_0 a_1 a_2...\0A\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %34
8: ; preds = %2
%9 = add nsw i32 %0, -1
%10 = zext i32 %9 to i64
%11 = tail call i8* @llvm.stacksave()
%12 = alloca i32, i64 %10
%13 = alloca i64, i64 %10
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = call i32 @load_coefficients(i32* %12, i8** %14)
%16 = call i32 @calculate_values(i64* %13, i32* %12, i32 %9, i32 %9)
%17 = icmp eq i32 %0, 2
br i1 %17, label %18, label %21
18: ; preds = %21, %8
%19 = phi i64 [ 0, %8 ], [ %32, %21 ]
%20 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %19)
br label %34
21: ; preds = %8, %21
%22 = phi i64 [ %24, %21 ], [ 1, %8 ]
%23 = phi i64 [ %32, %21 ], [ 0, %8 ]
%24 = add nuw nsw i64 %22, 1
%25 = trunc i64 %24 to i32
%26 = trunc i64 %22 to i32
%27 = call i64 @lagrange_poly_val(i64* %13, i32 %26, i32 %25)
%28 = getelementptr inbounds i64, i64* %13, i64 %22
%29 = load i64, i64* %28
%30 = icmp eq i64 %27, %29
%31 = select i1 %30, i64 0, i64 %27
%32 = add nsw i64 %31, %23
%33 = icmp eq i64 %24, %10
br i1 %33, label %18, label %21
34: ; preds = %18, %4
%35 = phi i32 [ 1, %4 ], [ 0, %18 ]
ret i32 %35
}