#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__ grid(int, int, int);
int /*<<< orphan*/ printf(char *, float);
long spiral_total(int);
float timeit();
int main(int argc, char *argv[]) {
  float start = timeit();
  int diagonal_pos = 3;
  long total = spiral_total(1001);
  int end_axis = 1001994;
  for (int i = 10; i < 15; i += 2) {
    total += grid(diagonal_pos, i, end_axis);
    diagonal_pos += 2;
    end_axis += 2;
  }
  float stop = timeit();
  printf("Answer: %ld\n", total);
  printf("Time: %f\n", stop - start);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <timeit@plt>
movss  %xmm0,-0x14(%rbp)
movl   $0x3,-0x18(%rbp)
mov    $0x3e9,%edi
call   1040 <spiral_total@plt>
mov    %rax,-0x20(%rbp)
movl   $0xf4a0a,-0x24(%rbp)
movl   $0xa,-0x28(%rbp)
cmpl   $0xf,-0x28(%rbp)
jge    11c5 <main+0x85>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1050 <grid@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x28(%rbp)
jmp    1185 <main+0x45>
mov    $0x0,%al
call   1060 <timeit@plt>
movss  %xmm0,-0x2c(%rbp)
cvtsi2ssq -0x20(%rbp),%xmm0
lea    0xe22(%rip),%rdi
call   1030 <printf@plt>
movss  -0x2c(%rbp),%xmm0
subss  -0x14(%rbp),%xmm0
lea    0xe19(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <timeit@plt>
movss  %xmm0,0x4(%rsp)
mov    $0x3e9,%edi
call   1040 <spiral_total@plt>
mov    %rax,%r14
mov    $0x3,%edi
mov    $0xa,%esi
mov    $0xf4a0a,%edx
call   1050 <grid@plt>
mov    %rax,%rbx
add    %r14,%rbx
mov    $0x5,%edi
mov    $0xc,%esi
mov    $0xf4a0c,%edx
call   1050 <grid@plt>
mov    %rax,%r14
add    %rbx,%r14
mov    $0x7,%edi
mov    $0xe,%esi
mov    $0xf4a0e,%edx
call   1050 <grid@plt>
mov    %rax,%rbx
add    %r14,%rbx
xor    %eax,%eax
call   1060 <timeit@plt>
movss  %xmm0,(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %rbx,%xmm0
lea    0xe39(%rip),%rdi
call   1030 <printf@plt>
movss  (%rsp),%xmm0
subss  0x4(%rsp),%xmm0
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Answer: %ld\0A\00"
@.str.1 = [10 x i8] c"Time: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call float (...) @timeit()
store float %12, float* %6
store i32 3, i32* %7
%13 = call i64 @spiral_total(i32 1001)
store i64 %13, i64* %8
store i32 1001994, i32* %9
store i32 10, i32* %10
br label %14
14: ; preds = %28, %2
%15 = load i32, i32* %10
%16 = icmp slt i32 %15, 15
br i1 %16, label %17, label %31
17: ; preds = %14
%18 = load i32, i32* %7
%19 = load i32, i32* %10
%20 = load i32, i32* %9
%21 = call i64 @grid(i32 %18, i32 %19, i32 %20)
%22 = load i64, i64* %8
%23 = add nsw i64 %22, %21
store i64 %23, i64* %8
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 2
store i32 %25, i32* %7
%26 = load i32, i32* %9
%27 = add nsw i32 %26, 2
store i32 %27, i32* %9
br label %28
28: ; preds = %17
%29 = load i32, i32* %10
%30 = add nsw i32 %29, 2
store i32 %30, i32* %10
br label %14
31: ; preds = %14
%32 = call float (...) @timeit()
store float %32, float* %11
%33 = load i64, i64* %8
%34 = sitofp i64 %33 to float
%35 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), float %34)
%36 = load float, float* %11
%37 = load float, float* %6
%38 = fsub float %36, %37
%39 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), float %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"Answer: %ld\0A\00"
@.str.1 = [10 x i8] c"Time: %f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call float (...) @timeit()
%4 = tail call i64 @spiral_total(i32 1001)
%5 = tail call i64 @grid(i32 3, i32 10, i32 1001994)
%6 = add nsw i64 %5, %4
%7 = tail call i64 @grid(i32 5, i32 12, i32 1001996)
%8 = add nsw i64 %7, %6
%9 = tail call i64 @grid(i32 7, i32 14, i32 1001998)
%10 = add nsw i64 %9, %8
%11 = tail call float (...) @timeit()
%12 = sitofp i64 %10 to float
%13 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), float %12)
%14 = fsub float %11, %3
%15 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), float %14)
ret i32 0
}