#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 */
typedef int int64_t;
typedef int int32_t;

/* Variables and functions */
scalar_t__ is_prime(int);
int /*<<< orphan*/ printf(char *, int);
int sqrt(int);
int main() {
  int32_t i;
  int64_t n = 600851475143;
  int32_t r;
  for (i = 2; i <= sqrt(n); i++) {
    if (n % i == 0 && is_prime(i)) {
      r = i;
    }
  }
  printf("%lld\n", r);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xe589eac7,-0xc(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <sqrt@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jg     11a3 <main+0x73>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
jne    1190 <main+0x60>
mov    -0x8(%rbp),%edi
call   1040 <is_prime@plt>
cmp    $0x0,%rax
je     1190 <main+0x60>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1195 <main+0x65>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    114d <main+0x1d>
mov    -0x10(%rbp),%esi
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0xe589eac7,%edi
call   1050 <sqrt@plt>
mov    $0x1,%ebp
jmp    115e <main+0x2e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0xe589eac7,%edi
call   1050 <sqrt@plt>
cmp    %eax,%ebp
jge    117c <main+0x4c>
add    $0x1,%ebp
mov    $0xe589eac7,%eax
cltd
idiv   %ebp
test   %edx,%edx
jne    1150 <main+0x20>
mov    %ebp,%edi
call   1040 <is_prime@plt>
test   %rax,%rax
cmovne %ebp,%ebx
jmp    1150 <main+0x20>
lea    0xe7d(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = tail call i32 @sqrt(i32 -443946297)
%2 = icmp sgt i32 %1, 1
br label %3
3: ; preds = %0, %12
%4 = phi i32 [ %13, %12 ], [ undef, %0 ]
%5 = phi i32 [ %14, %12 ], [ 2, %0 ]
%6 = srem i32 -443946297, %5
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = tail call i64 @is_prime(i32 %5)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i32 %4, i32 %5
br label %12
12: ; preds = %8, %3
%13 = phi i32 [ %4, %3 ], [ %11, %8 ]
%14 = add nuw nsw i32 %5, 1
%15 = tail call i32 @sqrt(i32 -443946297)
%16 = icmp slt i32 %5, %15
br i1 %16, label %3, label %17
17: ; preds = %12
%18 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %13)
ret i32 0
}