#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(int argc, char *argv[]) {
  long int i;
  long int largest = 0;
  for (i = 0; i * i <= 600851475143; i++) {
    if (is_prime(i) && (600851475143 % i == 0)) {
      largest = i;
    }
  }
  printf("The largest prime factor of 600851475143 is: %lu\n", largest);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x18(%rbp),%rax
movabs $0x8be589eac7,%rcx
cmp    %rcx,%rax
jg     11ad <main+0x8d>
mov    -0x18(%rbp),%rdi
call   1040 <is_prime@plt>
cmp    $0x0,%rax
je     1197 <main+0x77>
movabs $0x8be589eac7,%rax
cqto
idivq  -0x18(%rbp)
cmp    $0x0,%rdx
jne    1197 <main+0x77>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    119c <main+0x7c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1146 <main+0x26>
mov    -0x20(%rbp),%rsi
lea    0xe48(%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
xor    %r15d,%r15d
movabs $0x8be589eac7,%r14
xor    %ebx,%ebx
jmp    1150 <main+0x30>
cs nopw 0x0(%rax,%rax,1)
mov    %rax,%r15
add    $0x1,%rbx
cmp    $0xbd3eb,%rbx
je     1172 <main+0x52>
mov    %rbx,%rdi
call   1040 <is_prime@plt>
test   %rax,%rax
je     1143 <main+0x23>
mov    %r14,%rax
xor    %edx,%edx
div    %rbx
mov    %rbx,%rax
test   %rdx,%rdx
je     1140 <main+0x20>
mov    %r15,%rax
jmp    1140 <main+0x20>
lea    0xe87(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [50 x i8] c"The largest prime factor of 600851475143 is: %lu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %7
store i64 0, i64* %6
br label %8
8: ; preds = %24, %2
%9 = load i64, i64* %6
%10 = load i64, i64* %6
%11 = mul nsw i64 %9, %10
%12 = icmp sle i64 %11, 600851475143
br i1 %12, label %13, label %27
13: ; preds = %8
%14 = load i64, i64* %6
%15 = call i64 @is_prime(i64 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i64, i64* %6
%19 = srem i64 600851475143, %18
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load i64, i64* %6
store i64 %22, i64* %7
br label %23
23: ; preds = %21, %17, %13
br label %24
24: ; preds = %23
%25 = load i64, i64* %6
%26 = add nsw i64 %25, 1
store i64 %26, i64* %6
br label %8
27: ; preds = %8
%28 = load i64, i64* %7
%29 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i64 %28)
ret i32 0
}

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