#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 atoi(char *);
int count_representation_combinations_(int *, size_t, int,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(int *);
int *primes_under(int /*<<< orphan*/ *, int, size_t *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "usage: %s <N>\n", argv[0]);
    return 1;
  }
  int N = atoi(argv[1]);
  if (N <= 0)
    return 1;
  int upper_bound = 2 * N;
  size_t primes_count = 0;
  int *primes = primes_under(NULL, upper_bound + 1, &primes_count);
  int sum = 2;
  while (count_representation_combinations_(primes, primes_count - 1, sum,
                                            NULL) < N)
    sum++;
  printf("%d\n", sum);
  free(primes);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a8 <main+0x48>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124b <main+0xeb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     11ce <main+0x6e>
movl   $0x1,-0x4(%rbp)
jmp    124b <main+0xeb>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%esi
add    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x20(%rbp),%rdx
call   1040 <primes_under@plt>
mov    %rax,-0x28(%rbp)
movl   $0x2,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x2c(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <count_representation_combinations_@plt>
cmp    -0x14(%rbp),%eax
jge    122c <main+0xcc>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11fd <main+0x9d>
mov    -0x2c(%rbp),%esi
lea    0xdd9(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11e7 <main+0x87>
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
test   %eax,%eax
jle    11ff <main+0x9f>
mov    %eax,%r14d
movq   $0x0,0x8(%rsp)
lea    (%r14,%r14,1),%esi
add    $0x1,%esi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1040 <primes_under@plt>
mov    %rax,%rbx
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
mov    0x8(%rsp),%rsi
add    $0xffffffffffffffff,%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1070 <count_representation_combinations_@plt>
cmp    %r14d,%eax
jl     11b0 <main+0x50>
lea    0xe3b(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1204 <main+0xa4>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe06(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"usage: %s <N>\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %49
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp sle i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 1, i32* %3
br label %49
27: ; preds = %19
%28 = load i32, i32* %6
%29 = mul nsw i32 2, %28
store i32 %29, i32* %7
store i64 0, i64* %8
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
%32 = call i32* @primes_under(i32* null, i32 %31, i64* %8)
store i32* %32, i32** %9
store i32 2, i32* %10
br label %33
33: ; preds = %41, %27
%34 = load i32*, i32** %9
%35 = load i64, i64* %8
%36 = sub i64 %35, 1
%37 = load i32, i32* %10
%38 = call i32 @count_representation_combinations_(i32* %34, i64 %36, i32 %37, i32* null)
%39 = load i32, i32* %6
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %44
41: ; preds = %33
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %33
44: ; preds = %33
%45 = load i32, i32* %10
%46 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %45)
%47 = load i32*, i32** %9
%48 = call i32 @free(i32* %47)
store i32 0, i32* %3
br label %49
49: ; preds = %44, %26, %13
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"usage: %s <N>\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %29
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp slt i32 %12, 1
br i1 %13, label %29, label %14
14: ; preds = %9
%15 = shl nuw nsw i32 %12, 1
%16 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%17 = or i32 %15, 1
%18 = call i32* @primes_under(i32* null, i32 %17, i64* %3)
br label %19
19: ; preds = %19, %14
%20 = phi i32 [ 2, %14 ], [ %25, %19 ]
%21 = load i64, i64* %3
%22 = add i64 %21, -1
%23 = call i32 @count_representation_combinations_(i32* %18, i64 %22, i32 %20, i32* null)
%24 = icmp slt i32 %23, %12
%25 = add nuw nsw i32 %20, 1
br i1 %24, label %19, label %26
26: ; preds = %19
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%28 = call i32 @free(i32* %18)
br label %29
29: ; preds = %26, %9, %5
%30 = phi i32 [ 1, %5 ], [ 0, %26 ], [ 1, %9 ]
ret i32 %30
}