#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 long);
long long int least_pf(long long int n) {
  long long int i, j, k;
  if (isprime(n))
    j = n;
  else {
    for (i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        if (isprime(i)) {
          j = i;
          break;
        }
      }
    }
  }
  return j;
}


x86 assembly (clang, -O0):
<least_pf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <isprime@plt>
cmp    $0x0,%rax
je     113c <least_pf+0x2c>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11ab <least_pf+0x9b>
movq   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%rax
imul   -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jg     11a6 <least_pf+0x96>
mov    -0x8(%rbp),%rax
cqto
idivq  -0x10(%rbp)
cmp    $0x0,%rdx
jne    1190 <least_pf+0x80>
mov    -0x10(%rbp),%rdi
call   1030 <isprime@plt>
cmp    $0x0,%rax
je     118b <least_pf+0x7b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11a6 <least_pf+0x96>
jmp    1190 <least_pf+0x80>
jmp    1195 <least_pf+0x85>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1144 <least_pf+0x34>
jmp    11ab <least_pf+0x9b>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<least_pf>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <isprime@plt>
test   %rax,%rax
je     1126 <least_pf+0x16>
mov    %r14,%rbx
jmp    1189 <least_pf+0x79>
cmp    $0x4,%r14
jl     1189 <least_pf+0x79>
mov    $0x2,%eax
jmp    1150 <least_pf+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x1(%rbx),%rax
mov    %rax,%rcx
imul   %rax,%rcx
cmp    %r14,%rcx
jg     1189 <least_pf+0x79>
mov    %rax,%rbx
mov    %r14,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     1170 <least_pf+0x60>
mov    %r14,%rax
cqto
idiv   %rbx
test   %rdx,%rdx
jne    1140 <least_pf+0x30>
jmp    117c <least_pf+0x6c>
xchg   %ax,%ax
mov    %r14d,%eax
xor    %edx,%edx
div    %ebx
test   %rdx,%rdx
jne    1140 <least_pf+0x30>
mov    %rbx,%rdi
call   1030 <isprime@plt>
test   %rax,%rax
je     1140 <least_pf+0x30>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @least_pf(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %2
%6 = load i64, i64* %2
%7 = call i64 @isprime(i64 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i64, i64* %2
store i64 %10, i64* %4
br label %35
11: ; preds = %1
store i64 2, i64* %3
br label %12
12: ; preds = %31, %11
%13 = load i64, i64* %3
%14 = load i64, i64* %3
%15 = mul nsw i64 %13, %14
%16 = load i64, i64* %2
%17 = icmp sle i64 %15, %16
br i1 %17, label %18, label %34
18: ; preds = %12
%19 = load i64, i64* %2
%20 = load i64, i64* %3
%21 = srem i64 %19, %20
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %18
%24 = load i64, i64* %3
%25 = call i64 @isprime(i64 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = load i64, i64* %3
store i64 %28, i64* %4
br label %34
29: ; preds = %23
br label %30
30: ; preds = %29, %18
br label %31
31: ; preds = %30
%32 = load i64, i64* %3
%33 = add nsw i64 %32, 1
store i64 %33, i64* %3
br label %12
34: ; preds = %27, %12
br label %35
35: ; preds = %34, %9
%36 = load i64, i64* %4
ret i64 %36
}

LLVM IR (-O2):
define i64 @least_pf(i64 %0) {
%2 = tail call i64 @isprime(i64 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %17
4: ; preds = %1
%5 = icmp slt i64 %0, 4
br i1 %5, label %17, label %6
6: ; preds = %4, %13
%7 = phi i64 [ %14, %13 ], [ 2, %4 ]
%8 = srem i64 %0, %7
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = tail call i64 @isprime(i64 %7)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %6, %10
%14 = add nuw nsw i64 %7, 1
%15 = mul nsw i64 %14, %14
%16 = icmp sgt i64 %15, %0
br i1 %16, label %17, label %6
17: ; preds = %13, %10, %4, %1
%18 = phi i64 [ %0, %1 ], [ undef, %4 ], [ %7, %10 ], [ %7, %13 ]
ret i64 %18
}