#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*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(unsigned long *, int /*<<< orphan*/, int);
int next_zero(unsigned long *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main() {
  unsigned long *array = (unsigned long *)malloc((8388608 / 8));
  int i, j, count;
  memset(array, 0, (8388608 / 8));
  count = 0;
  array[0 >> 5] |= (1 << (0 & 31));
  i = 1;
  do {
    if (!((array[i >> 5] & (1 << (i & 31))) != 0)) {
      int val = i * 2 + 1;
      printf("%d ", val);
      count++;
      j = i + val;
      while (j < 8388608) {
        array[j >> 5] |= (1 << (j & 31));
        j += val;
      }
    }
    i = next_zero(array, i);
  } while (i < 8388608 && i != -1);
  fprintf(stderr, "found %d primes\n", count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x100000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x100000,%edx
call   1040 <memset@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
or     $0x1,%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sar    $0x5,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x14(%rbp),%ecx
and    $0x1f,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
movslq %ecx,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
jne    123b <main+0xeb>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe21(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x800000,-0x18(%rbp)
jge    1236 <main+0xe6>
mov    -0x18(%rbp),%ecx
and    $0x1f,%ecx
mov    $0x1,%eax
shl    %cl,%eax
movslq %eax,%rdx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sar    $0x5,%ecx
movslq %ecx,%rcx
or     (%rax,%rcx,8),%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11f6 <main+0xa6>
jmp    123b <main+0xeb>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <next_zero@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x800000,-0x14(%rbp)
mov    %al,-0x21(%rbp)
jge    1266 <main+0x116>
cmpl   $0xffffffff,-0x14(%rbp)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1199 <main+0x49>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xd80(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x100000,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
xor    %r15d,%r15d
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x100000,%edx
call   1040 <memset@plt>
orb    $0x1,(%r12)
mov    $0x1,%ebp
lea    0xe78(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
sar    $0x5,%eax
mov    $0x1,%edx
mov    %ebp,%ecx
shl    %cl,%edx
cltq
movslq %edx,%rcx
test   %rcx,(%r12,%rax,8)
jne    11f0 <main+0xa0>
lea    0x1(%rbp,%rbp,1),%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%r15d
lea    0x1(%rbp,%rbp,2),%ecx
cmp    $0x7fffff,%ecx
jg     11f0 <main+0xa0>
nopw   0x0(%rax,%rax,1)
mov    $0x1,%eax
shl    %cl,%eax
cltq
mov    %ecx,%edx
sar    $0x5,%edx
movslq %edx,%rdx
or     %rax,(%r12,%rdx,8)
add    %ebx,%ecx
cmp    $0x800000,%ecx
jl     11d0 <main+0x80>
nop
mov    %r12,%rdi
mov    %ebp,%esi
call   1060 <next_zero@plt>
cmp    $0x7fffff,%eax
jg     1208 <main+0xb8>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1190 <main+0x40>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
mov    %r15d,%edx
call   1050 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"found %d primes\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i64 @malloc(i32 1048576)
%8 = inttoptr i64 %7 to i64*
store i64* %8, i64** %2
%9 = load i64*, i64** %2
%10 = call i32 @memset(i64* %9, i32 0, i32 1048576)
store i32 0, i32* %5
%11 = load i64*, i64** %2
%12 = getelementptr inbounds i64, i64* %11, i64 0
%13 = load i64, i64* %12
%14 = or i64 %13, 1
store i64 %14, i64* %12
store i32 1, i32* %3
br label %15
15: ; preds = %68, %0
%16 = load i64*, i64** %2
%17 = load i32, i32* %3
%18 = ashr i32 %17, 5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i64, i64* %16, i64 %19
%21 = load i64, i64* %20
%22 = load i32, i32* %3
%23 = and i32 %22, 31
%24 = shl i32 1, %23
%25 = sext i32 %24 to i64
%26 = and i64 %21, %25
%27 = icmp ne i64 %26, 0
br i1 %27, label %58, label %28
28: ; preds = %15
%29 = load i32, i32* %3
%30 = mul nsw i32 %29, 2
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
%36 = load i32, i32* %3
%37 = load i32, i32* %6
%38 = add nsw i32 %36, %37
store i32 %38, i32* %4
br label %39
39: ; preds = %42, %28
%40 = load i32, i32* %4
%41 = icmp slt i32 %40, 8388608
br i1 %41, label %42, label %57
42: ; preds = %39
%43 = load i32, i32* %4
%44 = and i32 %43, 31
%45 = shl i32 1, %44
%46 = sext i32 %45 to i64
%47 = load i64*, i64** %2
%48 = load i32, i32* %4
%49 = ashr i32 %48, 5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i64, i64* %47, i64 %50
%52 = load i64, i64* %51
%53 = or i64 %52, %46
store i64 %53, i64* %51
%54 = load i32, i32* %6
%55 = load i32, i32* %4
%56 = add nsw i32 %55, %54
store i32 %56, i32* %4
br label %39
57: ; preds = %39
br label %58
58: ; preds = %57, %15
%59 = load i64*, i64** %2
%60 = load i32, i32* %3
%61 = call i32 @next_zero(i64* %59, i32 %60)
store i32 %61, i32* %3
br label %62
62: ; preds = %58
%63 = load i32, i32* %3
%64 = icmp slt i32 %63, 8388608
br i1 %64, label %65, label %68
65: ; preds = %62
%66 = load i32, i32* %3
%67 = icmp ne i32 %66, -1
br label %68
68: ; preds = %65, %62
%69 = phi i1 [ false, %62 ], [ %67, %65 ]
br i1 %69, label %15, label %70
70: ; preds = %68
%71 = load i32, i32* @stderr
%72 = load i32, i32* %5
%73 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %72)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"found %d primes\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 1048576)
%2 = inttoptr i64 %1 to i64*
%3 = tail call i32 @memset(i64* %2, i32 0, i32 1048576)
%4 = load i64, i64* %2
%5 = or i64 %4, 1
store i64 %5, i64* %2
br label %6
6: ; preds = %37, %0
%7 = phi i32 [ 0, %0 ], [ %38, %37 ]
%8 = phi i32 [ 1, %0 ], [ %39, %37 ]
%9 = ashr i32 %8, 5
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i64, i64* %2, i64 %10
%12 = load i64, i64* %11
%13 = and i32 %8, 31
%14 = shl nuw i32 1, %13
%15 = sext i32 %14 to i64
%16 = and i64 %12, %15
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %37
18: ; preds = %6
%19 = shl nsw i32 %8, 1
%20 = or i32 %19, 1
%21 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = add nsw i32 %7, 1
%23 = add nsw i32 %8, %20
%24 = icmp slt i32 %23, 8388608
br i1 %24, label %25, label %37
25: ; preds = %18, %25
%26 = phi i32 [ %35, %25 ], [ %23, %18 ]
%27 = and i32 %26, 31
%28 = shl nuw i32 1, %27
%29 = sext i32 %28 to i64
%30 = ashr i32 %26, 5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i64, i64* %2, i64 %31
%33 = load i64, i64* %32
%34 = or i64 %33, %29
store i64 %34, i64* %32
%35 = add nsw i32 %26, %20
%36 = icmp slt i32 %35, 8388608
br i1 %36, label %25, label %37
37: ; preds = %25, %18, %6
%38 = phi i32 [ %7, %6 ], [ %22, %18 ], [ %22, %25 ]
%39 = tail call i32 @next_zero(i64* %2, i32 %8)
%40 = icmp slt i32 %39, 8388608
%41 = icmp ne i32 %39, -1
%42 = and i1 %40, %41
br i1 %42, label %6, label %43
43: ; preds = %37
%44 = load i32, i32* @stderr
%45 = tail call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %38)
ret i32 0
}