#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 nextPrime(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  long const VALUE = 600851475143;
  long currentValue = VALUE;
  int currentPrime = 2;
  while (currentPrime != (int)currentValue) {
    if (currentValue % currentPrime == 0) {
      currentValue = currentValue / currentPrime;
      currentPrime = 2;
    } else {
      currentPrime = nextPrime(currentPrime);
    }
  }
  printf("%i\n", (int)currentValue);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movabs $0x8be589eac7,%rax
mov    %rax,-0x10(%rbp)
movabs $0x8be589eac7,%rax
mov    %rax,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    %ecx,%eax
je     11a5 <main+0x85>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1195 <main+0x75>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
jmp    11a0 <main+0x80>
mov    -0x1c(%rbp),%edi
call   1030 <nextPrime@plt>
mov    %eax,-0x1c(%rbp)
jmp    1152 <main+0x32>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xe4e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
movabs $0x8be589eac7,%rbx
mov    $0x2,%esi
jmp    1150 <main+0x30>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %esi,%edi
call   1030 <nextPrime@plt>
mov    %eax,%esi
mov    %rbx,%rax
cmp    %eax,%esi
je     1187 <main+0x67>
movslq %esi,%rcx
mov    %rbx,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1170 <main+0x50>
mov    %rbx,%rax
cqto
idiv   %rcx
test   %rdx,%rdx
jne    1140 <main+0x20>
jmp    117b <main+0x5b>
xchg   %ax,%ax
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
test   %rdx,%rdx
jne    1140 <main+0x20>
mov    $0x2,%esi
mov    %rax,%rbx
cmp    %eax,%esi
jne    1150 <main+0x30>
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

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

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