#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 *, int);
int sqrt(long long);
void problem_003(void) {
  long long n = 600851475143;
  int factor = 2;
  int largest_prime_factor = 1;
  int largest_possible_factor = sqrt(n);
  while (n > 1 && factor < largest_possible_factor) {
    if (n % factor == 0) {
      largest_prime_factor = factor;
      n = n / factor;
      while (n % factor == 0) {
        n = n / factor;
      }
    }
    factor++;
  }
  printf("%i", largest_prime_factor);
  return;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movabs $0x8be589eac7,%rax
mov    %rax,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <sqrt@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpq   $0x1,-0x8(%rbp)
mov    %al,-0x15(%rbp)
jle    116c <problem_003+0x4c>
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    117c <problem_003+0x5c>
jmp    11ea <problem_003+0xca>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11dc <problem_003+0xbc>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cqto
idiv   %rcx
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11d7 <problem_003+0xb7>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cqto
idiv   %rcx
mov    %rax,-0x8(%rbp)
jmp    11aa <problem_003+0x8a>
jmp    11dc <problem_003+0xbc>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1150 <problem_003+0x30>
mov    -0x10(%rbp),%esi
lea    0xe0c(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbx
movabs $0x8be589eac7,%rbx
mov    %rbx,%rdi
call   1040 <sqrt@plt>
mov    $0x1,%esi
cmp    $0x3,%eax
jl     11f4 <problem_003+0xd4>
mov    %eax,%ecx
mov    $0x1,%esi
mov    $0x2,%edi
nopl   (%rax)
mov    %rbx,%rax
or     %rdi,%rax
shr    $0x20,%rax
je     1180 <problem_003+0x60>
mov    %rbx,%rax
xor    %edx,%edx
div    %rdi
test   %rdx,%rdx
je     119d <problem_003+0x7d>
cmp    $0x2,%rbx
jge    11e7 <problem_003+0xc7>
jmp    11f4 <problem_003+0xd4>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%eax
xor    %edx,%edx
div    %edi
test   %rdx,%rdx
jne    1169 <problem_003+0x49>
jmp    119d <problem_003+0x7d>
nopl   (%rax)
mov    %rbx,%rax
cqto
idiv   %rdi
test   %rdx,%rdx
jne    11df <problem_003+0xbf>
mov    %rbx,%rax
or     %rdi,%rax
shr    $0x20,%rax
je     11c0 <problem_003+0xa0>
mov    %rbx,%rax
cqto
idiv   %rdi
mov    %rax,%rbx
jmp    11c8 <problem_003+0xa8>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %edi
mov    %eax,%ebx
mov    %rbx,%rax
or     %rdi,%rax
shr    $0x20,%rax
jne    1190 <problem_003+0x70>
mov    %ebx,%eax
xor    %edx,%edx
div    %edi
test   %rdx,%rdx
je     119d <problem_003+0x7d>
mov    %edi,%esi
cmp    $0x2,%rbx
jl     11f4 <problem_003+0xd4>
add    $0x1,%rdi
cmp    %rcx,%rdi
jb     1150 <problem_003+0x30>
lea    0xe05(%rip),%rdi
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
define void @problem_003() {
%1 = alloca i64
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i64 600851475143, i64* %1
store i32 2, i32* %2
store i32 1, i32* %3
%5 = load i64, i64* %1
%6 = call i32 @sqrt(i64 %5)
store i32 %6, i32* %4
br label %7
7: ; preds = %40, %0
%8 = load i64, i64* %1
%9 = icmp sgt i64 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* %2
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br label %14
14: ; preds = %10, %7
%15 = phi i1 [ false, %7 ], [ %13, %10 ]
br i1 %15, label %16, label %43
16: ; preds = %14
%17 = load i64, i64* %1
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = srem i64 %17, %19
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %40
22: ; preds = %16
%23 = load i32, i32* %2
store i32 %23, i32* %3
%24 = load i64, i64* %1
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = sdiv i64 %24, %26
store i64 %27, i64* %1
br label %28
28: ; preds = %34, %22
%29 = load i64, i64* %1
%30 = load i32, i32* %2
%31 = sext i32 %30 to i64
%32 = srem i64 %29, %31
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %28
%35 = load i64, i64* %1
%36 = load i32, i32* %2
%37 = sext i32 %36 to i64
%38 = sdiv i64 %35, %37
store i64 %38, i64* %1
br label %28
39: ; preds = %28
br label %40
40: ; preds = %39, %16
%41 = load i32, i32* %2
%42 = add nsw i32 %41, 1
store i32 %42, i32* %2
br label %7
43: ; preds = %14
%44 = load i32, i32* %3
%45 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %44)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
define void @problem_003() {
%1 = tail call i32 @sqrt(i64 600851475143)
%2 = icmp sgt i32 %1, 2
br i1 %2, label %3, label %25
3: ; preds = %0
%4 = zext i32 %1 to i64
br label %5
5: ; preds = %3, %18
%6 = phi i64 [ 2, %3 ], [ %21, %18 ]
%7 = phi i64 [ 600851475143, %3 ], [ %20, %18 ]
%8 = phi i32 [ 1, %3 ], [ %19, %18 ]
%9 = urem i64 %7, %6
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %5, %11
%12 = phi i64 [ %13, %11 ], [ %7, %5 ]
%13 = sdiv i64 %12, %6
%14 = srem i64 %13, %6
%15 = icmp eq i64 %14, 0
br i1 %15, label %11, label %16
16: ; preds = %11
%17 = trunc i64 %6 to i32
br label %18
18: ; preds = %16, %5
%19 = phi i32 [ %8, %5 ], [ %17, %16 ]
%20 = phi i64 [ %7, %5 ], [ %13, %16 ]
%21 = add nuw nsw i64 %6, 1
%22 = icmp sgt i64 %20, 1
%23 = icmp ult i64 %21, %4
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %5, label %25
25: ; preds = %18, %0
%26 = phi i32 [ 1, %0 ], [ %19, %18 ]
%27 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %26)
ret void
}