#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_4_pow(int, int);
int /*<<< orphan*/ printf(char *, long);
int main() {
  long res = 0;
  int i;
  for (i = 1; i < 1000; i++) {
    res += last_4_pow(i, i);
    res %= 10000000000;
  }
  printf("result:  %ld", res);
  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   $0x3e8,-0x14(%rbp)
jge    1183 <main+0x63>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <last_4_pow@plt>
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movabs $0x2540be400,%rcx
cqto
idiv   %rcx
mov    %rdx,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <main+0x1e>
mov    -0x10(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%ebp
xor    %ebx,%ebx
movabs $0x36f9bfb3af7b757,%r14
9b 6f 03
movabs $0x2540be400,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %ebp,%esi
call   1030 <last_4_pow@plt>
add    %rax,%rbx
mov    %rbx,%rax
imul   %r14
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x1b,%rdx
add    %rax,%rdx
imul   %r15,%rdx
sub    %rdx,%rbx
add    $0x1,%ebp
cmp    $0x3e8,%ebp
jne    1150 <main+0x30>
lea    0xe77(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"result: %ld\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 = %15, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 1000
br i1 %6, label %7, label %18
7: ; preds = %4
%8 = load i32, i32* %3
%9 = load i32, i32* %3
%10 = call i64 @last_4_pow(i32 %8, i32 %9)
%11 = load i64, i64* %2
%12 = add nsw i64 %11, %10
store i64 %12, i64* %2
%13 = load i64, i64* %2
%14 = srem i64 %13, 10000000000
store i64 %14, i64* %2
br label %15
15: ; preds = %7
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %4
18: ; preds = %4
%19 = load i64, i64* %2
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %19)
ret i32 0
}

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