#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 sqrt(long);
long get_prev_prime(long n) {
  int i;
  n = (n - 1) | 1;
  while (n > 0) {
    i = 3;
    while (i && i <= sqrt(n)) {
      if (n % i == 0)
        i = 0;
      else
        i += 2;
    }
    if (i)
      return (n);
    n -= 2;
  }
  return (n);
}


x86 assembly (clang, -O0):
<get_prev_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
or     $0x1,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    11d2 <get_prev_prime+0xc2>
movl   $0x3,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x15(%rbp)
je     1169 <get_prev_prime+0x59>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
setle  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1179 <get_prev_prime+0x69>
jmp    11aa <get_prev_prime+0x9a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    119c <get_prev_prime+0x8c>
movl   $0x0,-0x14(%rbp)
jmp    11a5 <get_prev_prime+0x95>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <get_prev_prime+0x2e>
cmpl   $0x0,-0x14(%rbp)
je     11c1 <get_prev_prime+0xb1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11da <get_prev_prime+0xca>
mov    -0x10(%rbp),%rax
sub    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    112c <get_prev_prime+0x1c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_prev_prime>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
or     $0x1,%rbx
jle    118f <get_prev_prime+0x7f>
mov    $0x3,%ebp
jmp    1136 <get_prev_prime+0x26>
nopw   0x0(%rax,%rax,1)
mov    %eax,%ebp
test   %eax,%eax
je     1180 <get_prev_prime+0x70>
mov    %rbx,%rdi
call   1030 <sqrt@plt>
cmp    %eax,%ebp
jg     118f <get_prev_prime+0x7f>
movslq %ebp,%rcx
mov    %rbx,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1160 <get_prev_prime+0x50>
mov    %rbx,%rax
cqto
idiv   %rcx
jmp    1166 <get_prev_prime+0x56>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
xor    %eax,%eax
test   %rdx,%rdx
je     1130 <get_prev_prime+0x20>
add    $0x2,%ebp
mov    %ebp,%eax
jmp    1130 <get_prev_prime+0x20>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    -0x2(%rbx),%rax
cmp    $0x2,%rbx
mov    %rax,%rbx
jg     1120 <get_prev_prime+0x10>
jmp    1192 <get_prev_prime+0x82>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i64 @get_prev_prime(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = sub nsw i64 %5, 1
%7 = or i64 %6, 1
store i64 %7, i64* %3
br label %8
8: ; preds = %38, %1
%9 = load i64, i64* %3
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %41
11: ; preds = %8
store i32 3, i32* %4
br label %12
12: ; preds = %32, %11
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* %4
%17 = load i64, i64* %3
%18 = call i32 @sqrt(i64 %17)
%19 = icmp sle i32 %16, %18
br label %20
20: ; preds = %15, %12
%21 = phi i1 [ false, %12 ], [ %19, %15 ]
br i1 %21, label %22, label %33
22: ; preds = %20
%23 = load i64, i64* %3
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = srem i64 %23, %25
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 0, i32* %4
br label %32
29: ; preds = %22
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 2
store i32 %31, i32* %4
br label %32
32: ; preds = %29, %28
br label %12
33: ; preds = %20
%34 = load i32, i32* %4
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = load i64, i64* %3
store i64 %37, i64* %2
br label %43
38: ; preds = %33
%39 = load i64, i64* %3
%40 = sub nsw i64 %39, 2
store i64 %40, i64* %3
br label %8
41: ; preds = %8
%42 = load i64, i64* %3
store i64 %42, i64* %2
br label %43
43: ; preds = %41, %36
%44 = load i64, i64* %2
ret i64 %44
}

LLVM IR (-O2):
define i64 @get_prev_prime(i64 %0) {
%2 = add nsw i64 %0, -1
%3 = or i64 %2, 1
%4 = icmp sgt i64 %3, 0
br i1 %4, label %5, label %21
5: ; preds = %1, %18
%6 = phi i64 [ %19, %18 ], [ %3, %1 ]
br label %7
7: ; preds = %5, %11
%8 = phi i32 [ 3, %5 ], [ %16, %11 ]
%9 = tail call i32 @sqrt(i64 %6)
%10 = icmp sgt i32 %8, %9
br i1 %10, label %21, label %11
11: ; preds = %7
%12 = sext i32 %8 to i64
%13 = srem i64 %6, %12
%14 = icmp eq i64 %13, 0
%15 = add nsw i32 %8, 2
%16 = select i1 %14, i32 0, i32 %15
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %7
18: ; preds = %11
%19 = add nsw i64 %6, -2
%20 = icmp sgt i64 %6, 2
br i1 %20, label %5, label %21
21: ; preds = %18, %7, %1
%22 = phi i64 [ %3, %1 ], [ %6, %7 ], [ %19, %18 ]
ret i64 %22
}