unsigned int spaced_primes_closest(unsigned int num) {
  static const unsigned int primes[] = {
      11,      19,      37,      73,      109,     163,     251,
      367,     557,     823,     1237,    1861,    2777,    4177,
      6247,    9371,    14057,   21089,   31627,   47431,   71143,
      106721,  160073,  240101,  360163,  540217,  810343,  1215497,
      1823231, 2734867, 4102283, 6153409, 9230113, 13845163};
  static const unsigned int nprimes = sizeof(primes) / sizeof(primes[0]);
  unsigned int i;
  for (i = 0; i < nprimes; i++)
    if (primes[i] > num)
      return primes[i];
  return primes[nprimes - 1];
}


x86 assembly (clang, -O0):
<spaced_primes_closest>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x22,-0xc(%rbp)
jae    115a <spaced_primes_closest+0x5a>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
lea    0xedc(%rip),%rax
mov    (%rax,%rcx,4),%eax
cmp    -0x8(%rbp),%eax
jbe    1147 <spaced_primes_closest+0x47>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
lea    0xec4(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x4(%rbp)
jmp    1163 <spaced_primes_closest+0x63>
jmp    114c <spaced_primes_closest+0x4c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    110e <spaced_primes_closest+0xe>
mov    0xf24(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<spaced_primes_closest>:
mov    $0x1,%ecx
lea    0xef4(%rip),%rdx
nopl   0x0(%rax)
mov    -0x4(%rdx,%rcx,4),%eax
cmp    %edi,%eax
ja     112e <spaced_primes_closest+0x2e>
mov    (%rdx,%rcx,4),%eax
cmp    %edi,%eax
ja     112e <spaced_primes_closest+0x2e>
add    $0x2,%rcx
cmp    $0x23,%rcx
jne    1110 <spaced_primes_closest+0x10>
mov    $0xd342ab,%eax
ret

LLVM IR (-O0):
@spaced_primes_closest.primes = internal constant [34 x i32] [i32 11, i32 19, i32 37, i32 73, i32 109, i32 163, i32 251, i32 367, i32 557, i32 823, i32 1237, i32 1861, i32 2777, i32 4177, i32 6247, i32 9371, i32 14057, i32 21089, i32 31627, i32 47431, i32 71143, i32 106721, i32 160073, i32 240101, i32 360163, i32 540217, i32 810343, i32 1215497, i32 1823231, i32 2734867, i32 4102283, i32 6153409, i32 9230113, i32 13845163]
@spaced_primes_closest.nprimes = internal constant i32 34
define i32 @spaced_primes_closest(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %21, %1
%6 = load i32, i32* %4
%7 = icmp ult i32 %6, 34
br i1 %7, label %8, label %24
8: ; preds = %5
%9 = load i32, i32* %4
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [34 x i32], [34 x i32]* @spaced_primes_closest.primes, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = load i32, i32* %3
%14 = icmp ugt i32 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %8
%16 = load i32, i32* %4
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds [34 x i32], [34 x i32]* @spaced_primes_closest.primes, i64 0, i64 %17
%19 = load i32, i32* %18
store i32 %19, i32* %2
br label %26
20: ; preds = %8
br label %21
21: ; preds = %20
%22 = load i32, i32* %4
%23 = add i32 %22, 1
store i32 %23, i32* %4
br label %5
24: ; preds = %5
%25 = load i32, i32* getelementptr inbounds ([34 x i32], [34 x i32]* @spaced_primes_closest.primes, i64 0, i64 33)
store i32 %25, i32* %2
br label %26
26: ; preds = %24, %15
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@spaced_primes_closest.primes = internal unnamed_addr constant [34 x i32] [i32 11, i32 19, i32 37, i32 73, i32 109, i32 163, i32 251, i32 367, i32 557, i32 823, i32 1237, i32 1861, i32 2777, i32 4177, i32 6247, i32 9371, i32 14057, i32 21089, i32 31627, i32 47431, i32 71143, i32 106721, i32 160073, i32 240101, i32 360163, i32 540217, i32 810343, i32 1215497, i32 1823231, i32 2734867, i32 4102283, i32 6153409, i32 9230113, i32 13845163]
define i32 @spaced_primes_closest(i32 %0) {
br label %10
2: ; preds = %10
%3 = or i64 %11, 1
%4 = getelementptr inbounds [34 x i32], [34 x i32]* @spaced_primes_closest.primes, i64 0, i64 %3
%5 = load i32, i32* %4
%6 = icmp ugt i32 %5, %0
br i1 %6, label %15, label %7
7: ; preds = %2
%8 = add nuw nsw i64 %11, 2
%9 = icmp eq i64 %8, 34
br i1 %9, label %15, label %10
10: ; preds = %7, %1
%11 = phi i64 [ 0, %1 ], [ %8, %7 ]
%12 = getelementptr inbounds [34 x i32], [34 x i32]* @spaced_primes_closest.primes, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = icmp ugt i32 %13, %0
br i1 %14, label %15, label %2
15: ; preds = %7, %2, %10
%16 = phi i32 [ %13, %10 ], [ %5, %2 ], [ 13845163, %7 ]
ret i32 %16
}