#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 *EratosthenesSieve(unsigned int);
unsigned int floor(int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ sqrt(unsigned long long);
int main() {
  unsigned long long num = 600851475143uLL;
  unsigned int divisor_limit = 0, max_factor = 0;
  unsigned int i = 0;
  int *sieve;
  divisor_limit = floor(sqrt(num));
  sieve = EratosthenesSieve(divisor_limit);
  while (num != 1) {
    for (i = 0; i < (divisor_limit - 2); i++) {
      if (sieve[i] == 1 && num % (i + 2) == 0) {
        if (max_factor <= i + 2) {
          max_factor = i + 2;
        }
        num /= i + 2;
        break;
      }
    }
  }
  free(sieve);
  sieve = NULL;
  printf("%d", max_factor);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movabs $0x8be589eac7,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1070 <floor@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <EratosthenesSieve@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x1,-0x10(%rbp)
je     123e <main+0xee>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jae    1239 <main+0xe9>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
cmpl   $0x1,(%rax,%rcx,4)
jne    1226 <main+0xd6>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    1226 <main+0xd6>
mov    -0x18(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
ja     120a <main+0xba>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,%eax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
jmp    1239 <main+0xe9>
jmp    122b <main+0xdb>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b3 <main+0x63>
jmp    11a1 <main+0x51>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%esi
lea    0xda7(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
movabs $0x8be589eac7,%rbx
mov    %rbx,%rdi
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1070 <floor@plt>
mov    %eax,%r14d
mov    %eax,%edi
call   1050 <EratosthenesSieve@plt>
mov    %rax,%r9
add    $0xfffffffe,%r14d
xor    %r15d,%r15d
jmp    1196 <main+0x46>
mov    %ebx,%eax
xor    %edx,%edx
div    %r8d
mov    %eax,%ebx
nopl   (%rax)
cmp    $0x1,%rbx
je     1200 <main+0xb0>
test   %r14,%r14
je     1190 <main+0x40>
xor    %ecx,%ecx
jmp    11b0 <main+0x60>
nop
mov    %rbx,%rax
xor    %edx,%edx
div    %rdi
test   %rdx,%rdx
jne    11d0 <main+0x80>
jmp    11e0 <main+0x90>
nop
cmpl   $0x1,(%r9,%rcx,4)
jne    11d0 <main+0x80>
lea    0x2(%rcx),%edi
mov    %rbx,%rsi
shr    $0x20,%rsi
jne    11a0 <main+0x50>
mov    %ebx,%eax
xor    %edx,%edx
div    %edi
test   %rdx,%rdx
je     11e0 <main+0x90>
xchg   %ax,%ax
add    $0x1,%rcx
cmp    %rcx,%r14
jne    11b0 <main+0x60>
jmp    1190 <main+0x40>
nopl   0x0(%rax,%rax,1)
add    $0x2,%rcx
mov    %ecx,%r8d
cmp    %ecx,%r15d
cmovbe %ecx,%r15d
test   %rsi,%rsi
je     1184 <main+0x34>
mov    %rbx,%rax
xor    %edx,%edx
div    %r8
mov    %rax,%rbx
jmp    1190 <main+0x40>
mov    %r9,%rdi
call   1030 <free@plt>
lea    0xdf1(%rip),%rdi
mov    %r15d,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32 0, i32* %1
store i64 600851475143, i64* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%7 = load i64, i64* %2
%8 = call i32 @sqrt(i64 %7)
%9 = call i32 @floor(i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = call i32* @EratosthenesSieve(i32 %10)
store i32* %11, i32** %6
br label %12
12: ; preds = %53, %0
%13 = load i64, i64* %2
%14 = icmp ne i64 %13, 1
br i1 %14, label %15, label %54
15: ; preds = %12
store i32 0, i32* %5
br label %16
16: ; preds = %50, %15
%17 = load i32, i32* %5
%18 = load i32, i32* %3
%19 = sub i32 %18, 2
%20 = icmp ult i32 %17, %19
br i1 %20, label %21, label %53
21: ; preds = %16
%22 = load i32*, i32** %6
%23 = load i32, i32* %5
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %49
28: ; preds = %21
%29 = load i64, i64* %2
%30 = load i32, i32* %5
%31 = add i32 %30, 2
%32 = zext i32 %31 to i64
%33 = urem i64 %29, %32
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %49
35: ; preds = %28
%36 = load i32, i32* %4
%37 = load i32, i32* %5
%38 = add i32 %37, 2
%39 = icmp ule i32 %36, %38
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i32, i32* %5
%42 = add i32 %41, 2
store i32 %42, i32* %4
br label %43
43: ; preds = %40, %35
%44 = load i32, i32* %5
%45 = add i32 %44, 2
%46 = zext i32 %45 to i64
%47 = load i64, i64* %2
%48 = udiv i64 %47, %46
store i64 %48, i64* %2
br label %53
49: ; preds = %28, %21
br label %50
50: ; preds = %49
%51 = load i32, i32* %5
%52 = add i32 %51, 1
store i32 %52, i32* %5
br label %16
53: ; preds = %43, %16
br label %12
54: ; preds = %12
%55 = load i32*, i32** %6
%56 = call i32 @free(i32* %55)
store i32* null, i32** %6
%57 = load i32, i32* %4
%58 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %57)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = tail call i32 @sqrt(i64 600851475143)
%2 = tail call i32 @floor(i32 %1)
%3 = tail call i32* @EratosthenesSieve(i32 %2)
%4 = add i32 %2, -2
%5 = icmp eq i32 %4, 0
%6 = zext i32 %4 to i64
br label %7
7: ; preds = %0, %29
%8 = phi i32 [ 0, %0 ], [ %31, %29 ]
%9 = phi i64 [ 600851475143, %0 ], [ %30, %29 ]
br i1 %5, label %29, label %10
10: ; preds = %7, %26
%11 = phi i64 [ %27, %26 ], [ 0, %7 ]
%12 = getelementptr inbounds i32, i32* %3, i64 %11
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %26
15: ; preds = %10
%16 = trunc i64 %11 to i32
%17 = add i32 %16, 2
%18 = zext i32 %17 to i64
%19 = urem i64 %9, %18
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = zext i32 %17 to i64
%23 = icmp ugt i32 %8, %17
%24 = select i1 %23, i32 %8, i32 %17
%25 = udiv i64 %9, %22
br label %29
26: ; preds = %10, %15
%27 = add nuw nsw i64 %11, 1
%28 = icmp eq i64 %27, %6
br i1 %28, label %29, label %10
29: ; preds = %26, %7, %21
%30 = phi i64 [ %25, %21 ], [ %9, %7 ], [ %9, %26 ]
%31 = phi i32 [ %24, %21 ], [ %8, %7 ], [ %8, %26 ]
%32 = icmp eq i64 %30, 1
br i1 %32, label %33, label %7
33: ; preds = %29
%34 = tail call i32 @free(i32* %3)
%35 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %31)
ret i32 0
}