#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__ isPrime(long);
int /*<<< orphan*/ printf(char *, long);
long sqrt(long const);
void main() {
  const long NUMBER = 600851475143;
  long largestPrimeFactor = 0;
  long i;
  for (i = 2; i < sqrt(NUMBER); i++) {
    if (NUMBER % i == 0 && isPrime(i) == 0) {
      largestPrimeFactor = i;
    }
  }
  printf("%d\n", largestPrimeFactor);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movabs $0x8be589eac7,%rax
mov    %rax,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movabs $0x8be589eac7,%rdi
call   1050 <sqrt@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jge    11c8 <main+0x98>
movabs $0x8be589eac7,%rax
cqto
idivq  -0x18(%rbp)
cmp    $0x0,%rdx
jne    11b2 <main+0x82>
mov    -0x18(%rbp),%rdi
call   1040 <isPrime@plt>
cmp    $0x0,%rax
jne    11b2 <main+0x82>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11b7 <main+0x87>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1156 <main+0x26>
mov    -0x10(%rbp),%rsi
lea    0xe2d(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movabs $0x8be589eac7,%r14
mov    %r14,%rdi
call   1050 <sqrt@plt>
cmp    $0x3,%rax
jl     119f <main+0x6f>
mov    $0x2,%ebx
xor    %r15d,%r15d
movabs $0x8be589eac7,%r12
jmp    1181 <main+0x51>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <sqrt@plt>
cmp    %rax,%rbx
jge    11a2 <main+0x72>
mov    %r12,%rax
xor    %edx,%edx
div    %rbx
test   %rdx,%rdx
jne    1170 <main+0x40>
mov    %rbx,%rdi
call   1040 <isPrime@plt>
test   %rax,%rax
cmove  %rbx,%r15
jmp    1170 <main+0x40>
xor    %r15d,%r15d
lea    0xe57(%rip),%rdi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define void @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
store i64 600851475143, i64* %1
store i64 0, i64* %2
store i64 2, i64* %3
br label %4
4: ; preds = %19, %0
%5 = load i64, i64* %3
%6 = call i64 @sqrt(i64 600851475143)
%7 = icmp slt i64 %5, %6
br i1 %7, label %8, label %22
8: ; preds = %4
%9 = load i64, i64* %3
%10 = srem i64 600851475143, %9
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %8
%13 = load i64, i64* %3
%14 = call i64 @isPrime(i64 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load i64, i64* %3
store i64 %17, i64* %2
br label %18
18: ; preds = %16, %12, %8
br label %19
19: ; preds = %18
%20 = load i64, i64* %3
%21 = add nsw i64 %20, 1
store i64 %21, i64* %3
br label %4
22: ; preds = %4
%23 = load i64, i64* %2
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %23)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define void @main() {
%1 = tail call i64 @sqrt(i64 600851475143)
%2 = icmp sgt i64 %1, 2
br i1 %2, label %3, label %17
3: ; preds = %0, %12
%4 = phi i64 [ %14, %12 ], [ 2, %0 ]
%5 = phi i64 [ %13, %12 ], [ 0, %0 ]
%6 = urem i64 600851475143, %4
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = tail call i64 @isPrime(i64 %4)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i64 %4, i64 %5
br label %12
12: ; preds = %8, %3
%13 = phi i64 [ %5, %3 ], [ %11, %8 ]
%14 = add nuw nsw i64 %4, 1
%15 = tail call i64 @sqrt(i64 600851475143)
%16 = icmp slt i64 %14, %15
br i1 %16, label %3, label %17
17: ; preds = %12, %0
%18 = phi i64 [ 0, %0 ], [ %13, %12 ]
%19 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %18)
ret void
}