#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*/ isPrime(unsigned long long);
int /*<<< orphan*/ printf(char *, unsigned long long, unsigned long long);
int main() {
  unsigned long long n = 600851475143;
  unsigned long long prime, temp, max = 0;
  temp = n;
  for (prime = 2; temp > 1; ++prime) {
    if (!isPrime(prime))
      continue;
    while (!(temp % prime)) {
      temp /= prime;
    }
    if (max < prime)
      max = prime;
  }
  printf("Largest prime factor of %lld is %lld\n", n, max);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movabs $0x8be589eac7,%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x2,-0x18(%rbp)
cmpq   $0x1,-0x20(%rbp)
jbe    11e0 <main+0xc0>
mov    -0x18(%rbp),%rdi
call   1040 <isPrime@plt>
cmp    $0x0,%eax
jne    1177 <main+0x57>
jmp    11cf <main+0xaf>
jmp    117c <main+0x5c>
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    119e <main+0x7e>
jmp    11b4 <main+0x94>
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
jmp    117c <main+0x5c>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11ca <main+0xaa>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11cf <main+0xaf>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1155 <main+0x35>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe11(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x2,%r12d
movabs $0x8be589eac7,%r14
xor    %r15d,%r15d
mov    %r14,%rbx
jmp    1151 <main+0x31>
cmp    %r12,%r15
cmovb  %r12,%r15
add    $0x1,%r12
cmp    $0x1,%rbx
jbe    11b3 <main+0x93>
mov    %r12,%rdi
call   1040 <isPrime@plt>
test   %eax,%eax
jne    116b <main+0x4b>
jmp    1147 <main+0x27>
nop
mov    %rbx,%rax
xor    %edx,%edx
div    %r12
mov    %rax,%rbx
mov    %rbx,%rax
or     %r12,%rax
shr    $0x20,%rax
je     1190 <main+0x70>
mov    %rbx,%rax
xor    %edx,%edx
div    %r12
test   %rdx,%rdx
je     119c <main+0x7c>
jmp    1140 <main+0x20>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %r12d
test   %rdx,%rdx
jne    1140 <main+0x20>
mov    %rbx,%rax
or     %r12,%rax
shr    $0x20,%rax
jne    1160 <main+0x40>
mov    %ebx,%eax
xor    %edx,%edx
div    %r12d
mov    %eax,%ebx
jmp    116b <main+0x4b>
lea    0xe46(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Largest prime factor of %lld is %lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i32 0, i32* %1
store i64 600851475143, i64* %2
store i64 0, i64* %5
%6 = load i64, i64* %2
store i64 %6, i64* %4
store i64 2, i64* %3
br label %7
7: ; preds = %33, %0
%8 = load i64, i64* %4
%9 = icmp ugt i64 %8, 1
br i1 %9, label %10, label %36
10: ; preds = %7
%11 = load i64, i64* %3
%12 = call i32 @isPrime(i64 %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %10
br label %33
15: ; preds = %10
br label %16
16: ; preds = %22, %15
%17 = load i64, i64* %4
%18 = load i64, i64* %3
%19 = urem i64 %17, %18
%20 = icmp ne i64 %19, 0
%21 = xor i1 %20, true
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i64, i64* %3
%24 = load i64, i64* %4
%25 = udiv i64 %24, %23
store i64 %25, i64* %4
br label %16
26: ; preds = %16
%27 = load i64, i64* %5
%28 = load i64, i64* %3
%29 = icmp ult i64 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = load i64, i64* %3
store i64 %31, i64* %5
br label %32
32: ; preds = %30, %26
br label %33
33: ; preds = %32, %14
%34 = load i64, i64* %3
%35 = add i64 %34, 1
store i64 %35, i64* %3
br label %7
36: ; preds = %7
%37 = load i64, i64* %2
%38 = load i64, i64* %5
%39 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 %37, i64 %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [38 x i8] c"Largest prime factor of %lld is %lld\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %19
%2 = phi i64 [ 0, %0 ], [ %21, %19 ]
%3 = phi i64 [ 600851475143, %0 ], [ %20, %19 ]
%4 = phi i64 [ 2, %0 ], [ %22, %19 ]
%5 = tail call i32 @isPrime(i64 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %1
%8 = urem i64 %3, %4
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7, %10
%11 = phi i64 [ %12, %10 ], [ %3, %7 ]
%12 = udiv i64 %11, %4
%13 = urem i64 %12, %4
%14 = icmp eq i64 %13, 0
br i1 %14, label %10, label %15
15: ; preds = %10, %7
%16 = phi i64 [ %3, %7 ], [ %12, %10 ]
%17 = icmp ult i64 %2, %4
%18 = select i1 %17, i64 %4, i64 %2
br label %19
19: ; preds = %15, %1
%20 = phi i64 [ %3, %1 ], [ %16, %15 ]
%21 = phi i64 [ %2, %1 ], [ %18, %15 ]
%22 = add i64 %4, 1
%23 = icmp ugt i64 %20, 1
br i1 %23, label %1, label %24
24: ; preds = %19
%25 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 600851475143, i64 %21)
ret i32 0
}