#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 *, long, ...);
long sqrt(long);
long find_max_prime_factor(long value) {
  long largest_prime_factor = value;
  long divider = 2;
  while (value % divider == 0) {
    printf("value: %lu divider: %lu\n", value, divider);
    value = value / divider;
    largest_prime_factor = divider;
  }
  divider++;
  for (; divider <= sqrt(value); divider = divider + 2) {
    printf("Checkking divider: %lu\n", divider);
    while (value % divider == 0) {
      printf("value: %lu divider: %lu\n", value, divider);
      value = value / divider;
      largest_prime_factor = divider;
    }
  }
  if (value > 2)
    largest_prime_factor = value;
  return largest_prime_factor;
}


x86 assembly (clang, -O0):
<find_max_prime_factor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movq   $0x2,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cqto
idivq  -0x18(%rbp)
cmp    $0x0,%rdx
jne    1181 <find_max_prime_factor+0x61>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
cqto
idivq  -0x18(%rbp)
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    113c <find_max_prime_factor+0x1c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <sqrt@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jg     121b <find_max_prime_factor+0xfb>
mov    -0x18(%rbp),%rsi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
cqto
idivq  -0x18(%rbp)
cmp    $0x0,%rdx
jne    1205 <find_max_prime_factor+0xe5>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
cqto
idivq  -0x18(%rbp)
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11c0 <find_max_prime_factor+0xa0>
jmp    120a <find_max_prime_factor+0xea>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    118d <find_max_prime_factor+0x6d>
cmpq   $0x2,-0x8(%rbp)
jle    122e <find_max_prime_factor+0x10e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_max_prime_factor>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
test   $0x1,%r14b
jne    1176 <find_max_prime_factor+0x56>
lea    0xec7(%rip),%r15
mov    %r14,%rbx
mov    $0x2,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x2,%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
shr    $0x3f,%rbx
add    %r14,%rbx
sar    %rbx
mov    %rbx,%r14
test   $0x1,%bl
je     1150 <find_max_prime_factor+0x30>
jmp    117c <find_max_prime_factor+0x5c>
mov    %r14,%rbx
mov    %r14,%r13
mov    %rbx,%rdi
call   1040 <sqrt@plt>
cmp    $0x3,%rax
jge    119f <find_max_prime_factor+0x7f>
cmp    $0x3,%rbx
cmovge %rbx,%r13
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    $0x3,%r14d
lea    0xe6d(%rip),%r15
lea    0xe4d(%rip),%r12
jmp    11d4 <find_max_prime_factor+0xb4>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%r13
add    $0x2,%r14
mov    %rbx,%rdi
call   1040 <sqrt@plt>
cmp    %rax,%r14
jg     118a <find_max_prime_factor+0x6a>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rax
or     %r14,%rax
shr    $0x20,%rax
je     1200 <find_max_prime_factor+0xe0>
mov    %rbx,%rax
cqto
idiv   %r14
test   %rdx,%rdx
jne    11c3 <find_max_prime_factor+0xa3>
jmp    121d <find_max_prime_factor+0xfd>
nopl   0x0(%rax)
mov    %ebx,%eax
xor    %edx,%edx
div    %r14d
test   %rdx,%rdx
jne    11c3 <find_max_prime_factor+0xa3>
jmp    121d <find_max_prime_factor+0xfd>
xchg   %ax,%ax
mov    %rbx,%rax
cqto
idiv   %r14
test   %rdx,%rdx
jne    11c0 <find_max_prime_factor+0xa0>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rax
or     %r14,%rax
shr    $0x20,%rax
je     1250 <find_max_prime_factor+0x130>
mov    %rbx,%rax
cqto
idiv   %r14
mov    %rax,%rbx
jmp    1259 <find_max_prime_factor+0x139>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %r14d
mov    %eax,%ebx
mov    %rbx,%rax
or     %r14,%rax
shr    $0x20,%rax
jne    1210 <find_max_prime_factor+0xf0>
mov    %ebx,%eax
xor    %edx,%edx
div    %r14d
test   %rdx,%rdx
je     121d <find_max_prime_factor+0xfd>
jmp    11c0 <find_max_prime_factor+0xa0>

LLVM IR (-O0):
@.str = [25 x i8] c"value: %lu divider: %lu\0A\00"
@.str.1 = [24 x i8] c"Checkking divider: %lu\0A\00"
define i64 @find_max_prime_factor(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %2
%5 = load i64, i64* %2
store i64 %5, i64* %3
store i64 2, i64* %4
br label %6
6: ; preds = %11, %1
%7 = load i64, i64* %2
%8 = load i64, i64* %4
%9 = srem i64 %7, %8
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %6
%12 = load i64, i64* %2
%13 = load i64, i64* %4
%14 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %12, i64 %13)
%15 = load i64, i64* %2
%16 = load i64, i64* %4
%17 = sdiv i64 %15, %16
store i64 %17, i64* %2
%18 = load i64, i64* %4
store i64 %18, i64* %3
br label %6
19: ; preds = %6
%20 = load i64, i64* %4
%21 = add nsw i64 %20, 1
store i64 %21, i64* %4
br label %22
22: ; preds = %44, %19
%23 = load i64, i64* %4
%24 = load i64, i64* %2
%25 = call i64 @sqrt(i64 %24)
%26 = icmp sle i64 %23, %25
br i1 %26, label %27, label %47
27: ; preds = %22
%28 = load i64, i64* %4
%29 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %28)
br label %30
30: ; preds = %35, %27
%31 = load i64, i64* %2
%32 = load i64, i64* %4
%33 = srem i64 %31, %32
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %43
35: ; preds = %30
%36 = load i64, i64* %2
%37 = load i64, i64* %4
%38 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %36, i64 %37)
%39 = load i64, i64* %2
%40 = load i64, i64* %4
%41 = sdiv i64 %39, %40
store i64 %41, i64* %2
%42 = load i64, i64* %4
store i64 %42, i64* %3
br label %30
43: ; preds = %30
br label %44
44: ; preds = %43
%45 = load i64, i64* %4
%46 = add nsw i64 %45, 2
store i64 %46, i64* %4
br label %22
47: ; preds = %22
%48 = load i64, i64* %2
%49 = icmp sgt i64 %48, 2
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = load i64, i64* %2
store i64 %51, i64* %3
br label %52
52: ; preds = %50, %47
%53 = load i64, i64* %3
ret i64 %53
}

LLVM IR (-O2):
@.str = [25 x i8] c"value: %lu divider: %lu\0A\00"
@.str.1 = [24 x i8] c"Checkking divider: %lu\0A\00"
define i64 @find_max_prime_factor(i64 %0) {
%2 = and i64 %0, 1
%3 = icmp eq i64 %2, 0
br i1 %3, label %9, label %4
4: ; preds = %9, %1
%5 = phi i64 [ %0, %1 ], [ %12, %9 ]
%6 = phi i64 [ %0, %1 ], [ 2, %9 ]
%7 = tail call i64 @sqrt(i64 %5)
%8 = icmp slt i64 %7, 3
br i1 %8, label %34, label %15
9: ; preds = %1, %9
%10 = phi i64 [ %12, %9 ], [ %0, %1 ]
%11 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %10, i64 2)
%12 = sdiv i64 %10, 2
%13 = and i64 %12, 1
%14 = icmp eq i64 %13, 0
br i1 %14, label %9, label %4
15: ; preds = %4, %28
%16 = phi i64 [ %31, %28 ], [ 3, %4 ]
%17 = phi i64 [ %30, %28 ], [ %6, %4 ]
%18 = phi i64 [ %29, %28 ], [ %5, %4 ]
%19 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %16)
%20 = srem i64 %18, %16
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %15, %22
%23 = phi i64 [ %25, %22 ], [ %18, %15 ]
%24 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %23, i64 %16)
%25 = sdiv i64 %23, %16
%26 = srem i64 %25, %16
%27 = icmp eq i64 %26, 0
br i1 %27, label %22, label %28
28: ; preds = %22, %15
%29 = phi i64 [ %18, %15 ], [ %25, %22 ]
%30 = phi i64 [ %17, %15 ], [ %16, %22 ]
%31 = add nuw nsw i64 %16, 2
%32 = tail call i64 @sqrt(i64 %29)
%33 = icmp sgt i64 %31, %32
br i1 %33, label %34, label %15
34: ; preds = %28, %4
%35 = phi i64 [ %5, %4 ], [ %29, %28 ]
%36 = phi i64 [ %6, %4 ], [ %30, %28 ]
%37 = icmp sgt i64 %35, 2
%38 = select i1 %37, i64 %35, i64 %36
ret i64 %38
}