#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);
int main(void) {
  long number = 600851475143;
  for (long i = 1; (i * i) < number; i += 2) {
    if (number % i == 0) {
      number /= i;
    }
  }
  printf("largest prime: %lu\n", number);
  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   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1183 <main+0x73>
mov    -0x10(%rbp),%rax
cqto
idivq  -0x18(%rbp)
cmp    $0x0,%rdx
jne    116d <main+0x5d>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
jmp    1172 <main+0x62>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    1135 <main+0x25>
mov    -0x10(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
movabs $0x8be589eac7,%rsi
mov    $0x1,%ecx
jmp    114f <main+0x3f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rsi,%rax
cqto
idiv   %rcx
test   %rdx,%rdx
cmove  %rax,%rsi
add    $0x2,%rcx
mov    %rcx,%rax
imul   %rcx,%rax
cmp    %rsi,%rax
jge    1163 <main+0x53>
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    0xe95(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"largest prime: %lu\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 1, i64* %3
br label %4
4: ; preds = %20, %0
%5 = load i64, i64* %3
%6 = load i64, i64* %3
%7 = mul nsw i64 %5, %6
%8 = load i64, i64* %2
%9 = icmp slt i64 %7, %8
br i1 %9, label %10, label %23
10: ; preds = %4
%11 = load i64, i64* %2
%12 = load i64, i64* %3
%13 = srem i64 %11, %12
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i64, i64* %3
%17 = load i64, i64* %2
%18 = sdiv i64 %17, %16
store i64 %18, i64* %2
br label %19
19: ; preds = %15, %10
br label %20
20: ; preds = %19
%21 = load i64, i64* %3
%22 = add nsw i64 %21, 2
store i64 %22, i64* %3
br label %4
23: ; preds = %4
%24 = load i64, i64* %2
%25 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i64 %24)
ret i32 0
}

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