#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 */
int find_biggest_prime_factor(long);
int floor(int /*<<< orphan*/);
scalar_t__ is_prime(int);
int /*<<< orphan*/ printf(char *, long, ...);
int /*<<< orphan*/ sqrt(long);
int main(void) {
  long n = 600851475143L;
  int x = floor(sqrt(n));
  if ((x & 0x01) == 0) {
    x--;
  }
  while (x >= 1) {
    if (n % x == 0) {
      if (is_prime(x)) {
        printf(" it is %d\n", x);
        break;
      }
    }
    x -= 2;
  }
  int bpf = find_biggest_prime_factor(n);
  printf("biggest prime factor of %ld is %d\n", n, bpf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movabs $0x8be589eac7,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1070 <floor@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1198 <main+0x48>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    119d <main+0x4d>
cmpl   $0x1,-0x14(%rbp)
jl     11fa <main+0xaa>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11ec <main+0x9c>
mov    -0x14(%rbp),%edi
call   1040 <is_prime@plt>
cmp    $0x0,%rax
je     11e7 <main+0x97>
movslq -0x14(%rbp),%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fa <main+0xaa>
jmp    11ec <main+0x9c>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    119d <main+0x4d>
mov    -0x10(%rbp),%rdi
call   1050 <find_biggest_prime_factor@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movabs $0x8be589eac7,%r14
mov    %r14,%rdi
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1070 <floor@plt>
mov    %eax,%ecx
and    $0x1,%ecx
lea    (%rax,%rcx,1),%ebx
add    $0xffffffff,%ebx
test   %ebx,%ebx
jle    11c7 <main+0x77>
movabs $0x8be589eac7,%r15
jmp    119a <main+0x4a>
nopl   0x0(%rax)
lea    -0x2(%rbx),%eax
cmp    $0x2,%ebx
mov    %eax,%ebx
jle    11c7 <main+0x77>
mov    %ebx,%r12d
mov    %r15,%rax
xor    %edx,%edx
div    %r12
test   %rdx,%rdx
jne    1190 <main+0x40>
mov    %ebx,%edi
call   1040 <is_prime@plt>
test   %rax,%rax
je     1190 <main+0x40>
lea    0xe43(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
call   1050 <find_biggest_prime_factor@plt>
lea    0xe35(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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