#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 */
scalar_t__ last_ten(int);
int /*<<< orphan*/ printf(char *, long long);
int main() {
  long long sum = 0;
  int i;
  for (i = 1; i < 1001; ++i) {
    sum += last_ten(i);
    if (sum > 10000000000)
      sum %= 10000000000;
  }
  printf("%lld\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x3e9,-0x14(%rbp)
jge    1199 <main+0x79>
mov    -0x14(%rbp),%edi
call   1040 <last_ten@plt>
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
movabs $0x2540be400,%rax
cmp    %rax,-0x10(%rbp)
jle    1186 <main+0x66>
mov    -0x10(%rbp),%rax
movabs $0x2540be400,%rcx
cqto
idiv   %rcx
mov    %rdx,-0x10(%rbp)
jmp    118b <main+0x6b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <main+0x1e>
mov    -0x10(%rbp),%rsi
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0x1,%ebx
xor    %esi,%esi
movabs $0x2540be401,%r14
movabs $0x36f9bfb3af7b757,%r15
9b 6f 03
movabs $0x2540be400,%r12
jmp    115b <main+0x3b>
add    $0x1,%ebx
cmp    $0x3e9,%ebx
je     118d <main+0x6d>
mov    %rsi,%r13
mov    %ebx,%edi
call   1040 <last_ten@plt>
mov    %rax,%rsi
add    %r13,%rsi
cmp    %r14,%rsi
jl     1150 <main+0x30>
mov    %rsi,%rax
imul   %r15
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x1b,%rdx
add    %rax,%rdx
imul   %r12,%rdx
sub    %rdx,%rsi
jmp    1150 <main+0x30>
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
store i32 0, i32* %1
store i64 0, i64* %2
store i32 1, i32* %3
br label %4
4: ; preds = %18, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 1001
br i1 %6, label %7, label %21
7: ; preds = %4
%8 = load i32, i32* %3
%9 = call i64 @last_ten(i32 %8)
%10 = load i64, i64* %2
%11 = add nsw i64 %10, %9
store i64 %11, i64* %2
%12 = load i64, i64* %2
%13 = icmp sgt i64 %12, 10000000000
br i1 %13, label %14, label %17
14: ; preds = %7
%15 = load i64, i64* %2
%16 = srem i64 %15, 10000000000
store i64 %16, i64* %2
br label %17
17: ; preds = %14, %7
br label %18
18: ; preds = %17
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %4
21: ; preds = %4
%22 = load i64, i64* %2
%23 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%lld\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 1, %0 ], [ %9, %1 ]
%3 = phi i64 [ 0, %0 ], [ %8, %1 ]
%4 = tail call i64 @last_ten(i32 %2)
%5 = add nsw i64 %4, %3
%6 = icmp sgt i64 %5, 10000000000
%7 = srem i64 %5, 10000000000
%8 = select i1 %6, i64 %7, i64 %5
%9 = add nuw nsw i32 %2, 1
%10 = icmp eq i32 %9, 1001
br i1 %10, label %11, label %1
11: ; preds = %1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %8)
ret i32 0
}