#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__ is_prime(unsigned long);
int /*<<< orphan*/ printf(char *, float);
int sqrt(unsigned long long);
float timeit();
int main(int argc, char *argv[]) {
  float start = timeit();
  unsigned long long limit = 600851475143;
  unsigned long high = 0, i = 0;
  while (i++ < sqrt(limit) + 1)
    high = limit % i == 0 && is_prime(i) ? i : high;
  float stop = timeit();
  printf("Answer: %ld\n", high);
  printf("Time: %.8f\n", stop - start);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <timeit@plt>
movss  %xmm0,-0x14(%rbp)
movabs $0x8be589eac7,%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <sqrt@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jae    11f9 <main+0xb9>
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x30(%rbp)
cmp    $0x0,%rdx
jne    11e4 <main+0xa4>
mov    -0x30(%rbp),%rdi
call   1040 <is_prime@plt>
cmp    $0x0,%rax
je     11e4 <main+0xa4>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    11ec <main+0xac>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1180 <main+0x40>
xor    %eax,%eax
call   1050 <timeit@plt>
movss  %xmm0,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x50(%rbp)
test   %rax,%rax
movss  %xmm0,-0x4c(%rbp)
js     1242 <main+0x102>
movss  -0x50(%rbp),%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x4c(%rbp),%xmm0
lea    0xdb2(%rip),%rdi
call   1030 <printf@plt>
movss  -0x34(%rbp),%xmm0
subss  -0x14(%rbp),%xmm0
lea    0xda9(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movabs $0x8be589eac7,%r14
xor    %r12d,%r12d
xor    %eax,%eax
call   1050 <timeit@plt>
movss  %xmm0,0xc(%rsp)
mov    %r14,%rdi
call   1060 <sqrt@plt>
cmp    $0xffffffff,%eax
je     11cb <main+0x8b>
xor    %r13d,%r13d
movabs $0x8be589eac7,%r15
xor    %ebx,%ebx
jmp    11a8 <main+0x68>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%r12
mov    %r14,%rdi
call   1060 <sqrt@plt>
add    $0x1,%eax
cltq
mov    %r12,%rbx
cmp    %rax,%r13
jae    11cb <main+0x8b>
add    $0x1,%r13
mov    %r15,%rax
xor    %edx,%edx
div    %r13
test   %rdx,%rdx
jne    1190 <main+0x50>
mov    %r13,%rdi
call   1040 <is_prime@plt>
mov    %r13,%r12
test   %rax,%rax
jne    1193 <main+0x53>
jmp    1190 <main+0x50>
xor    %eax,%eax
call   1050 <timeit@plt>
test   %r12,%r12
movss  %xmm0,0x8(%rsp)
js     11e7 <main+0xa7>
xorps  %xmm0,%xmm0
cvtsi2ss %r12,%xmm0
jmp    1200 <main+0xc0>
mov    %r12,%rax
shr    %rax
and    $0x1,%r12d
or     %rax,%r12
xorps  %xmm0,%xmm0
cvtsi2ss %r12,%xmm0
addss  %xmm0,%xmm0
lea    0xdf9(%rip),%rdi
call   1030 <printf@plt>
movss  0x8(%rsp),%xmm0
subss  0xc(%rsp),%xmm0
lea    0xdee(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"Answer: %ld\0A\00"
@.str.1 = [12 x i8] c"Time: %.8f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call float (...) @timeit()
%4 = tail call i32 @sqrt(i64 600851475143)
%5 = icmp eq i32 %4, -1
br i1 %5, label %22, label %6
6: ; preds = %2, %15
%7 = phi i64 [ %17, %15 ], [ 1, %2 ]
%8 = phi i64 [ %16, %15 ], [ 0, %2 ]
%9 = urem i64 600851475143, %7
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = tail call i64 @is_prime(i64 %7)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11, %6
br label %15
15: ; preds = %11, %14
%16 = phi i64 [ %8, %14 ], [ %7, %11 ]
%17 = add i64 %7, 1
%18 = tail call i32 @sqrt(i64 600851475143)
%19 = add nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = icmp ult i64 %7, %20
br i1 %21, label %6, label %22
22: ; preds = %15, %2
%23 = phi i64 [ 0, %2 ], [ %16, %15 ]
%24 = tail call float (...) @timeit()
%25 = uitofp i64 %23 to float
%26 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), float %25)
%27 = fsub float %24, %3
%28 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), float %27)
ret i32 0
}