#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 */
int /*<<< orphan*/ printf(char *, double, ...);
double sqrtl(long);
long findLargestPrime(long value) {
  double MPP = sqrtl(value);
  long largestPrimeFound = 1;
  long nextPrimeToCheck = 2;
  long totalCalculation = 1;
  printf("Largest Possible Prime is %lg\n", MPP);
  while (!0) {
    if (value % nextPrimeToCheck == 0) {
      largestPrimeFound = largestPrimeFound < nextPrimeToCheck
                              ? nextPrimeToCheck
                              : largestPrimeFound;
      value /= nextPrimeToCheck;
      totalCalculation *= nextPrimeToCheck;
      printf("MPP=%lg : nextPrimeToCheck=%lu : largestPrimeFound=%lu : "
             "totalCalculation=%lu\n",
             MPP, nextPrimeToCheck, largestPrimeFound, totalCalculation);
      if (value == 1)
        return largestPrimeFound;
      nextPrimeToCheck = 2;
    } else
      nextPrimeToCheck += nextPrimeToCheck % 2 ? 2 : 1;
  }
  return -1;
}


x86 assembly (clang, -O0):
<findLargestPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <sqrtl@plt>
movsd  %xmm0,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
movq   $0x2,-0x20(%rbp)
movq   $0x1,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xea2(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
cqto
idivq  -0x20(%rbp)
cmp    $0x0,%rdx
jne    1203 <findLargestPrime+0xe3>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    1194 <findLargestPrime+0x74>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    119c <findLargestPrime+0x7c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rax
imul   -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe45(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
cmpq   $0x1,-0x8(%rbp)
jne    11f6 <findLargestPrime+0xd6>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret
movq   $0x2,-0x20(%rbp)
jmp    122c <findLargestPrime+0x10c>
mov    -0x20(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    $0x1,%eax
mov    $0x2,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
cltq
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1165 <findLargestPrime+0x45>

x86 assembly (clang, -O2):
<findLargestPrime>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1040 <sqrtl@plt>
lea    0xec4(%rip),%rdi
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x1,%r14d
lea    0xec9(%rip),%r15
mov    $0x1,%r12d
jmp    118a <findLargestPrime+0x6a>
xchg   %ax,%ax
cmp    %rsi,%r14
cmovl  %rsi,%r14
imul   %rsi,%r12
mov    %r15,%rdi
movsd  0x8(%rsp),%xmm0
mov    %r14,%rdx
mov    %r12,%rcx
mov    $0x1,%al
call   1030 <printf@plt>
mov    %r13,%rbx
cmp    $0x1,%r13
je     11d1 <findLargestPrime+0xb1>
mov    $0x2,%esi
nop
mov    %rbx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     11b0 <findLargestPrime+0x90>
mov    %rbx,%rax
cqto
idiv   %rsi
mov    %rax,%r13
test   %rdx,%rdx
jne    11be <findLargestPrime+0x9e>
jmp    1160 <findLargestPrime+0x40>
xchg   %ax,%ax
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
mov    %eax,%r13d
test   %rdx,%rdx
je     1160 <findLargestPrime+0x40>
mov    %esi,%eax
and    $0x1,%eax
cmp    $0x1,%rax
sbb    $0x0,%rsi
add    $0x2,%rsi
jmp    1190 <findLargestPrime+0x70>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Largest Possible Prime is %lg\0A\00"
@.str.1 = [79 x i8] c"MPP=%lg : nextPrimeToCheck=%lu : largestPrimeFound=%lu : totalCalculation=%lu\0A\00"
define i64 @findLargestPrime(i64 %0) {
%2 = alloca i64
%3 = alloca double
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %2
%7 = load i64, i64* %2
%8 = call double @sqrtl(i64 %7)
store double %8, double* %3
store i64 1, i64* %4
store i64 2, i64* %5
store i64 1, i64* %6
%9 = load double, double* %3
%10 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), double %9)
br label %11
11: ; preds = %1, %51
%12 = load i64, i64* %2
%13 = load i64, i64* %5
%14 = srem i64 %12, %13
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %42
16: ; preds = %11
%17 = load i64, i64* %4
%18 = load i64, i64* %5
%19 = icmp slt i64 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i64, i64* %5
br label %24
22: ; preds = %16
%23 = load i64, i64* %4
br label %24
24: ; preds = %22, %20
%25 = phi i64 [ %21, %20 ], [ %23, %22 ]
store i64 %25, i64* %4
%26 = load i64, i64* %5
%27 = load i64, i64* %2
%28 = sdiv i64 %27, %26
store i64 %28, i64* %2
%29 = load i64, i64* %5
%30 = load i64, i64* %6
%31 = mul nsw i64 %30, %29
store i64 %31, i64* %6
%32 = load double, double* %3
%33 = load i64, i64* %5
%34 = load i64, i64* %4
%35 = load i64, i64* %6
%36 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0), double %32, i64 %33, i64 %34, i64 %35)
%37 = load i64, i64* %2
%38 = icmp eq i64 %37, 1
br i1 %38, label %39, label %41
39: ; preds = %24
%40 = load i64, i64* %4
ret i64 %40
41: ; preds = %24
store i64 2, i64* %5
br label %51
42: ; preds = %11
%43 = load i64, i64* %5
%44 = srem i64 %43, 2
%45 = icmp ne i64 %44, 0
%46 = zext i1 %45 to i64
%47 = select i1 %45, i32 2, i32 1
%48 = sext i32 %47 to i64
%49 = load i64, i64* %5
%50 = add nsw i64 %49, %48
store i64 %50, i64* %5
br label %51
51: ; preds = %42, %41
br label %11
}

LLVM IR (-O2):
@.str = [31 x i8] c"Largest Possible Prime is %lg\0A\00"
@.str.1 = [79 x i8] c"MPP=%lg : nextPrimeToCheck=%lu : largestPrimeFound=%lu : totalCalculation=%lu\0A\00"
define i64 @findLargestPrime(i64 %0) {
%2 = tail call double @sqrtl(i64 %0)
%3 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), double %2)
br label %4
4: ; preds = %13, %1
%5 = phi i64 [ %11, %13 ], [ %0, %1 ]
%6 = phi i64 [ %15, %13 ], [ 1, %1 ]
%7 = phi i64 [ %16, %13 ], [ 1, %1 ]
br label %8
8: ; preds = %4, %20
%9 = phi i64 [ %24, %20 ], [ 2, %4 ]
%10 = srem i64 %5, %9
%11 = sdiv i64 %5, %9
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %20
13: ; preds = %8
%14 = icmp slt i64 %6, %9
%15 = select i1 %14, i64 %9, i64 %6
%16 = mul nsw i64 %7, %9
%17 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0), double %2, i64 %9, i64 %15, i64 %16)
%18 = icmp eq i64 %11, 1
br i1 %18, label %19, label %4
19: ; preds = %13
ret i64 %15
20: ; preds = %8
%21 = and i64 %9, 1
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, i64 1, i64 2
%24 = add nuw nsw i64 %23, %9
br label %8
}