#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 */
double fmod(long, long);
scalar_t__ is_prime(long);
long sqrt(long);
long euler_problem_3() {
  long target = 600851475143;
  long i, max = 0;
  for (i = 0; i < sqrt(target); ++i) {
    if (fmod(target, i) == 0.0 && is_prime(i)) {
      max = i;
    }
  }
  return max;
}


x86 assembly (clang, -O0):
<euler_problem_3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movabs $0x8be589eac7,%rax
mov    %rax,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <sqrt@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jge    11c8 <euler_problem_3+0x98>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <fmod@plt>
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b2 <euler_problem_3+0x82>
jp     11b2 <euler_problem_3+0x82>
mov    -0x10(%rbp),%rdi
call   1040 <is_prime@plt>
cmp    $0x0,%rax
je     11b2 <euler_problem_3+0x82>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11b7 <euler_problem_3+0x87>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1156 <euler_problem_3+0x26>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euler_problem_3>:
push   %r15
push   %r14
push   %rbx
movabs $0x8be589eac7,%r14
mov    %r14,%rdi
call   1050 <sqrt@plt>
xor    %r15d,%r15d
test   %rax,%rax
jle    1199 <euler_problem_3+0x69>
xor    %ebx,%ebx
jmp    1171 <euler_problem_3+0x41>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <sqrt@plt>
cmp    %rax,%rbx
jge    1199 <euler_problem_3+0x69>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <fmod@plt>
ucomisd 0xe7c(%rip),%xmm0
jne    1160 <euler_problem_3+0x30>
jp     1160 <euler_problem_3+0x30>
mov    %rbx,%rdi
call   1040 <is_prime@plt>
test   %rax,%rax
cmovne %rbx,%r15
jmp    1160 <euler_problem_3+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @euler_problem_3() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
store i64 600851475143, i64* %1
store i64 0, i64* %3
store i64 0, i64* %2
br label %4
4: ; preds = %21, %0
%5 = load i64, i64* %2
%6 = load i64, i64* %1
%7 = call i64 @sqrt(i64 %6)
%8 = icmp slt i64 %5, %7
br i1 %8, label %9, label %24
9: ; preds = %4
%10 = load i64, i64* %1
%11 = load i64, i64* %2
%12 = call double @fmod(i64 %10, i64 %11)
%13 = fcmp oeq double %12, 0.000000e+00
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = load i64, i64* %2
%16 = call i64 @is_prime(i64 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = load i64, i64* %2
store i64 %19, i64* %3
br label %20
20: ; preds = %18, %14, %9
br label %21
21: ; preds = %20
%22 = load i64, i64* %2
%23 = add nsw i64 %22, 1
store i64 %23, i64* %2
br label %4
24: ; preds = %4
%25 = load i64, i64* %3
ret i64 %25
}

LLVM IR (-O2):
define i64 @euler_problem_3() {
%1 = tail call i64 @sqrt(i64 600851475143)
%2 = icmp sgt i64 %1, 0
br i1 %2, label %3, label %17
3: ; preds = %0, %12
%4 = phi i64 [ %13, %12 ], [ 0, %0 ]
%5 = phi i64 [ %14, %12 ], [ 0, %0 ]
%6 = tail call double @fmod(i64 600851475143, i64 %5)
%7 = fcmp oeq double %6, 0.000000e+00
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = tail call i64 @is_prime(i64 %5)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i64 %4, i64 %5
br label %12
12: ; preds = %8, %3
%13 = phi i64 [ %4, %3 ], [ %11, %8 ]
%14 = add nuw nsw i64 %5, 1
%15 = tail call i64 @sqrt(i64 600851475143)
%16 = icmp slt i64 %14, %15
br i1 %16, label %3, label %17
17: ; preds = %12, %0
%18 = phi i64 [ 0, %0 ], [ %13, %12 ]
ret i64 %18
}