#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__ sqrt(long);
long largestPrime(long num) {
  for (long i = 2; i < (long)sqrt(num) + 1; i++) {
    if (num % i == 0) {
      return largestPrime(num / i);
    }
  }
  return num;
}


x86 assembly (clang, -O0):
<largestPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sqrt@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
add    $0x1,%rcx
cmp    %rcx,%rax
jge    119e <largestPrime+0x7e>
mov    -0x10(%rbp),%rax
cqto
idivq  -0x18(%rbp)
cmp    $0x0,%rdx
jne    1188 <largestPrime+0x68>
mov    -0x10(%rbp),%rax
cqto
idivq  -0x18(%rbp)
mov    %rax,%rdi
call   1030 <largestPrime@plt>
mov    %rax,-0x8(%rbp)
jmp    11a6 <largestPrime+0x86>
jmp    118d <largestPrime+0x6d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1134 <largestPrime+0x14>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<largestPrime>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1030 <sqrt@plt>
cmp    $0x2,%rax
jge    1130 <largestPrime+0x20>
mov    %r15,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
nop
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     1160 <largestPrime+0x50>
mov    %r15,%rax
cqto
idiv   %rbx
mov    %rax,%r14
test   %rdx,%rdx
jne    116f <largestPrime+0x5f>
jmp    1190 <largestPrime+0x80>
xchg   %ax,%ax
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%r14d
test   %rdx,%rdx
je     1190 <largestPrime+0x80>
lea    0x1(%rbx),%r14
mov    %r15,%rdi
call   1030 <sqrt@plt>
cmp    %rax,%rbx
mov    %r14,%rbx
jl     1140 <largestPrime+0x30>
jmp    1123 <largestPrime+0x13>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1030 <sqrt@plt>
mov    %r14,%r15
cmp    $0x2,%rax
jge    1130 <largestPrime+0x20>
jmp    1126 <largestPrime+0x16>

LLVM IR (-O0):
define i64 @largestPrime(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
store i64 2, i64* %4
br label %5
5: ; preds = %22, %1
%6 = load i64, i64* %4
%7 = load i64, i64* %3
%8 = call i64 @sqrt(i64 %7)
%9 = add nsw i64 %8, 1
%10 = icmp slt i64 %6, %9
br i1 %10, label %11, label %25
11: ; preds = %5
%12 = load i64, i64* %3
%13 = load i64, i64* %4
%14 = srem i64 %12, %13
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i64, i64* %3
%18 = load i64, i64* %4
%19 = sdiv i64 %17, %18
%20 = call i64 @largestPrime(i64 %19)
store i64 %20, i64* %2
br label %27
21: ; preds = %11
br label %22
22: ; preds = %21
%23 = load i64, i64* %4
%24 = add nsw i64 %23, 1
store i64 %24, i64* %4
br label %5
25: ; preds = %5
%26 = load i64, i64* %3
store i64 %26, i64* %2
br label %27
27: ; preds = %25, %16
%28 = load i64, i64* %2
ret i64 %28
}

LLVM IR (-O2):
define i64 @largestPrime(i64 %0) {
%2 = tail call i64 @sqrt(i64 %0)
%3 = icmp slt i64 %2, 2
br i1 %3, label %18, label %4
4: ; preds = %1, %11
%5 = phi i64 [ %9, %11 ], [ %0, %1 ]
br label %6
6: ; preds = %4, %14
%7 = phi i64 [ 2, %4 ], [ %15, %14 ]
%8 = srem i64 %5, %7
%9 = sdiv i64 %5, %7
%10 = icmp eq i64 %8, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = tail call i64 @sqrt(i64 %9)
%13 = icmp slt i64 %12, 2
br i1 %13, label %18, label %4
14: ; preds = %6
%15 = add nuw nsw i64 %7, 1
%16 = tail call i64 @sqrt(i64 %5)
%17 = icmp slt i64 %7, %16
br i1 %17, label %6, label %18
18: ; preds = %11, %14, %1
%19 = phi i64 [ %0, %1 ], [ %5, %14 ], [ %9, %11 ]
ret i64 %19
}