#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 EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, unsigned long const, unsigned long);
int main(int argc, char *argv[]) {
  const unsigned long given = 600851475143;
  unsigned long number = given, factor = 2, largest = factor;
  while (factor <= number) {
    if (number % factor == 0) {
      if (factor > largest) {
        largest = factor;
      }
      number /= factor;
      factor = 2;
    } else {
      factor++;
    }
  }
  printf("Largest prime factor of %lu is: %lu.\n", given, largest);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0x8be589eac7,%rax
mov    %rax,-0x18(%rbp)
movabs $0x8be589eac7,%rax
mov    %rax,-0x20(%rbp)
movq   $0x2,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
ja     11bb <main+0xab>
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x28(%rbp)
cmp    $0x0,%rdx
jne    11aa <main+0x9a>
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jbe    118c <main+0x7c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
movq   $0x2,-0x28(%rbp)
jmp    11b6 <main+0xa6>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1152 <main+0x42>
mov    -0x30(%rbp),%rdx
lea    0xe3a(%rip),%rdi
movabs $0x8be589eac7,%rsi
call   1030 <printf@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x2,%r8d
movabs $0x8be589eac7,%rsi
mov    $0x2,%r9d
mov    $0x2,%ecx
mov    %rsi,%r10
jmp    115a <main+0x4a>
mov    %r10,%rax
xor    %edx,%edx
div    %rcx
cmp    %r9,%rcx
mov    %r9,%rdi
cmova  %rcx,%rdi
add    $0x1,%rcx
test   %rdx,%rdx
cmove  %rax,%r10
cmove  %r8,%rcx
cmove  %rdi,%r9
cmp    %r10,%rcx
ja     116f <main+0x5f>
mov    %r10,%rax
or     %rcx,%rax
shr    $0x20,%rax
jne    1130 <main+0x20>
mov    %r10d,%eax
xor    %edx,%edx
div    %ecx
jmp    1138 <main+0x28>
push   %rax
lea    0xe89(%rip),%rdi
mov    %r9,%rdx
call   1030 <printf@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret

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

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