#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 */
double brun_constant(int *, int);
int /*<<< orphan*/ printf(char *, int, double);
int /*<<< orphan*/ sieve(int *, int);
int twin_primes(int *, int);
int main(void) {
  int array[10001], count = 0, i;
  double bruns;
  sieve(array, 10001 - 1);
  for (i = 0; i < 10001; i++) {
    if (array[i] == 1) {
      count++;
      printf("Prime #%04i:  %4i\n", count, i);
    }
  }
  printf("%i primes found between 0 and %i.\n", count, 10001 - 1);
  count = twin_primes(array, 10001 - 1);
  printf("%i twin primes found between 0 and %i.\n", count, 10001 - 1);
  bruns = brun_constant(array, 10001 - 1);
  printf("Brun's constant with %i twin primes is %1.12f.\n", count, bruns);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x9c54(%rbp)
lea    -0x9c50(%rbp),%rdi
mov    $0x2710,%esi
call   1060 <sieve@plt>
movl   $0x0,-0x9c58(%rbp)
cmpl   $0x2711,-0x9c58(%rbp)
jge    11de <main+0x9e>
movslq -0x9c58(%rbp),%rax
cmpl   $0x1,-0x9c50(%rbp,%rax,4)
01
jne    11c5 <main+0x85>
mov    -0x9c54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c54(%rbp)
mov    -0x9c54(%rbp),%esi
cvtsi2sdl -0x9c58(%rbp),%xmm0
ff
lea    0xe48(%rip),%rdi
call   1050 <printf@plt>
jmp    11ca <main+0x8a>
mov    -0x9c58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c58(%rbp)
jmp    1177 <main+0x37>
mov    -0x9c54(%rbp),%esi
lea    0xe30(%rip),%rdi
movsd  0xe0d(%rip),%xmm0
call   1050 <printf@plt>
lea    -0x9c50(%rbp),%rdi
mov    $0x2710,%esi
call   1030 <twin_primes@plt>
mov    %eax,-0x9c54(%rbp)
mov    -0x9c54(%rbp),%esi
lea    0xe22(%rip),%rdi
movsd  0xddc(%rip),%xmm0
call   1050 <printf@plt>
lea    -0x9c50(%rbp),%rdi
mov    $0x2710,%esi
call   1040 <brun_constant@plt>
movsd  %xmm0,-0x9c60(%rbp)
ff
mov    -0x9c54(%rbp),%esi
movsd  -0x9c60(%rbp),%xmm0
ff
lea    0xe0f(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x9c60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x9c50,%rsp
mov    %rsp,%rdi
mov    $0x2710,%esi
call   1060 <sieve@plt>
xor    %ebp,%ebp
lea    0xea7(%rip),%r14
xor    %ebx,%ebx
jmp    117d <main+0x3d>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbp
cmp    $0x2711,%rbp
je     1199 <main+0x59>
cmpl   $0x1,(%rsp,%rbp,4)
jne    1170 <main+0x30>
add    $0x1,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
jmp    1170 <main+0x30>
lea    0xe7b(%rip),%rdi
movsd  0xe58(%rip),%xmm0
mov    %ebx,%esi
call   1050 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x2710,%esi
call   1030 <twin_primes@plt>
mov    %eax,%ebp
lea    0xe76(%rip),%rdi
mov    %eax,%esi
movsd  0xe2e(%rip),%xmm0
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x2710,%esi
call   1040 <brun_constant@plt>
lea    0xe7b(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x9c50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Prime #%04i: %4i\0A\00"
@.str.1 = [35 x i8] c"%i primes found between 0 and %i.\0A\00"
@.str.2 = [40 x i8] c"%i twin primes found between 0 and %i.\0A\00"
@.str.3 = [48 x i8] c"Brun's constant with %i twin primes is %1.12f.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10001 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
store i32 0, i32* %1
store i32 0, i32* %3
%6 = getelementptr inbounds [10001 x i32], [10001 x i32]* %2, i64 0, i64 0
%7 = call i32 @sieve(i32* %6, i32 10000)
store i32 0, i32* %4
br label %8
8: ; preds = %25, %0
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 10001
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [10001 x i32], [10001 x i32]* %2, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %24
17: ; preds = %11
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = sitofp i32 %21 to double
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %20, double %22)
br label %24
24: ; preds = %17, %11
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %8
28: ; preds = %8
%29 = load i32, i32* %3
%30 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %29, double 1.000000e+04)
%31 = getelementptr inbounds [10001 x i32], [10001 x i32]* %2, i64 0, i64 0
%32 = call i32 @twin_primes(i32* %31, i32 10000)
store i32 %32, i32* %3
%33 = load i32, i32* %3
%34 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %33, double 1.000000e+04)
%35 = getelementptr inbounds [10001 x i32], [10001 x i32]* %2, i64 0, i64 0
%36 = call double @brun_constant(i32* %35, i32 10000)
store double %36, double* %5
%37 = load i32, i32* %3
%38 = load double, double* %5
%39 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i32 %37, double %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Prime #%04i: %4i\0A\00"
@.str.1 = [35 x i8] c"%i primes found between 0 and %i.\0A\00"
@.str.2 = [40 x i8] c"%i twin primes found between 0 and %i.\0A\00"
@.str.3 = [48 x i8] c"Brun's constant with %i twin primes is %1.12f.\0A\00"
define i32 @main() {
%1 = alloca [10001 x i32]
%2 = bitcast [10001 x i32]* %1 to i8*
%3 = getelementptr inbounds [10001 x i32], [10001 x i32]* %1, i64 0, i64 0
%4 = call i32 @sieve(i32* %3, i32 10000)
br label %5
5: ; preds = %0, %16
%6 = phi i64 [ 0, %0 ], [ %18, %16 ]
%7 = phi i32 [ 0, %0 ], [ %17, %16 ]
%8 = getelementptr inbounds [10001 x i32], [10001 x i32]* %1, i64 0, i64 %6
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %5
%12 = add nsw i32 %7, 1
%13 = trunc i64 %6 to i32
%14 = sitofp i32 %13 to double
%15 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %12, double %14)
br label %16
16: ; preds = %5, %11
%17 = phi i32 [ %12, %11 ], [ %7, %5 ]
%18 = add nuw nsw i64 %6, 1
%19 = icmp eq i64 %18, 10001
br i1 %19, label %20, label %5
20: ; preds = %16
%21 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %17, double 1.000000e+04)
%22 = call i32 @twin_primes(i32* %3, i32 10000)
%23 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %22, double 1.000000e+04)
%24 = call double @brun_constant(i32* %3, i32 10000)
%25 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i32 %22, double %24)
ret i32 0
}