#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);
int main() {
  long n = 600851475143, factor = 2;
  while (1) {
    if (n % factor == 0)
      n /= factor;
    else
      factor += 1;
    if (factor * factor > n) {
      factor = n;
      break;
    }
    if (n == 1)
      break;
  }
  printf("%d\n", factor);
  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)
movq   $0x2,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cqto
idivq  -0x18(%rbp)
cmp    $0x0,%rdx
jne    115f <main+0x4f>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
jmp    116b <main+0x5b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jle    118b <main+0x7b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11a0 <main+0x90>
cmpq   $0x1,-0x10(%rbp)
jne    119b <main+0x8b>
jmp    11a0 <main+0x90>
jmp    1135 <main+0x25>
mov    -0x18(%rbp),%rsi
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x2,%esi
movabs $0x8be589eac7,%rcx
nop
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     1140 <main+0x30>
mov    %rcx,%rax
cqto
idiv   %rsi
jmp    1146 <main+0x36>
cs nopw 0x0(%rax,%rax,1)
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
lea    0x1(%rsi),%rdi
test   %rdx,%rdx
cmove  %rax,%rcx
cmovne %rdi,%rsi
mov    %rsi,%rax
imul   %rsi,%rax
cmp    %rcx,%rax
jg     1169 <main+0x59>
cmp    $0x1,%rcx
jne    1120 <main+0x10>
jmp    116c <main+0x5c>
mov    %rcx,%rsi
push   %rax
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

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