#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);
scalar_t__ sqrt(long);
int main() {
  long n = 600851475143;
  int lastFactor, factor, maxFactor;
  if (n % 2 == 0) {
    lastFactor = 2;
    n /= 2;
    while (n % 2 == 0)
      n /= 2;
  } else
    lastFactor = 1;
  factor = 3;
  maxFactor = (int)sqrt(n);
  while ((n > 1) && (factor <= maxFactor)) {
    if (n % factor == 0) {
      n /= factor;
      lastFactor = factor;
      while (n % factor == 0)
        n /= factor;
      maxFactor = (int)sqrt(n);
    }
    factor += 2;
  }
  if (n == 1)
    printf("%d\n", lastFactor);
  else
    printf("%d\n", n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movabs $0x8be589eac7,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11a2 <main+0x82>
movl   $0x2,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    119d <main+0x7d>
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
jmp    116e <main+0x4e>
jmp    11a9 <main+0x89>
movl   $0x1,-0x14(%rbp)
movl   $0x3,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sqrt@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpq   $0x1,-0x10(%rbp)
mov    %al,-0x1d(%rbp)
jle    11d8 <main+0xb8>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setle  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11e8 <main+0xc8>
jmp    125d <main+0x13d>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    124f <main+0x12f>
movslq -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1243 <main+0x123>
movslq -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
jmp    1216 <main+0xf6>
mov    -0x10(%rbp),%rdi
call   1040 <sqrt@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    11bc <main+0x9c>
cmpq   $0x1,-0x10(%rbp)
jne    127d <main+0x15d>
movslq -0x14(%rbp),%rsi
lea    0xd8d(%rip),%rdi
call   1030 <printf@plt>
jmp    128d <main+0x16d>
mov    -0x10(%rbp),%rsi
lea    0xd78(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
movabs $0x8be589eac7,%r14
mov    %r14,%rdi
call   1040 <sqrt@plt>
mov    %rax,%rcx
cmp    $0x3,%ecx
jl     120c <main+0xec>
mov    $0x1,%esi
mov    $0x3,%ebx
nopl   0x0(%rax)
mov    %r14,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     1180 <main+0x60>
mov    %r14,%rax
xor    %edx,%edx
div    %rbx
test   %rdx,%rdx
je     119d <main+0x7d>
cmp    $0x2,%r14
jge    11f5 <main+0xd5>
jmp    1201 <main+0xe1>
nopl   0x0(%rax,%rax,1)
mov    %r14d,%eax
xor    %edx,%edx
div    %ebx
test   %rdx,%rdx
jne    1169 <main+0x49>
jmp    119d <main+0x7d>
xchg   %ax,%ax
mov    %r14,%rax
cqto
idiv   %rbx
test   %rdx,%rdx
jne    11e2 <main+0xc2>
mov    %r14,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     11c0 <main+0xa0>
mov    %r14,%rax
cqto
idiv   %rbx
mov    %rax,%r14
jmp    11ca <main+0xaa>
cs nopw 0x0(%rax,%rax,1)
mov    %r14d,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%r14d
mov    %r14,%rax
or     %rbx,%rax
shr    $0x20,%rax
jne    1190 <main+0x70>
mov    %r14d,%eax
xor    %edx,%edx
div    %ebx
test   %rdx,%rdx
je     119d <main+0x7d>
mov    %r14,%rdi
call   1040 <sqrt@plt>
mov    %rax,%rcx
mov    %ebx,%esi
cmp    $0x2,%r14
jl     1201 <main+0xe1>
add    $0x2,%rbx
cmp    %ebx,%ecx
jge    1150 <main+0x30>
cmp    $0x1,%r14
movslq %esi,%rax
cmove  %rax,%r14
lea    0xded(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i64 600851475143, i64* %2
%6 = load i64, i64* %2
%7 = srem i64 %6, 2
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %0
store i32 2, i32* %3
%10 = load i64, i64* %2
%11 = sdiv i64 %10, 2
store i64 %11, i64* %2
br label %12
12: ; preds = %16, %9
%13 = load i64, i64* %2
%14 = srem i64 %13, 2
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i64, i64* %2
%18 = sdiv i64 %17, 2
store i64 %18, i64* %2
br label %12
19: ; preds = %12
br label %21
20: ; preds = %0
store i32 1, i32* %3
br label %21
21: ; preds = %20, %19
store i32 3, i32* %4
%22 = load i64, i64* %2
%23 = call i64 @sqrt(i64 %22)
%24 = trunc i64 %23 to i32
store i32 %24, i32* %5
br label %25
25: ; preds = %61, %21
%26 = load i64, i64* %2
%27 = icmp sgt i64 %26, 1
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = icmp sle i32 %29, %30
br label %32
32: ; preds = %28, %25
%33 = phi i1 [ false, %25 ], [ %31, %28 ]
br i1 %33, label %34, label %64
34: ; preds = %32
%35 = load i64, i64* %2
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = srem i64 %35, %37
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %61
40: ; preds = %34
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = load i64, i64* %2
%44 = sdiv i64 %43, %42
store i64 %44, i64* %2
%45 = load i32, i32* %4
store i32 %45, i32* %3
br label %46
46: ; preds = %52, %40
%47 = load i64, i64* %2
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = srem i64 %47, %49
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %46
%53 = load i32, i32* %4
%54 = sext i32 %53 to i64
%55 = load i64, i64* %2
%56 = sdiv i64 %55, %54
store i64 %56, i64* %2
br label %46
57: ; preds = %46
%58 = load i64, i64* %2
%59 = call i64 @sqrt(i64 %58)
%60 = trunc i64 %59 to i32
store i32 %60, i32* %5
br label %61
61: ; preds = %57, %34
%62 = load i32, i32* %4
%63 = add nsw i32 %62, 2
store i32 %63, i32* %4
br label %25
64: ; preds = %32
%65 = load i64, i64* %2
%66 = icmp eq i64 %65, 1
br i1 %66, label %67, label %71
67: ; preds = %64
%68 = load i32, i32* %3
%69 = sext i32 %68 to i64
%70 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %69)
br label %74
71: ; preds = %64
%72 = load i64, i64* %2
%73 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %72)
br label %74
74: ; preds = %71, %67
ret i32 0
}

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