#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(long);
int /*<<< orphan*/ printf(char *, long);
long sqrt(long);
int main(int argc, char const *argv[]) {
  long max_factor = 0;
  long N = 600851475143;
  for (long i = 3; i < sqrt(N); ++i) {
    if (N % i == 0) {
      if (isprime(i)) {
        max_factor = i;
      } else if (isprime(N / i)) {
        max_factor = N / i;
      }
    }
  }
  printf("The answer to Euler Problem 3 is %lu", max_factor);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movabs $0x8be589eac7,%rax
mov    %rax,-0x20(%rbp)
movq   $0x3,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <sqrt@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jge    1203 <main+0xd3>
mov    -0x20(%rbp),%rax
cqto
idivq  -0x28(%rbp)
cmp    $0x0,%rdx
jne    11ed <main+0xbd>
mov    -0x28(%rbp),%rdi
call   1040 <isprime@plt>
cmp    $0x0,%rax
je     11b9 <main+0x89>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11e8 <main+0xb8>
mov    -0x20(%rbp),%rax
cqto
idivq  -0x28(%rbp)
mov    %rax,%rdi
call   1040 <isprime@plt>
cmp    $0x0,%rax
je     11e3 <main+0xb3>
mov    -0x20(%rbp),%rax
cqto
idivq  -0x28(%rbp)
mov    %rax,-0x18(%rbp)
jmp    11e8 <main+0xb8>
jmp    11ed <main+0xbd>
jmp    11f2 <main+0xc2>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1164 <main+0x34>
mov    -0x18(%rbp),%rsi
lea    0xdf2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movabs $0x8be589eac7,%r14
mov    %r14,%rdi
call   1050 <sqrt@plt>
cmp    $0x4,%rax
jl     11b8 <main+0x88>
mov    $0x3,%ebx
xor    %ebp,%ebp
movabs $0x8be589eac7,%r15
jmp    1187 <main+0x57>
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%r12
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <sqrt@plt>
mov    %r12,%rbp
cmp    %rax,%rbx
jge    11bb <main+0x8b>
mov    %r15,%rax
xor    %edx,%edx
div    %rbx
test   %rdx,%rdx
jne    1170 <main+0x40>
mov    %rax,%r13
mov    %rbx,%rdi
call   1040 <isprime@plt>
mov    %rbx,%r12
test   %rax,%rax
jne    1173 <main+0x43>
mov    %r13,%rdi
call   1040 <isprime@plt>
test   %rax,%rax
cmovne %r13,%rbp
jmp    1170 <main+0x40>
xor    %r12d,%r12d
lea    0xe3e(%rip),%rdi
mov    %r12,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"The answer to Euler Problem 3 is %lu\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
store i64 600851475143, i64* %7
store i64 3, i64* %8
br label %9
9: ; preds = %38, %2
%10 = load i64, i64* %8
%11 = load i64, i64* %7
%12 = call i64 @sqrt(i64 %11)
%13 = icmp slt i64 %10, %12
br i1 %13, label %14, label %41
14: ; preds = %9
%15 = load i64, i64* %7
%16 = load i64, i64* %8
%17 = srem i64 %15, %16
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %37
19: ; preds = %14
%20 = load i64, i64* %8
%21 = call i64 @isprime(i64 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = load i64, i64* %8
store i64 %24, i64* %6
br label %36
25: ; preds = %19
%26 = load i64, i64* %7
%27 = load i64, i64* %8
%28 = sdiv i64 %26, %27
%29 = call i64 @isprime(i64 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = load i64, i64* %7
%33 = load i64, i64* %8
%34 = sdiv i64 %32, %33
store i64 %34, i64* %6
br label %35
35: ; preds = %31, %25
br label %36
36: ; preds = %35, %23
br label %37
37: ; preds = %36, %14
br label %38
38: ; preds = %37
%39 = load i64, i64* %8
%40 = add nsw i64 %39, 1
store i64 %40, i64* %8
br label %9
41: ; preds = %9
%42 = load i64, i64* %6
%43 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %42)
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [37 x i8] c"The answer to Euler Problem 3 is %lu\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @sqrt(i64 600851475143)
%4 = icmp sgt i64 %3, 3
br i1 %4, label %8, label %5
5: ; preds = %21, %2
%6 = phi i64 [ 0, %2 ], [ %22, %21 ]
%7 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %6)
ret i32 0
8: ; preds = %2, %21
%9 = phi i64 [ %23, %21 ], [ 3, %2 ]
%10 = phi i64 [ %22, %21 ], [ 0, %2 ]
%11 = urem i64 600851475143, %9
%12 = udiv i64 600851475143, %9
%13 = icmp eq i64 %11, 0
br i1 %13, label %14, label %21
14: ; preds = %8
%15 = tail call i64 @isprime(i64 %9)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = tail call i64 @isprime(i64 %12)
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i64 %10, i64 %12
br label %21
21: ; preds = %17, %14, %8
%22 = phi i64 [ %10, %8 ], [ %9, %14 ], [ %20, %17 ]
%23 = add nuw nsw i64 %9, 1
%24 = tail call i64 @sqrt(i64 600851475143)
%25 = icmp slt i64 %23, %24
br i1 %25, label %8, label %5
}