#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 */
struct timeval {
  scalar_t__ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
long pow(long, int);
int /*<<< orphan*/ printf(char *, long, ...);
int main(void) {
  struct timeval stop, start;
  gettimeofday(&start, NULL);
  int i;
  long sum = 0, squared = 0, squaredsum = 0;
  for (i = 1; i <= 100; i++) {
    sum += i;
    squared += pow(i, 2);
  }
  squaredsum = pow(sum, 2);
  printf("%lu - %lu = %lu", squaredsum, squared, squaredsum - squared);
  gettimeofday(&stop, NULL);
  printf("\ntook %lu usec\n", stop.tv_usec - start.tv_usec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jg     11a5 <main+0x75>
movslq -0x1c(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
movslq -0x1c(%rbp),%rdi
mov    $0x2,%esi
call   1050 <pow@plt>
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116b <main+0x3b>
mov    -0x28(%rbp),%rdi
mov    $0x2,%esi
call   1050 <pow@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
sub    -0x30(%rbp),%rcx
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x10(%rbp),%rsi
sub    -0x18(%rbp),%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %r14d,%r14d
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    $0x1,%ebx
nop
mov    %rbx,%rdi
mov    $0x2,%esi
call   1050 <pow@plt>
mov    %rax,%r15
add    %r14,%r15
lea    0x1(%rbx),%rdi
mov    $0x2,%esi
call   1050 <pow@plt>
mov    %rax,%r14
add    %r15,%r14
lea    0x2(%rbx),%rdi
mov    $0x2,%esi
call   1050 <pow@plt>
mov    %rax,%r15
add    %r14,%r15
lea    0x3(%rbx),%rdi
mov    $0x2,%esi
call   1050 <pow@plt>
mov    %rax,%r12
add    %r15,%r12
lea    0x4(%rbx),%rdi
mov    $0x2,%esi
call   1050 <pow@plt>
mov    %rax,%r14
add    %r12,%r14
add    $0x5,%rbx
cmp    $0x65,%rbx
jne    1150 <main+0x20>
mov    $0x13ba,%edi
mov    $0x2,%esi
call   1050 <pow@plt>
mov    %rax,%rcx
sub    %r14,%rcx
lea    0xe27(%rip),%rdi
mov    %rax,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x10(%rsp),%rsi
sub    0x8(%rsp),%rsi
lea    0xe0d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
@.str = [16 x i8] c"%lu - %lu = %lu\00"
@.str.1 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
store i64 0, i64* %5
store i64 0, i64* %6
store i64 0, i64* %7
store i32 1, i32* %4
br label %9
9: ; preds = %22, %0
%10 = load i32, i32* %4
%11 = icmp sle i32 %10, 100
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = load i64, i64* %5
%16 = add nsw i64 %15, %14
store i64 %16, i64* %5
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = call i64 @pow(i64 %18, i32 2)
%20 = load i64, i64* %6
%21 = add nsw i64 %20, %19
store i64 %21, i64* %6
br label %22
22: ; preds = %12
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %9
25: ; preds = %9
%26 = load i64, i64* %5
%27 = call i64 @pow(i64 %26, i32 2)
store i64 %27, i64* %7
%28 = load i64, i64* %7
%29 = load i64, i64* %6
%30 = load i64, i64* %7
%31 = load i64, i64* %6
%32 = sub nsw i64 %30, %31
%33 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 %28, i64 %29, i64 %32)
%34 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%36 = load i64, i64* %35
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%38 = load i64, i64* %37
%39 = sub nsw i64 %36, %38
%40 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %39)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@.str = [16 x i8] c"%lu - %lu = %lu\00"
@.str.1 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
br label %6
6: ; preds = %6, %0
%7 = phi i64 [ 1, %0 ], [ %23, %6 ]
%8 = phi i64 [ 0, %0 ], [ %22, %6 ]
%9 = tail call i64 @pow(i64 %7, i32 2)
%10 = add nsw i64 %9, %8
%11 = add nuw nsw i64 %7, 1
%12 = tail call i64 @pow(i64 %11, i32 2)
%13 = add nsw i64 %12, %10
%14 = add nuw nsw i64 %7, 2
%15 = tail call i64 @pow(i64 %14, i32 2)
%16 = add nsw i64 %15, %13
%17 = add nuw nsw i64 %7, 3
%18 = tail call i64 @pow(i64 %17, i32 2)
%19 = add nsw i64 %18, %16
%20 = add nuw nsw i64 %7, 4
%21 = tail call i64 @pow(i64 %20, i32 2)
%22 = add nsw i64 %21, %19
%23 = add nuw nsw i64 %7, 5
%24 = icmp eq i64 %23, 101
br i1 %24, label %25, label %6
25: ; preds = %6
%26 = tail call i64 @pow(i64 5050, i32 2)
%27 = sub nsw i64 %26, %22
%28 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 %26, i64 %22, i64 %27)
%29 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%31 = load i64, i64* %30
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%33 = load i64, i64* %32
%34 = sub nsw i64 %31, %33
%35 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %34)
ret i32 0
}