#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 *, int);
int main() {
  long unsigned int val = 600851475143;
  int d = 2;
  while (val > 1) {
    if ((val % d == 0))
      val /= d;
    else
      d++;
  }
  printf("largest factor = %d\n", d);
  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)
movl   $0x2,-0x14(%rbp)
cmpq   $0x1,-0x10(%rbp)
jbe    117a <main+0x6a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    116c <main+0x5c>
movslq -0x14(%rbp),%rcx
mov    -0x10(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
jmp    1175 <main+0x65>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1134 <main+0x24>
mov    -0x14(%rbp),%esi
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
movabs $0x8be589eac7,%rcx
mov    $0x2,%esi
jmp    114b <main+0x3b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rcx,%rax
xor    %edx,%edx
div    %rdi
test   %rdx,%rdx
cmove  %rax,%rcx
lea    0x1(%rsi),%eax
cmovne %eax,%esi
cmp    $0x1,%rcx
jbe    1162 <main+0x52>
movslq %esi,%rdi
mov    %rcx,%rax
or     %rdi,%rax
shr    $0x20,%rax
jne    1130 <main+0x20>
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
jmp    1138 <main+0x28>
push   %rax
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [21 x i8] c"largest factor = %d\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 2, %0 ], [ %10, %1 ]
%3 = phi i64 [ 600851475143, %0 ], [ %9, %1 ]
%4 = sext i32 %2 to i64
%5 = urem i64 %3, %4
%6 = udiv i64 %3, %4
%7 = icmp eq i64 %5, 0
%8 = add nsw i32 %2, 1
%9 = select i1 %7, i64 %6, i64 %3
%10 = select i1 %7, i32 %2, i32 %8
%11 = icmp ugt i64 %9, 1
br i1 %11, label %1, label %12
12: ; preds = %1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %10)
ret i32 0
}