#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 /*<<< orphan*/ is_odd_prime(int);
int ethash_find_largest_prime(int upper_bound) {
  int n = upper_bound;
  if (n < 2)
    return 0;
  if (n == 2)
    return 2;
  if (n % 2 == 0)
    --n;
  while (!is_odd_prime(n))
    n -= 2;
  return n;
}


x86 assembly (clang, -O0):
<ethash_find_largest_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    1137 <ethash_find_largest_prime+0x27>
movl   $0x0,-0x4(%rbp)
jmp    11a0 <ethash_find_largest_prime+0x90>
cmpl   $0x2,-0xc(%rbp)
jne    114d <ethash_find_largest_prime+0x3d>
movl   $0x2,-0x4(%rbp)
jmp    11a0 <ethash_find_largest_prime+0x90>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    116a <ethash_find_largest_prime+0x5a>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    116f <ethash_find_largest_prime+0x5f>
mov    -0xc(%rbp),%edi
call   1030 <is_odd_prime@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    118c <ethash_find_largest_prime+0x7c>
jmp    119a <ethash_find_largest_prime+0x8a>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    116f <ethash_find_largest_prime+0x5f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ethash_find_largest_prime>:
push   %rbx
xor    %ebx,%ebx
cmp    $0x2,%edi
jl     113e <ethash_find_largest_prime+0x2e>
mov    $0x2,%ebx
je     113e <ethash_find_largest_prime+0x2e>
mov    %edi,%eax
and    $0x1,%eax
lea    (%rdi,%rax,1),%ebx
add    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
add    $0xfffffffe,%ebx
mov    %ebx,%edi
call   1030 <is_odd_prime@plt>
test   %eax,%eax
je     1130 <ethash_find_largest_prime+0x20>
mov    %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @ethash_find_largest_prime(i32 %0) {
%2 = icmp slt i32 %0, 2
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = icmp eq i32 %0, 2
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = and i32 %0, 1
%7 = add nsw i32 %0, -1
%8 = add nuw nsw i32 %7, %6
br label %9
9: ; preds = %9, %5
%10 = phi i32 [ %8, %5 ], [ %13, %9 ]
%11 = tail call i32 @is_odd_prime(i32 %10)
%12 = icmp eq i32 %11, 0
%13 = add nsw i32 %10, -2
br i1 %12, label %9, label %14
14: ; preds = %9, %3, %1
%15 = phi i32 [ 0, %1 ], [ 2, %3 ], [ %10, %9 ]
ret i32 %15
}