#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 floor(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, long);
int /*<<< orphan*/ sqrt(long);
int find_biggest_prime_factor(long n) {
  int lastFactor = 1;
  ;
  if ((n & 0x01) == 0) {
    n /= 2;
    lastFactor = 2;
    while ((n & 0x01) == 0) {
      n /= 2;
    }
  }
  int factor = 3;
  int limit = floor(sqrt(n));
  while (n > 1 && factor < limit) {
    if (n % factor == 0) {
      n /= factor;
      lastFactor = factor;
      while (n % factor == 0) {
        n /= factor;
      }
      limit = floor(sqrt(n));
    }
    factor += 2;
  }
  if (n == 1) {
    printf("biggest prime factor is %d\n", lastFactor);
    return lastFactor;
  } else {
    printf("biggest prime factor is %d\n", n);
    return n;
  }
}


x86 assembly (clang, -O0):
<find_biggest_prime_factor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    119c <find_biggest_prime_factor+0x6c>
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    1197 <find_biggest_prime_factor+0x67>
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
jmp    116e <find_biggest_prime_factor+0x3e>
jmp    119c <find_biggest_prime_factor+0x6c>
movl   $0x3,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1050 <floor@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpq   $0x1,-0x10(%rbp)
mov    %al,-0x1d(%rbp)
jle    11d2 <find_biggest_prime_factor+0xa2>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11e2 <find_biggest_prime_factor+0xb2>
jmp    125e <find_biggest_prime_factor+0x12e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1250 <find_biggest_prime_factor+0x120>
movslq -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    123d <find_biggest_prime_factor+0x10d>
movslq -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
jmp    1210 <find_biggest_prime_factor+0xe0>
mov    -0x10(%rbp),%rdi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1050 <floor@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    11b6 <find_biggest_prime_factor+0x86>
cmpq   $0x1,-0x10(%rbp)
jne    1284 <find_biggest_prime_factor+0x154>
movslq -0x14(%rbp),%rsi
lea    0xd8c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    129b <find_biggest_prime_factor+0x16b>
mov    -0x10(%rbp),%rsi
lea    0xd71(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_biggest_prime_factor>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x1,%r14d
test   $0x1,%bl
jne    1168 <find_biggest_prime_factor+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rax
shr    $0x3f,%rax
add    %rax,%rbx
sar    %rbx
test   $0x1,%bl
je     1150 <find_biggest_prime_factor+0x20>
mov    $0x2,%r14d
mov    %rbx,%rdi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1050 <floor@plt>
cmp    $0x2,%rbx
jl     1255 <find_biggest_prime_factor+0x125>
mov    %eax,%ecx
cmp    $0x4,%eax
jl     1255 <find_biggest_prime_factor+0x125>
mov    $0x3,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rax
or     %rbp,%rax
shr    $0x20,%rax
je     11d0 <find_biggest_prime_factor+0xa0>
mov    %rbx,%rax
xor    %edx,%edx
div    %rbp
test   %rdx,%rdx
je     11ed <find_biggest_prime_factor+0xbd>
cmp    $0x2,%rbx
jge    1249 <find_biggest_prime_factor+0x119>
jmp    1255 <find_biggest_prime_factor+0x125>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
test   %rdx,%rdx
jne    11b9 <find_biggest_prime_factor+0x89>
jmp    11ed <find_biggest_prime_factor+0xbd>
nopl   (%rax)
mov    %rbx,%rax
cqto
idiv   %rbp
test   %rdx,%rdx
jne    122f <find_biggest_prime_factor+0xff>
mov    %rbx,%rax
or     %rbp,%rax
shr    $0x20,%rax
je     1210 <find_biggest_prime_factor+0xe0>
mov    %rbx,%rax
cqto
idiv   %rbp
mov    %rax,%rbx
jmp    1218 <find_biggest_prime_factor+0xe8>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
mov    %eax,%ebx
mov    %rbx,%rax
or     %rbp,%rax
shr    $0x20,%rax
jne    11e0 <find_biggest_prime_factor+0xb0>
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
test   %rdx,%rdx
je     11ed <find_biggest_prime_factor+0xbd>
mov    %rbx,%rdi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1050 <floor@plt>
mov    %eax,%ecx
mov    %ebp,%r14d
cmp    $0x2,%rbx
jl     1255 <find_biggest_prime_factor+0x125>
add    $0x2,%rbp
cmp    %ebp,%ecx
jg     11a0 <find_biggest_prime_factor+0x70>
cmp    $0x1,%rbx
jne    126c <find_biggest_prime_factor+0x13c>
movslq %r14d,%rsi
lea    0xd9b(%rip),%rdi
call   1030 <printf@plt>
jmp    127e <find_biggest_prime_factor+0x14e>
lea    0xd8d(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %ebx,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"biggest prime factor is %d\0A\00"
define i32 @find_biggest_prime_factor(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i64 %0, i64* %3
store i32 1, i32* %4
%7 = load i64, i64* %3
%8 = and i64 %7, 1
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %1
%11 = load i64, i64* %3
%12 = sdiv i64 %11, 2
store i64 %12, i64* %3
store i32 2, i32* %4
br label %13
13: ; preds = %17, %10
%14 = load i64, i64* %3
%15 = and i64 %14, 1
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i64, i64* %3
%19 = sdiv i64 %18, 2
store i64 %19, i64* %3
br label %13
20: ; preds = %13
br label %21
21: ; preds = %20, %1
store i32 3, i32* %5
%22 = load i64, i64* %3
%23 = call i32 @sqrt(i64 %22)
%24 = call i32 @floor(i32 %23)
store i32 %24, i32* %6
br label %25
25: ; preds = %61, %21
%26 = load i64, i64* %3
%27 = icmp sgt i64 %26, 1
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = icmp slt i32 %29, %30
br label %32
32: ; preds = %28, %25
%33 = phi i1 [ false, %25 ], [ %31, %28 ]
br i1 %33, label %34, label %64
34: ; preds = %32
%35 = load i64, i64* %3
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = srem i64 %35, %37
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %61
40: ; preds = %34
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = load i64, i64* %3
%44 = sdiv i64 %43, %42
store i64 %44, i64* %3
%45 = load i32, i32* %5
store i32 %45, i32* %4
br label %46
46: ; preds = %52, %40
%47 = load i64, i64* %3
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = srem i64 %47, %49
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %46
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = load i64, i64* %3
%56 = sdiv i64 %55, %54
store i64 %56, i64* %3
br label %46
57: ; preds = %46
%58 = load i64, i64* %3
%59 = call i32 @sqrt(i64 %58)
%60 = call i32 @floor(i32 %59)
store i32 %60, i32* %6
br label %61
61: ; preds = %57, %34
%62 = load i32, i32* %5
%63 = add nsw i32 %62, 2
store i32 %63, i32* %5
br label %25
64: ; preds = %32
%65 = load i64, i64* %3
%66 = icmp eq i64 %65, 1
br i1 %66, label %67, label %72
67: ; preds = %64
%68 = load i32, i32* %4
%69 = sext i32 %68 to i64
%70 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i64 %69)
%71 = load i32, i32* %4
store i32 %71, i32* %2
br label %77
72: ; preds = %64
%73 = load i64, i64* %3
%74 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i64 %73)
%75 = load i64, i64* %3
%76 = trunc i64 %75 to i32
store i32 %76, i32* %2
br label %77
77: ; preds = %72, %67
%78 = load i32, i32* %2
ret i32 %78
}

LLVM IR (-O2):
@.str = [28 x i8] c"biggest prime factor is %d\0A\00"
define i32 @find_biggest_prime_factor(i64 %0) {
%2 = and i64 %0, 1
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %9
4: ; preds = %1, %4
%5 = phi i64 [ %6, %4 ], [ %0, %1 ]
%6 = sdiv i64 %5, 2
%7 = and i64 %6, 1
%8 = icmp eq i64 %7, 0
br i1 %8, label %4, label %9
9: ; preds = %4, %1
%10 = phi i64 [ %0, %1 ], [ %6, %4 ]
%11 = phi i32 [ 1, %1 ], [ 2, %4 ]
%12 = tail call i32 @sqrt(i64 %10)
%13 = tail call i32 @floor(i32 %12)
%14 = icmp sgt i64 %10, 1
%15 = icmp sgt i32 %13, 3
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %17, label %42
17: ; preds = %9, %33
%18 = phi i64 [ %37, %33 ], [ 3, %9 ]
%19 = phi i32 [ %36, %33 ], [ %13, %9 ]
%20 = phi i32 [ %35, %33 ], [ %11, %9 ]
%21 = phi i64 [ %34, %33 ], [ %10, %9 ]
%22 = urem i64 %21, %18
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %17, %24
%25 = phi i64 [ %26, %24 ], [ %21, %17 ]
%26 = sdiv i64 %25, %18
%27 = srem i64 %26, %18
%28 = icmp eq i64 %27, 0
br i1 %28, label %24, label %29
29: ; preds = %24
%30 = tail call i32 @sqrt(i64 %26)
%31 = tail call i32 @floor(i32 %30)
%32 = trunc i64 %18 to i32
br label %33
33: ; preds = %29, %17
%34 = phi i64 [ %26, %29 ], [ %21, %17 ]
%35 = phi i32 [ %32, %29 ], [ %20, %17 ]
%36 = phi i32 [ %31, %29 ], [ %19, %17 ]
%37 = add nuw i64 %18, 2
%38 = icmp sgt i64 %34, 1
%39 = trunc i64 %37 to i32
%40 = icmp sgt i32 %36, %39
%41 = select i1 %38, i1 %40, i1 false
br i1 %41, label %17, label %42
42: ; preds = %33, %9
%43 = phi i64 [ %10, %9 ], [ %34, %33 ]
%44 = phi i32 [ %11, %9 ], [ %35, %33 ]
%45 = icmp eq i64 %43, 1
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = sext i32 %44 to i64
%48 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i64 %47)
br label %52
49: ; preds = %42
%50 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i64 %43)
%51 = trunc i64 %43 to i32
br label %52
52: ; preds = %49, %46
%53 = phi i32 [ %44, %46 ], [ %51, %49 ]
ret i32 %53
}