#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_trunctable_prime(int *, int);
int /*<<< orphan*/ sieve(int *, int);
int solve() {
  bool prime[1000000];
  sieve(prime, 1000000);
  int count = 0, sum = 0;
  int i = 10;
  while (count < 11) {
    if (is_trunctable_prime(prime, i)) {
      sum += i;
      ++count;
    }
    ++i;
  }
  return sum;
}


x86 assembly (clang, -O0):
<solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3d0910,%rsp
lea    -0x3d0900(%rbp),%rdi
mov    $0xf4240,%esi
call   1030 <sieve@plt>
movl   $0x0,-0x3d0904(%rbp)
movl   $0x0,-0x3d0908(%rbp)
movl   $0xa,-0x3d090c(%rbp)
cmpl   $0xb,-0x3d0904(%rbp)
jge    11b8 <solve+0x98>
lea    -0x3d0900(%rbp),%rdi
mov    -0x3d090c(%rbp),%esi
call   1040 <is_trunctable_prime@plt>
cmp    $0x0,%rax
je     11a4 <solve+0x84>
mov    -0x3d090c(%rbp),%eax
add    -0x3d0908(%rbp),%eax
mov    %eax,-0x3d0908(%rbp)
mov    -0x3d0904(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0904(%rbp)
mov    -0x3d090c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d090c(%rbp)
jmp    115a <solve+0x3a>
mov    -0x3d0908(%rbp),%eax
add    $0x3d0910,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3d0900,%rsp
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xf4240,%esi
call   1030 <sieve@plt>
xor    %r15d,%r15d
mov    $0xa,%ebx
xor    %r12d,%r12d
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <is_trunctable_prime@plt>
lea    0x1(%rbx),%ecx
xor    %edx,%edx
test   %rax,%rax
cmove  %r15d,%ebx
setne  %dl
add    %edx,%ebp
add    %ebx,%r12d
mov    %ecx,%ebx
cmp    $0xb,%ebp
jb     1150 <solve+0x30>
mov    %r12d,%eax
add    $0x3d0900,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @solve() {
%1 = alloca [1000000 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 0
%6 = call i32 @sieve(i32* %5, i32 1000000)
store i32 0, i32* %2
store i32 0, i32* %3
store i32 10, i32* %4
br label %7
7: ; preds = %21, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 11
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 0
%12 = load i32, i32* %4
%13 = call i64 @is_trunctable_prime(i32* %11, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load i32, i32* %4
%17 = load i32, i32* %3
%18 = add nsw i32 %17, %16
store i32 %18, i32* %3
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %21
21: ; preds = %15, %10
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %7
24: ; preds = %7
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
define i32 @solve() {
%1 = alloca [1000000 x i32]
%2 = bitcast [1000000 x i32]* %1 to i8*
%3 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 0
%4 = call i32 @sieve(i32* %3, i32 1000000)
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 10, %0 ], [ %11, %5 ]
%7 = phi i32 [ 0, %0 ], [ %16, %5 ]
%8 = phi i32 [ 0, %0 ], [ %14, %5 ]
%9 = call i64 @is_trunctable_prime(i32* %3, i32 %6)
%10 = icmp eq i64 %9, 0
%11 = add nuw nsw i32 %6, 1
%12 = xor i1 %10, true
%13 = zext i1 %12 to i32
%14 = add nuw nsw i32 %8, %13
%15 = select i1 %10, i32 0, i32 %6
%16 = add nuw nsw i32 %15, %7
%17 = icmp ult i32 %14, 11
br i1 %17, label %5, label %18
18: ; preds = %5
ret i32 %16
}