#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__ is_prime(long);
long prev_prime(long n) {
  if (n <= 2) {
    return 0;
  } else if (n == 3) {
    return 2;
  } else if (0 == n % 2) {
    if (is_prime(n - 1)) {
      return n - 1;
    } else {
      return prev_prime(n - 1);
    }
  } else {
    if (is_prime(n - 2)) {
      return n - 2;
    } else {
      return prev_prime(n - 2);
    }
  }
}


x86 assembly (clang, -O0):
<prev_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x2,-0x10(%rbp)
jg     1144 <prev_prime+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11ec <prev_prime+0xcc>
cmpq   $0x3,-0x10(%rbp)
jne    115c <prev_prime+0x3c>
movq   $0x2,-0x8(%rbp)
jmp    11ec <prev_prime+0xcc>
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
xor    %eax,%eax
cmp    %rdx,%rax
jne    11b3 <prev_prime+0x93>
mov    -0x10(%rbp),%rdi
sub    $0x1,%rdi
call   1030 <is_prime@plt>
cmp    $0x0,%rax
je     119d <prev_prime+0x7d>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11ec <prev_prime+0xcc>
mov    -0x10(%rbp),%rdi
sub    $0x1,%rdi
call   1040 <prev_prime@plt>
mov    %rax,-0x8(%rbp)
jmp    11ec <prev_prime+0xcc>
mov    -0x10(%rbp),%rdi
sub    $0x2,%rdi
call   1030 <is_prime@plt>
cmp    $0x0,%rax
je     11db <prev_prime+0xbb>
mov    -0x10(%rbp),%rax
sub    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    11ec <prev_prime+0xcc>
mov    -0x10(%rbp),%rdi
sub    $0x2,%rdi
call   1040 <prev_prime@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prev_prime>:
push   %rbx
cmp    $0x3,%rdi
jl     1157 <prev_prime+0x47>
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
cmp    $0x3,%rbx
je     115e <prev_prime+0x4e>
test   $0x1,%bl
jne    1140 <prev_prime+0x30>
add    $0xffffffffffffffff,%rbx
jmp    1144 <prev_prime+0x34>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xfffffffffffffffe,%rbx
mov    %rbx,%rdi
call   1030 <is_prime@plt>
test   %rax,%rax
jne    1159 <prev_prime+0x49>
cmp    $0x3,%rbx
jae    1120 <prev_prime+0x10>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret
mov    $0x2,%ebx
jmp    1159 <prev_prime+0x49>

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

LLVM IR (-O2):
define i64 @prev_prime(i64 %0) {
%2 = icmp slt i64 %0, 3
br i1 %2, label %20, label %3
3: ; preds = %1, %13
%4 = phi i64 [ %14, %13 ], [ %0, %1 ]
%5 = icmp eq i64 %4, 3
br i1 %5, label %20, label %6
6: ; preds = %3
%7 = and i64 %4, 1
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = add nsw i64 %4, -1
%11 = tail call i64 @is_prime(i64 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %9, %16
%14 = phi i64 [ %10, %9 ], [ %17, %16 ]
%15 = icmp ult i64 %14, 3
br i1 %15, label %20, label %3
16: ; preds = %6
%17 = add nsw i64 %4, -2
%18 = tail call i64 @is_prime(i64 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %13, label %20
20: ; preds = %13, %3, %9, %16, %1
%21 = phi i64 [ 0, %1 ], [ %17, %16 ], [ %10, %9 ], [ 2, %3 ], [ 0, %13 ]
ret i64 %21
}