#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(long);
long max_prime_factor(long n) {
  long i, p = 0;
  if (n % 2 == 0)
    p = 2;
  for (i = 3; i * i < n; i += 2)
    if (n % i == 0 && is_prime(i))
      p = i;
  return p;
}


x86 assembly (clang, -O0):
<max_prime_factor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1144 <max_prime_factor+0x34>
movq   $0x2,-0x18(%rbp)
movq   $0x3,-0x10(%rbp)
mov    -0x10(%rbp),%rax
imul   -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    11a4 <max_prime_factor+0x94>
mov    -0x8(%rbp),%rax
cqto
idivq  -0x10(%rbp)
cmp    $0x0,%rdx
jne    118e <max_prime_factor+0x7e>
mov    -0x10(%rbp),%rdi
call   1030 <is_prime@plt>
cmp    $0x0,%rax
je     118e <max_prime_factor+0x7e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1193 <max_prime_factor+0x83>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    114c <max_prime_factor+0x3c>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<max_prime_factor>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    (%rdi,%rdi,1),%r14d
not    %r14d
and    $0x2,%r14d
cmp    $0xa,%rdi
jl     118e <max_prime_factor+0x7e>
mov    %rdi,%r15
mov    $0x5,%ebx
jmp    1150 <max_prime_factor+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rax
imul   %rbx,%rax
add    $0x2,%rbx
cmp    %r15,%rax
jge    118e <max_prime_factor+0x7e>
lea    -0x2(%rbx),%r12
mov    %r15,%rax
or     %r12,%rax
shr    $0x20,%rax
je     1170 <max_prime_factor+0x60>
mov    %r15,%rax
cqto
idiv   %r12
test   %rdx,%rdx
jne    1140 <max_prime_factor+0x30>
jmp    117d <max_prime_factor+0x6d>
nop
mov    %r15d,%eax
xor    %edx,%edx
div    %r12d
test   %rdx,%rdx
jne    1140 <max_prime_factor+0x30>
mov    %r12,%rdi
call   1030 <is_prime@plt>
test   %rax,%rax
cmovne %r12,%r14
jmp    1140 <max_prime_factor+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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