#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ check_prime(unsigned long);
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, double);
scalar_t__ sqrt(unsigned long);
int main() {
  unsigned long int sr, flag = 1;
  clock_t begin, end;
  double time_spent;
  begin = clock();
  sr = ((unsigned long int)sqrt(6008514751431UL)) + 1;
  while ((sr > 1) && (flag)) {
    if (check_prime(sr)) {
      if (!(6008514751431UL % sr))
        flag = 0UL;
    }
    sr--;
  }
  printf("\nLargest Prime Factor is %u", sr + 1);
  end = clock();
  time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("\n%g", time_spent);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x1,-0x18(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x20(%rbp)
movabs $0x576f7632bc7,%rdi
call   1060 <sqrt@plt>
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x1,-0x10(%rbp)
mov    %al,-0x31(%rbp)
jbe    1194 <main+0x54>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11a4 <main+0x64>
jmp    11f1 <main+0xb1>
mov    -0x10(%rbp),%rdi
call   1030 <check_prime@plt>
cmp    $0x0,%rax
je     11e0 <main+0xa0>
movabs $0x576f7632bc7,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
cmp    $0x0,%rdx
jne    11db <main+0x9b>
movq   $0x0,-0x18(%rbp)
jmp    11e0 <main+0xa0>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1179 <main+0x39>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
movq   %rax,%xmm0
movaps 0xdfb(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xdff(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
lea    0xdf9(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d9d(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xddc(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
movabs $0x576f7632bc7,%rdi
call   1060 <sqrt@plt>
mov    %rax,%rbx
add    $0x1,%rax
cmp    $0x2,%rax
jb     11cb <main+0x8b>
movabs $0x576f7632bc7,%r15
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbx),%r12
mov    %r12,%rdi
call   1030 <check_prime@plt>
test   %rax,%rax
je     11b0 <main+0x70>
mov    %r15,%rax
xor    %edx,%edx
div    %r12
xor    %ecx,%ecx
test   %rdx,%rdx
setne  %cl
jmp    11b5 <main+0x75>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%ecx
lea    -0x1(%rbx),%rax
test   %rcx,%rcx
je     11c7 <main+0x87>
cmp    $0x1,%rbx
mov    %rax,%rbx
ja     1180 <main+0x40>
add    $0x1,%rax
add    $0x1,%rax
movq   %rax,%xmm1
punpckldq 0xe24(%rip),%xmm1
subpd  0xe2c(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
lea    0xe29(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2dd3(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe1c(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"\0ALargest Prime Factor is %u\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [4 x i8] c"\0A%g\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca double
store i32 0, i32* %1
store i64 1, i64* %3
%7 = call i64 (...) @clock()
store i64 %7, i64* %4
%8 = call i64 @sqrt(i64 6008514751431)
%9 = add i64 %8, 1
store i64 %9, i64* %2
br label %10
10: ; preds = %28, %0
%11 = load i64, i64* %2
%12 = icmp ugt i64 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i64, i64* %3
%15 = icmp ne i64 %14, 0
br label %16
16: ; preds = %13, %10
%17 = phi i1 [ false, %10 ], [ %15, %13 ]
br i1 %17, label %18, label %31
18: ; preds = %16
%19 = load i64, i64* %2
%20 = call i64 @check_prime(i64 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i64, i64* %2
%24 = urem i64 6008514751431, %23
%25 = icmp ne i64 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %22
store i64 0, i64* %3
br label %27
27: ; preds = %26, %22
br label %28
28: ; preds = %27, %18
%29 = load i64, i64* %2
%30 = add i64 %29, -1
store i64 %30, i64* %2
br label %10
31: ; preds = %16
%32 = load i64, i64* %2
%33 = add i64 %32, 1
%34 = uitofp i64 %33 to double
%35 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), double %34)
%36 = call i64 (...) @clock()
store i64 %36, i64* %5
%37 = load i64, i64* %5
%38 = load i64, i64* %4
%39 = sub nsw i64 %37, %38
%40 = sitofp i64 %39 to double
%41 = load double, double* @CLOCKS_PER_SEC
%42 = fdiv double %40, %41
store double %42, double* %6
%43 = load double, double* %6
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"\0ALargest Prime Factor is %u\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [4 x i8] c"\0A%g\00"
define i32 @main() {
%1 = tail call i64 (...) @clock()
%2 = tail call i64 @sqrt(i64 6008514751431)
%3 = add i64 %2, 1
%4 = icmp ugt i64 %3, 1
br i1 %4, label %5, label %19
5: ; preds = %0, %13
%6 = phi i64 [ %15, %13 ], [ %3, %0 ]
%7 = tail call i64 @check_prime(i64 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = urem i64 6008514751431, %6
%11 = icmp ne i64 %10, 0
%12 = zext i1 %11 to i64
br label %13
13: ; preds = %9, %5
%14 = phi i64 [ 1, %5 ], [ %12, %9 ]
%15 = add i64 %6, -1
%16 = icmp ugt i64 %15, 1
%17 = icmp ne i64 %14, 0
%18 = and i1 %17, %16
br i1 %18, label %5, label %19
19: ; preds = %13, %0
%20 = phi i64 [ %3, %0 ], [ %15, %13 ]
%21 = add i64 %20, 1
%22 = uitofp i64 %21 to double
%23 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), double %22)
%24 = tail call i64 (...) @clock()
%25 = sub nsw i64 %24, %1
%26 = sitofp i64 %25 to double
%27 = load double, double* @CLOCKS_PER_SEC
%28 = fdiv double %26, %27
%29 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %28)
ret i32 0
}