#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(int *);
int /*<<< orphan*/ generate_eratosthenes(int, int *);
int /*<<< orphan*/ generate_primes_window(int, int, int *);
scalar_t__ is_it_prime_eratosthenes(int, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int n;
  int start = 100, end = 200;
  int max = 1000;
  int found = 0;
  bool *primes = (bool *)malloc(max * 8 * sizeof(bool));
  generate_eratosthenes(max * 8, primes);
  printf("list %d first primes:\n", max);
  for (n = 1; found < max; n++) {
    if (is_it_prime_eratosthenes(n, primes)) {
      printf("%d ", n);
      found++;
    }
  }
  printf("\n");
  bool *window = (bool *)malloc((end - start) * sizeof(bool));
  generate_primes_window(start, end, window);
  printf("The window %d to %d has the following primes:\n", start, end);
  for (int i = start; i < end; i++) {
    if (window[i - start])
      printf("%d ", i);
  }
  printf("\n");
  free(primes);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0xc(%rbp)
movl   $0xc8,-0x10(%rbp)
movl   $0x3e8,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x3,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
shl    $0x3,%edi
mov    -0x20(%rbp),%rsi
call   1030 <generate_eratosthenes@plt>
mov    -0x14(%rbp),%esi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1218 <main+0xb8>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1050 <is_it_prime_eratosthenes@plt>
cmp    $0x0,%rax
je     1205 <main+0xa5>
mov    -0x8(%rbp),%esi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    120a <main+0xaa>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c9 <main+0x69>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1080 <generate_primes_window@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12ad <main+0x14d>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     129a <main+0x13a>
mov    -0x2c(%rbp),%esi
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    129f <main+0x13f>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1266 <main+0x106>
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@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
mov    $0x7d00,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    $0x1f40,%edi
mov    %rax,%rsi
call   1030 <generate_eratosthenes@plt>
lea    0xe68(%rip),%rdi
mov    $0x3e8,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%ebx
lea    0xe67(%rip),%r15
xor    %ebp,%ebp
jmp    11cb <main+0x5b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebx
cmp    $0x3e8,%ebp
jge    11eb <main+0x7b>
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <is_it_prime_eratosthenes@plt>
test   %rax,%rax
je     11c0 <main+0x50>
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%ebp
jmp    11c0 <main+0x50>
mov    $0xa,%edi
call   1050 <putchar@plt>
mov    $0x190,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    $0x64,%edi
mov    $0xc8,%esi
mov    %rax,%rdx
call   1090 <generate_primes_window@plt>
lea    0xe00(%rip),%rdi
mov    $0x64,%esi
mov    $0xc8,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xde4(%rip),%r15
xor    %ebp,%ebp
jmp    124a <main+0xda>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    $0x64,%rbp
je     125f <main+0xef>
cmpl   $0x0,(%rbx,%rbp,4)
je     1240 <main+0xd0>
lea    0x64(%rbp),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1240 <main+0xd0>
mov    $0xa,%edi
call   1050 <putchar@plt>
mov    %r14,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"list %d first primes:\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [47 x i8] c"The window %d to %d has the following primes:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %1
store i32 100, i32* %3
store i32 200, i32* %4
store i32 1000, i32* %5
store i32 0, i32* %6
%10 = load i32, i32* %5
%11 = mul nsw i32 %10, 8
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 4
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i32*
store i32* %16, i32** %7
%17 = load i32, i32* %5
%18 = mul nsw i32 %17, 8
%19 = load i32*, i32** %7
%20 = call i32 @generate_eratosthenes(i32 %18, i32* %19)
%21 = load i32, i32* %5
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 1, i32* %2
br label %23
23: ; preds = %38, %0
%24 = load i32, i32* %6
%25 = load i32, i32* %5
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %41
27: ; preds = %23
%28 = load i32, i32* %2
%29 = load i32*, i32** %7
%30 = call i64 @is_it_prime_eratosthenes(i32 %28, i32* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i32, i32* %2
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %37
37: ; preds = %32, %27
br label %38
38: ; preds = %37
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
br label %23
41: ; preds = %23
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* %4
%44 = load i32, i32* %3
%45 = sub nsw i32 %43, %44
%46 = sext i32 %45 to i64
%47 = mul i64 %46, 4
%48 = trunc i64 %47 to i32
%49 = call i64 @malloc(i32 %48)
%50 = inttoptr i64 %49 to i32*
store i32* %50, i32** %8
%51 = load i32, i32* %3
%52 = load i32, i32* %4
%53 = load i32*, i32** %8
%54 = call i32 @generate_primes_window(i32 %51, i32 %52, i32* %53)
%55 = load i32, i32* %3
%56 = load i32, i32* %4
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %55, i32 %56)
%58 = load i32, i32* %3
store i32 %58, i32* %9
br label %59
59: ; preds = %76, %41
%60 = load i32, i32* %9
%61 = load i32, i32* %4
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %79
63: ; preds = %59
%64 = load i32*, i32** %8
%65 = load i32, i32* %9
%66 = load i32, i32* %3
%67 = sub nsw i32 %65, %66
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i32, i32* %64, i64 %68
%70 = load i32, i32* %69
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %63
%73 = load i32, i32* %9
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %73)
br label %75
75: ; preds = %72, %63
br label %76
76: ; preds = %75
%77 = load i32, i32* %9
%78 = add nsw i32 %77, 1
store i32 %78, i32* %9
br label %59
79: ; preds = %59
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%81 = load i32*, i32** %7
%82 = call i32 @free(i32* %81)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"list %d first primes:\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.3 = [47 x i8] c"The window %d to %d has the following primes:\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 32000)
%2 = inttoptr i64 %1 to i32*
%3 = tail call i32 @generate_eratosthenes(i32 8000, i32* %2)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 1000)
br label %5
5: ; preds = %0, %13
%6 = phi i32 [ 1, %0 ], [ %15, %13 ]
%7 = phi i32 [ 0, %0 ], [ %14, %13 ]
%8 = tail call i64 @is_it_prime_eratosthenes(i32 %6, i32* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%12 = add nsw i32 %7, 1
br label %13
13: ; preds = %5, %10
%14 = phi i32 [ %12, %10 ], [ %7, %5 ]
%15 = add nuw nsw i32 %6, 1
%16 = icmp slt i32 %14, 1000
br i1 %16, label %5, label %17
17: ; preds = %13
%18 = tail call i32 @putchar(i32 10)
%19 = tail call i64 @malloc(i32 400)
%20 = inttoptr i64 %19 to i32*
%21 = tail call i32 @generate_primes_window(i32 100, i32 200, i32* %20)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 100, i32 200)
br label %26
23: ; preds = %35
%24 = tail call i32 @putchar(i32 10)
%25 = tail call i32 @free(i32* %2)
ret i32 0
26: ; preds = %17, %35
%27 = phi i64 [ 100, %17 ], [ %36, %35 ]
%28 = add nsw i64 %27, -100
%29 = getelementptr inbounds i32, i32* %20, i64 %28
%30 = load i32, i32* %29
%31 = icmp eq i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %26
%33 = trunc i64 %27 to i32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %26, %32
%36 = add nuw nsw i64 %27, 1
%37 = icmp eq i64 %36, 200
br i1 %37, label %23, label %26
}