#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*/ free_prime();
int /*<<< orphan*/ generate_sieve(unsigned long);
scalar_t__ is_composite(unsigned long);
int /*<<< orphan*/ printf(char *, unsigned long long, unsigned long);
unsigned long sqrt(unsigned long long);
void p003() {
  unsigned long long number = 600851475143;
  unsigned long number_index = sqrt(number);
  generate_sieve(number_index);
  while (is_composite(number_index) || number % number_index > 0) {
    number_index--;
  }
  free_prime();
  printf("Largest prime factor of %llu is %lu.", number, number_index);
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movabs $0x8be589eac7,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <sqrt@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <generate_sieve@plt>
mov    -0x10(%rbp),%rdi
call   1060 <is_composite@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
jne    11ad <p003+0x5d>
mov    -0x8(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
cmp    $0x0,%rdx
seta   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11bd <p003+0x6d>
jmp    11ce <p003+0x7e>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    117c <p003+0x2c>
mov    $0x0,%al
call   1030 <free_prime@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe1c(%rip),%rdi
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %r14
push   %rbx
push   %rax
movabs $0x8be589eac7,%r14
mov    %r14,%rdi
call   1070 <sqrt@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <generate_sieve@plt>
jmp    1184 <p003+0x34>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffffffffffff,%rbx
mov    %rbx,%rdi
call   1060 <is_composite@plt>
test   %rax,%rax
jne    1180 <p003+0x30>
mov    %r14,%rax
xor    %edx,%edx
div    %rbx
test   %rdx,%rdx
jne    1180 <p003+0x30>
xor    %eax,%eax
call   1030 <free_prime@plt>
lea    0xe54(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"Largest prime factor of %llu is %lu.\00"
define void @p003() {
%1 = alloca i64
%2 = alloca i64
store i64 600851475143, i64* %1
%3 = load i64, i64* %1
%4 = call i64 @sqrt(i64 %3)
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = call i32 @generate_sieve(i64 %5)
br label %7
7: ; preds = %18, %0
%8 = load i64, i64* %2
%9 = call i64 @is_composite(i64 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = load i64, i64* %1
%13 = load i64, i64* %2
%14 = urem i64 %12, %13
%15 = icmp ugt i64 %14, 0
br label %16
16: ; preds = %11, %7
%17 = phi i1 [ true, %7 ], [ %15, %11 ]
br i1 %17, label %18, label %21
18: ; preds = %16
%19 = load i64, i64* %2
%20 = add i64 %19, -1
store i64 %20, i64* %2
br label %7
21: ; preds = %16
%22 = call i32 (...) @free_prime()
%23 = load i64, i64* %1
%24 = load i64, i64* %2
%25 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %23, i64 %24)
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"Largest prime factor of %llu is %lu.\00"
define void @p003() {
%1 = tail call i64 @sqrt(i64 600851475143)
%2 = tail call i32 @generate_sieve(i64 %1)
br label %3
3: ; preds = %10, %0
%4 = phi i64 [ %1, %0 ], [ %11, %10 ]
%5 = tail call i64 @is_composite(i64 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = urem i64 600851475143, %4
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %3, %7
%11 = add i64 %4, -1
br label %3
12: ; preds = %7
%13 = tail call i32 (...) @free_prime()
%14 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 600851475143, i64 %4)
ret void
}