#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);
int main(int argc, char *argv[]) {
  long long n = 600851475143;
  long long currentPrime = 1;
  while (n > 1) {
    currentPrime++;
    while (n % currentPrime == 0)
      n /= currentPrime;
  }
  printf("Largest prime factor: %lld\n", currentPrime);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0x8be589eac7,%rax
mov    %rax,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
cmpq   $0x1,-0x18(%rbp)
jle    1182 <main+0x72>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cqto
idivq  -0x20(%rbp)
cmp    $0x0,%rdx
jne    117d <main+0x6d>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
jmp    1153 <main+0x43>
jmp    113c <main+0x2c>
mov    -0x20(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
movabs $0x8be589eac7,%rcx
mov    $0x1,%esi
jmp    1136 <main+0x26>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x2,%rcx
jl     1191 <main+0x81>
add    $0x1,%rsi
jmp    114b <main+0x3b>
nopl   0x0(%rax)
mov    %rcx,%rax
cqto
idiv   %rsi
mov    %rax,%rcx
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     1170 <main+0x60>
mov    %rcx,%rax
cqto
idiv   %rsi
test   %rdx,%rdx
je     117b <main+0x6b>
jmp    1130 <main+0x20>
cs nopw 0x0(%rax,%rax,1)
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
test   %rdx,%rdx
jne    1130 <main+0x20>
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
jne    1140 <main+0x30>
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
mov    %eax,%ecx
jmp    114b <main+0x3b>
push   %rax
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

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