#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 */
scalar_t__ is_prime(long);
int /*<<< orphan*/ printf(char *, long);
int main() {
  long number = 600851475143;
  long testnumber = 0;
  int j = 2;
  while (1) {
    testnumber = number / j;
    if (number % testnumber == 0) {
      if (is_prime(testnumber))
        break;
    }
    j++;
  }
  printf("LARGEST PRIME FACTOR: %ld\n", testnumber);
  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   $0x0,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cqto
idivq  -0x18(%rbp)
cmp    $0x0,%rdx
jne    118e <main+0x6e>
mov    -0x18(%rbp),%rdi
call   1040 <is_prime@plt>
cmp    $0x0,%rax
je     1189 <main+0x69>
jmp    119c <main+0x7c>
jmp    118e <main+0x6e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114c <main+0x2c>
mov    -0x18(%rbp),%rsi
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x2,%ebx
movabs $0x8be589eac7,%r14
jmp    1144 <main+0x24>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r14,%rax
xor    %edx,%edx
div    %rbx
mov    %rax,%r15
mov    %r14,%rax
xor    %edx,%edx
div    %r15
test   %rdx,%rdx
jne    1140 <main+0x20>
mov    %r15,%rdi
call   1040 <is_prime@plt>
test   %rax,%rax
je     1140 <main+0x20>
lea    0xe90(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [27 x i8] c"LARGEST PRIME FACTOR: %ld\0A\00"
define i32 @main() {
br label %1
1: ; preds = %9, %0
%2 = phi i64 [ %10, %9 ], [ 2, %0 ]
%3 = udiv i64 600851475143, %2
%4 = urem i64 600851475143, %3
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i64 @is_prime(i64 %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6, %1
%10 = add nuw i64 %2, 1
br label %1
11: ; preds = %6
%12 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %3)
ret i32 0
}