#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 *, unsigned long long);
int main(void) {
  unsigned long long n = 600851475143ULL;
  unsigned long long i;
  for (i = 2; i < n / 2; i++) {
    if (n % i == 0)
      n /= i;
  }
  printf("The largest prime factor is %llu\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)
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
shr    $0x1,%rcx
cmp    %rcx,%rax
jae    1187 <main+0x77>
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
jne    1171 <main+0x61>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
jmp    1176 <main+0x66>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1135 <main+0x25>
mov    -0x10(%rbp),%rsi
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
movabs $0x8be589eac7,%rsi
mov    $0x2,%ecx
jmp    114e <main+0x3e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rsi,%rax
xor    %edx,%edx
div    %rcx
test   %rdx,%rdx
cmove  %rax,%rsi
add    $0x1,%rcx
mov    %rsi,%rax
shr    %rax
cmp    %rax,%rcx
jae    1162 <main+0x52>
mov    %rsi,%rax
or     %rcx,%rax
shr    $0x20,%rax
jne    1130 <main+0x20>
mov    %esi,%eax
xor    %edx,%edx
div    %ecx
jmp    1138 <main+0x28>
push   %rax
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [34 x i8] c"The largest prime factor is %llu\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 = %19, %0
%5 = load i64, i64* %3
%6 = load i64, i64* %2
%7 = udiv i64 %6, 2
%8 = icmp ult i64 %5, %7
br i1 %8, label %9, label %22
9: ; preds = %4
%10 = load i64, i64* %2
%11 = load i64, i64* %3
%12 = urem i64 %10, %11
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i64, i64* %3
%16 = load i64, i64* %2
%17 = udiv i64 %16, %15
store i64 %17, i64* %2
br label %18
18: ; preds = %14, %9
br label %19
19: ; preds = %18
%20 = load i64, i64* %3
%21 = add 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 ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"The largest prime factor is %llu\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i64 [ 2, %0 ], [ %8, %1 ]
%3 = phi i64 [ 600851475143, %0 ], [ %7, %1 ]
%4 = urem i64 %3, %2
%5 = udiv i64 %3, %2
%6 = icmp eq i64 %4, 0
%7 = select i1 %6, i64 %5, i64 %3
%8 = add nuw nsw i64 %2, 1
%9 = lshr i64 %7, 1
%10 = icmp ult i64 %8, %9
br i1 %10, label %1, label %11
11: ; preds = %1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 %7)
ret i32 0
}