#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);
int main() {
  long input, i, compound;
  long prime = -1;
  input = 600851475143;
  compound = input;
  for (i = 2; i < sqrt(input); i++) {
    if (compound % i == 0) {
      compound = compound / i;
      if (i > prime) {
        prime = i;
      }
      i = 2;
    }
  }
  printf("%ld\n", prime);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0xffffffffffffffff,-0x28(%rbp)
ff
movabs $0x8be589eac7,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sqrt@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jge    11cc <main+0xac>
mov    -0x20(%rbp),%rax
cqto
idivq  -0x18(%rbp)
cmp    $0x0,%rdx
jne    11b6 <main+0x96>
mov    -0x20(%rbp),%rax
cqto
idivq  -0x18(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jle    11ae <main+0x8e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x2,-0x18(%rbp)
jmp    11bb <main+0x9b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1155 <main+0x35>
mov    -0x28(%rbp),%rsi
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
movabs $0x8be589eac7,%r14
mov    %r14,%rdi
call   1040 <sqrt@plt>
mov    $0xffffffffffffffff,%r15
cmp    $0x3,%rax
jl     11a7 <main+0x87>
mov    $0x2,%ebx
mov    $0x2,%r13d
mov    %r14,%r12
jmp    1192 <main+0x72>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rax
cqto
idiv   %rbx
cmp    %r15,%rbx
mov    %r15,%rcx
cmovg  %rbx,%rcx
test   %rdx,%rdx
cmove  %r13,%rbx
cmove  %rax,%r12
cmove  %rcx,%r15
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <sqrt@plt>
cmp    %rax,%rbx
jge    11a7 <main+0x87>
mov    %r12,%rax
or     %rbx,%rax
shr    $0x20,%rax
jne    1160 <main+0x40>
mov    %r12d,%eax
xor    %edx,%edx
div    %ebx
jmp    1168 <main+0x48>
lea    0xe52(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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