#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 */
typedef int /*<<< orphan*/ primes;

/* Variables and functions */
int /*<<< orphan*/ is_prime(size_t);
size_t snap_to_prime(size_t x) {
  size_t primes[] = {5,      11,     23,     47,     97,      197,     397,
                     797,    1597,   3203,   6421,   12853,   25717,   51437,
                     102877, 205759, 411527, 823117, 1646237, 3292489, 6584983};
  for (size_t i = 0; i < sizeof(primes) / sizeof(size_t); i++) {
    if (primes[i] >= x)
      return primes[i];
  }
  x |= 1;
  while (!is_prime(x))
    x += 2;
  return x;
}


x86 assembly (clang, -O0):
<snap_to_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0xc0(%rbp),%rdi
lea    0xec3(%rip),%rsi
mov    $0xa8,%edx
call   1030 <memcpy@plt>
movq   $0x0,-0xc8(%rbp)
cmpq   $0x15,-0xc8(%rbp)
15
jae    11ad <snap_to_prime+0x8d>
mov    -0xc8(%rbp),%rax
mov    -0xc0(%rbp,%rax,8),%rax
ff
cmp    -0x10(%rbp),%rax
jb     1191 <snap_to_prime+0x71>
mov    -0xc8(%rbp),%rax
mov    -0xc0(%rbp,%rax,8),%rax
ff
mov    %rax,-0x8(%rbp)
jmp    11f0 <snap_to_prime+0xd0>
jmp    1196 <snap_to_prime+0x76>
mov    -0xc8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xc8(%rbp)
jmp    1152 <snap_to_prime+0x32>
mov    -0x10(%rbp),%rax
or     $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <is_prime@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d7 <snap_to_prime+0xb7>
jmp    11e8 <snap_to_prime+0xc8>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    11b9 <snap_to_prime+0x99>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snap_to_prime>:
push   %rbx
mov    $0x5,%eax
cmp    $0x6,%rdi
jb     127a <snap_to_prime+0x16a>
mov    %rdi,%rbx
mov    $0xb,%eax
cmp    $0xc,%rdi
jb     127a <snap_to_prime+0x16a>
mov    $0x17,%eax
cmp    $0x18,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0x2f,%eax
cmp    $0x30,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0x61,%eax
cmp    $0x62,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0xc5,%eax
cmp    $0xc6,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0x18d,%eax
cmp    $0x18e,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0x31d,%eax
cmp    $0x31e,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0x63d,%eax
cmp    $0x63e,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0xc83,%eax
cmp    $0xc84,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0x1915,%eax
cmp    $0x1916,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0x3235,%eax
cmp    $0x3236,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0x6475,%eax
cmp    $0x6476,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0xc8ed,%eax
cmp    $0xc8ee,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0x191dd,%eax
cmp    $0x191de,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0x323bf,%eax
cmp    $0x323c0,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0x64787,%eax
cmp    $0x64788,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0xc8f4d,%eax
cmp    $0xc8f4e,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0x191e9d,%eax
cmp    $0x191e9e,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0x323d49,%eax
cmp    $0x323d4a,%rbx
jb     127a <snap_to_prime+0x16a>
mov    $0x647a97,%eax
cmp    $0x647a98,%rbx
jb     127a <snap_to_prime+0x16a>
or     $0x1,%rbx
mov    %rbx,%rdi
call   1030 <is_prime@plt>
add    $0x2,%rbx
test   %eax,%eax
je     1263 <snap_to_prime+0x153>
add    $0xfffffffffffffffe,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@__const.snap_to_prime.primes = [21 x i64] [i64 5, i64 11, i64 23, i64 47, i64 97, i64 197, i64 397, i64 797, i64 1597, i64 3203, i64 6421, i64 12853, i64 25717, i64 51437, i64 102877, i64 205759, i64 411527, i64 823117, i64 1646237, i64 3292489, i64 6584983]
define i64 @snap_to_prime(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca [21 x i64]
%5 = alloca i64
store i64 %0, i64* %3
%6 = bitcast [21 x i64]* %4 to i8*
store i64 0, i64* %5
br label %7
7: ; preds = %21, %1
%8 = load i64, i64* %5
%9 = icmp ult i64 %8, 21
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = load i64, i64* %5
%12 = getelementptr inbounds [21 x i64], [21 x i64]* %4, i64 0, i64 %11
%13 = load i64, i64* %12
%14 = load i64, i64* %3
%15 = icmp uge i64 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load i64, i64* %5
%18 = getelementptr inbounds [21 x i64], [21 x i64]* %4, i64 0, i64 %17
%19 = load i64, i64* %18
store i64 %19, i64* %2
br label %37
20: ; preds = %10
br label %21
21: ; preds = %20
%22 = load i64, i64* %5
%23 = add i64 %22, 1
store i64 %23, i64* %5
br label %7
24: ; preds = %7
%25 = load i64, i64* %3
%26 = or i64 %25, 1
store i64 %26, i64* %3
br label %27
27: ; preds = %32, %24
%28 = load i64, i64* %3
%29 = call i32 @is_prime(i64 %28)
%30 = icmp ne i32 %29, 0
%31 = xor i1 %30, true
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i64, i64* %3
%34 = add i64 %33, 2
store i64 %34, i64* %3
br label %27
35: ; preds = %27
%36 = load i64, i64* %3
store i64 %36, i64* %2
br label %37
37: ; preds = %35, %16
%38 = load i64, i64* %2
ret i64 %38
}

LLVM IR (-O2):
define i64 @snap_to_prime(i64 %0) {
%2 = icmp ugt i64 %0, 5
br i1 %2, label %3, label %50
3: ; preds = %1
%4 = icmp ugt i64 %0, 11
br i1 %4, label %5, label %50
5: ; preds = %3
%6 = icmp ugt i64 %0, 23
br i1 %6, label %7, label %50
7: ; preds = %5
%8 = icmp ugt i64 %0, 47
br i1 %8, label %9, label %50
9: ; preds = %7
%10 = icmp ugt i64 %0, 97
br i1 %10, label %11, label %50
11: ; preds = %9
%12 = icmp ugt i64 %0, 197
br i1 %12, label %13, label %50
13: ; preds = %11
%14 = icmp ugt i64 %0, 397
br i1 %14, label %15, label %50
15: ; preds = %13
%16 = icmp ugt i64 %0, 797
br i1 %16, label %17, label %50
17: ; preds = %15
%18 = icmp ugt i64 %0, 1597
br i1 %18, label %19, label %50
19: ; preds = %17
%20 = icmp ugt i64 %0, 3203
br i1 %20, label %21, label %50
21: ; preds = %19
%22 = icmp ugt i64 %0, 6421
br i1 %22, label %23, label %50
23: ; preds = %21
%24 = icmp ugt i64 %0, 12853
br i1 %24, label %25, label %50
25: ; preds = %23
%26 = icmp ugt i64 %0, 25717
br i1 %26, label %27, label %50
27: ; preds = %25
%28 = icmp ugt i64 %0, 51437
br i1 %28, label %29, label %50
29: ; preds = %27
%30 = icmp ugt i64 %0, 102877
br i1 %30, label %31, label %50
31: ; preds = %29
%32 = icmp ugt i64 %0, 205759
br i1 %32, label %33, label %50
33: ; preds = %31
%34 = icmp ugt i64 %0, 411527
br i1 %34, label %35, label %50
35: ; preds = %33
%36 = icmp ugt i64 %0, 823117
br i1 %36, label %37, label %50
37: ; preds = %35
%38 = icmp ugt i64 %0, 1646237
br i1 %38, label %39, label %50
39: ; preds = %37
%40 = icmp ugt i64 %0, 3292489
br i1 %40, label %41, label %50
41: ; preds = %39
%42 = icmp ugt i64 %0, 6584983
br i1 %42, label %43, label %50
43: ; preds = %41
%44 = or i64 %0, 1
br label %45
45: ; preds = %45, %43
%46 = phi i64 [ %44, %43 ], [ %49, %45 ]
%47 = tail call i32 @is_prime(i64 %46)
%48 = icmp eq i32 %47, 0
%49 = add i64 %46, 2
br i1 %48, label %45, label %50
50: ; preds = %45, %1, %3, %5, %7, %9, %11, %13, %15, %17, %19, %21, %23, %25, %27, %29, %31, %33, %35, %37, %39, %41
%51 = phi i64 [ 5, %1 ], [ 11, %3 ], [ 23, %5 ], [ 47, %7 ], [ 97, %9 ], [ 197, %11 ], [ 397, %13 ], [ 797, %15 ], [ 1597, %17 ], [ 3203, %19 ], [ 6421, %21 ], [ 12853, %23 ], [ 25717, %25 ], [ 51437, %27 ], [ 102877, %29 ], [ 205759, %31 ], [ 411527, %33 ], [ 823117, %35 ], [ 1646237, %37 ], [ 3292489, %39 ], [ 6584983, %41 ], [ %46, %45 ]
ret i64 %51
}