#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__ isPrime(int);
int /*<<< orphan*/ printf(char *, int, unsigned long);
int sqrt(unsigned long);
int main(int argc, char **argv) {
  unsigned long number = 600851475143;
  int i, max;
  max = sqrt(number);
  for (i = max; i > 1; i--) {
    if (!(number % i ? 0 : 1)) {
      continue;
    }
    if (isPrime(i)) {
      break;
    }
  }
  printf("%d is the largest prime factor of %lu \n", i, number);
}


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)
movabs $0x8be589eac7,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <sqrt@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jle    11d4 <main+0xa4>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
je     1196 <main+0x66>
xor    %eax,%eax
test   $0x1,%al
jne    11aa <main+0x7a>
jmp    11a5 <main+0x75>
mov    $0x1,%al
test   $0x1,%al
jne    11aa <main+0x7a>
jmp    11a5 <main+0x75>
jmp    11c6 <main+0x96>
mov    -0x1c(%rbp),%edi
call   1040 <isPrime@plt>
cmp    $0x0,%rax
je     11c1 <main+0x91>
jmp    11d4 <main+0xa4>
jmp    11c6 <main+0x96>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1166 <main+0x36>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
movabs $0x8be589eac7,%r14
mov    %r14,%rdi
call   1050 <sqrt@plt>
mov    %eax,%ebx
cmp    $0x2,%eax
jl     118d <main+0x5d>
mov    %ebx,%ebx
movabs $0x8be589eac7,%r15
jmp    116d <main+0x3d>
nopl   0x0(%rax)
lea    -0x1(%rbx),%rax
cmp    $0x2,%rbx
mov    %rax,%rbx
jle    1188 <main+0x58>
mov    %r15,%rax
xor    %edx,%edx
div    %rbx
test   %rdx,%rdx
jne    1160 <main+0x30>
mov    %ebx,%edi
call   1040 <isPrime@plt>
test   %rax,%rax
je     1160 <main+0x30>
jmp    118d <main+0x5d>
mov    $0x1,%ebx
lea    0xe6c(%rip),%rdi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [40 x i8] c"%d is the largest prime factor of %lu \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @sqrt(i64 600851475143)
%4 = icmp sgt i32 %3, 1
br i1 %4, label %5, label %20
5: ; preds = %2
%6 = zext i32 %3 to i64
br label %7
7: ; preds = %5, %15
%8 = phi i64 [ %6, %5 ], [ %16, %15 ]
%9 = urem i64 600851475143, %8
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = trunc i64 %8 to i32
%13 = tail call i64 @isPrime(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11, %7
%16 = add nsw i64 %8, -1
%17 = icmp sgt i64 %8, 2
br i1 %17, label %7, label %20
18: ; preds = %11
%19 = trunc i64 %8 to i32
br label %20
20: ; preds = %15, %18, %2
%21 = phi i32 [ %3, %2 ], [ %19, %18 ], [ 1, %15 ]
%22 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %21, i64 600851475143)
ret i32 0
}