#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*/ free(char *);
int /*<<< orphan*/ is_prime(int);
scalar_t__ prime_backwards(char *);
scalar_t__ prime_forwards(char *);
int /*<<< orphan*/ printf(char *, float);
char *set_prime_string(int);
float timeit();
int main(int argc, char *argv[]) {
  float start = timeit();
  int prime_sum = 0;
  int primes = 11;
  for (int i = 11; primes > 0; i++) {
    if (!is_prime(i))
      continue;
    char *prime_string = set_prime_string(i);
    if (prime_forwards(prime_string) && prime_backwards(prime_string)) {
      primes--;
      prime_sum += i;
    }
    free(prime_string);
  }
  float stop = timeit();
  printf("Answer: %d\n", prime_sum);
  printf("Time: %f\n", stop - start);
  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)
mov    $0x0,%al
call   1090 <timeit@plt>
movss  %xmm0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0xb,-0x1c(%rbp)
movl   $0xb,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1222 <main+0xb2>
mov    -0x20(%rbp),%edi
call   1050 <is_prime@plt>
cmp    $0x0,%eax
jne    11c7 <main+0x57>
jmp    1214 <main+0xa4>
mov    -0x20(%rbp),%edi
call   1060 <set_prime_string@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <prime_forwards@plt>
cmp    $0x0,%rax
je     120b <main+0x9b>
mov    -0x28(%rbp),%rdi
call   1070 <prime_backwards@plt>
cmp    $0x0,%rax
je     120b <main+0x9b>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a7 <main+0x37>
mov    $0x0,%al
call   1090 <timeit@plt>
movss  %xmm0,-0x2c(%rbp)
cvtsi2ssl -0x18(%rbp),%xmm0
lea    0xdc6(%rip),%rdi
call   1040 <printf@plt>
movss  -0x2c(%rbp),%xmm0
subss  -0x14(%rbp),%xmm0
lea    0xdbc(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r15d,%r15d
xor    %eax,%eax
call   1090 <timeit@plt>
movss  %xmm0,0x4(%rsp)
mov    $0xb,%ebp
mov    $0xb,%ebx
jmp    11af <main+0x3f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x1,%ebx
test   %ebp,%ebp
jle    11e6 <main+0x76>
mov    %ebx,%edi
call   1050 <is_prime@plt>
test   %eax,%eax
je     11a8 <main+0x38>
mov    %ebx,%edi
call   1060 <set_prime_string@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <prime_forwards@plt>
test   %rax,%rax
je     11a0 <main+0x30>
mov    %r14,%rdi
call   1070 <prime_backwards@plt>
test   %rax,%rax
je     11a0 <main+0x30>
add    $0xffffffff,%ebp
add    %ebx,%r15d
jmp    11a0 <main+0x30>
xor    %eax,%eax
call   1090 <timeit@plt>
movss  %xmm0,(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %r15d,%xmm0
lea    0xdff(%rip),%rdi
call   1040 <printf@plt>
movss  (%rsp),%xmm0
subss  0x4(%rsp),%xmm0
lea    0xdf4(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Answer: %d\0A\00"
@.str.1 = [10 x i8] c"Time: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call float (...) @timeit()
store float %12, float* %6
store i32 0, i32* %7
store i32 11, i32* %8
store i32 11, i32* %9
br label %13
13: ; preds = %40, %2
%14 = load i32, i32* %8
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %43
16: ; preds = %13
%17 = load i32, i32* %9
%18 = call i32 @is_prime(i32 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %16
br label %40
21: ; preds = %16
%22 = load i32, i32* %9
%23 = call i8* @set_prime_string(i32 %22)
store i8* %23, i8** %10
%24 = load i8*, i8** %10
%25 = call i64 @prime_forwards(i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %21
%28 = load i8*, i8** %10
%29 = call i64 @prime_backwards(i8* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = load i32, i32* %8
%33 = add nsw i32 %32, -1
store i32 %33, i32* %8
%34 = load i32, i32* %9
%35 = load i32, i32* %7
%36 = add nsw i32 %35, %34
store i32 %36, i32* %7
br label %37
37: ; preds = %31, %27, %21
%38 = load i8*, i8** %10
%39 = call i32 @free(i8* %38)
br label %40
40: ; preds = %37, %20
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %13
43: ; preds = %13
%44 = call float (...) @timeit()
store float %44, float* %11
%45 = load i32, i32* %7
%46 = sitofp i32 %45 to float
%47 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), float %46)
%48 = load float, float* %11
%49 = load float, float* %6
%50 = fsub float %48, %49
%51 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), float %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"Answer: %d\0A\00"
@.str.1 = [10 x i8] c"Time: %f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call float (...) @timeit()
br label %10
4: ; preds = %30
%5 = tail call float (...) @timeit()
%6 = sitofp i32 %32 to float
%7 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), float %6)
%8 = fsub float %5, %3
%9 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), float %8)
ret i32 0
10: ; preds = %2, %30
%11 = phi i32 [ 0, %2 ], [ %32, %30 ]
%12 = phi i32 [ 11, %2 ], [ %31, %30 ]
%13 = phi i32 [ 11, %2 ], [ %33, %30 ]
%14 = tail call i32 @is_prime(i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %30, label %16
16: ; preds = %10
%17 = tail call i8* @set_prime_string(i32 %13)
%18 = tail call i64 @prime_forwards(i8* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %16
%21 = tail call i64 @prime_backwards(i8* %17)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = add nsw i32 %12, -1
%25 = add nsw i32 %11, %13
br label %26
26: ; preds = %23, %20, %16
%27 = phi i32 [ %24, %23 ], [ %12, %20 ], [ %12, %16 ]
%28 = phi i32 [ %25, %23 ], [ %11, %20 ], [ %11, %16 ]
%29 = tail call i32 @free(i8* %17)
br label %30
30: ; preds = %10, %26
%31 = phi i32 [ %27, %26 ], [ %12, %10 ]
%32 = phi i32 [ %28, %26 ], [ %11, %10 ]
%33 = add nuw nsw i32 %13, 1
%34 = icmp sgt i32 %31, 0
br i1 %34, label %10, label %4
}