#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 */
typedef int uint64_t;

/* Variables and functions */
int /*<<< orphan*/ mark_low_prime(char *, int, int);
int sqrtl(int);
void calc_primes(char *bitmap, uint64_t max) {
  uint64_t a, r;
  mark_low_prime(bitmap, max, 2);
  mark_low_prime(bitmap, max, 3);
  mark_low_prime(bitmap, max, 5);
  mark_low_prime(bitmap, max, 7);
  mark_low_prime(bitmap, max, 11);
  mark_low_prime(bitmap, max, 13);
  for (a = 17; a < sqrtl(max); a++) {
    if (bitmap[a / 8] & 1 << (a % 8))
      continue;
    for (r = a * a; r <= max; r += a)
      bitmap[r / 8] |= 1 << (r % 8);
  }
  bitmap[0] = 0x53;
  bitmap[1] = 0xD7;
}


x86 assembly (clang, -O0):
<calc_primes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x2,%edx
call   1030 <mark_low_prime@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x3,%edx
call   1030 <mark_low_prime@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x5,%edx
call   1030 <mark_low_prime@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x7,%edx
call   1030 <mark_low_prime@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0xb,%edx
call   1030 <mark_low_prime@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0xd,%edx
call   1030 <mark_low_prime@plt>
movl   $0x11,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <sqrtl@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    1273 <calc_primes+0x153>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
mov    %edx,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1203 <calc_primes+0xe3>
jmp    1265 <calc_primes+0x145>
mov    -0x10(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1260 <calc_primes+0x140>
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    $0x1,%esi
shl    %cl,%esi
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edx
or     %esi,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    120d <calc_primes+0xed>
jmp    1265 <calc_primes+0x145>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119c <calc_primes+0x7c>
mov    -0x8(%rbp),%rax
movb   $0x53,(%rax)
mov    -0x8(%rbp),%rax
movb   $0xd7,0x1(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_primes>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0x2,%edx
call   1030 <mark_low_prime@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x3,%edx
call   1030 <mark_low_prime@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x5,%edx
call   1030 <mark_low_prime@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x7,%edx
call   1030 <mark_low_prime@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0xb,%edx
call   1030 <mark_low_prime@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0xd,%edx
call   1030 <mark_low_prime@plt>
mov    %ebp,%edi
call   1040 <sqrtl@plt>
cmp    $0x12,%eax
jl     11ee <calc_primes+0xce>
mov    $0x11,%ebx
jmp    11ae <calc_primes+0x8e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    %ebp,%edi
call   1040 <sqrtl@plt>
cmp    %eax,%ebx
jge    11ee <calc_primes+0xce>
mov    %ebx,%eax
shr    $0x3,%rax
movzbl (%r14,%rax,1),%eax
mov    %ebx,%ecx
and    $0x7,%cl
movzbl %cl,%ecx
bt     %ecx,%eax
jb     11a0 <calc_primes+0x80>
mov    %ebx,%eax
imul   %ebx,%eax
cmp    %ebp,%eax
jg     11a0 <calc_primes+0x80>
nop
mov    %eax,%ecx
and    $0x7,%cl
mov    $0x1,%edx
shl    %cl,%edx
mov    %eax,%ecx
shr    $0x3,%rcx
or     %dl,(%r14,%rcx,1)
add    %ebx,%eax
cmp    %ebp,%eax
jle    11d0 <calc_primes+0xb0>
jmp    11a0 <calc_primes+0x80>
movw   $0xd753,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @calc_primes(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = load i32, i32* %4
%9 = call i32 @mark_low_prime(i8* %7, i32 %8, i32 2)
%10 = load i8*, i8** %3
%11 = load i32, i32* %4
%12 = call i32 @mark_low_prime(i8* %10, i32 %11, i32 3)
%13 = load i8*, i8** %3
%14 = load i32, i32* %4
%15 = call i32 @mark_low_prime(i8* %13, i32 %14, i32 5)
%16 = load i8*, i8** %3
%17 = load i32, i32* %4
%18 = call i32 @mark_low_prime(i8* %16, i32 %17, i32 7)
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = call i32 @mark_low_prime(i8* %19, i32 %20, i32 11)
%22 = load i8*, i8** %3
%23 = load i32, i32* %4
%24 = call i32 @mark_low_prime(i8* %22, i32 %23, i32 13)
store i32 17, i32* %5
br label %25
25: ; preds = %70, %2
%26 = load i32, i32* %5
%27 = load i32, i32* %4
%28 = call i32 @sqrtl(i32 %27)
%29 = icmp slt i32 %26, %28
br i1 %29, label %30, label %73
30: ; preds = %25
%31 = load i8*, i8** %3
%32 = load i32, i32* %5
%33 = sdiv i32 %32, 8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = load i32, i32* %5
%39 = srem i32 %38, 8
%40 = shl i32 1, %39
%41 = and i32 %37, %40
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %30
br label %70
44: ; preds = %30
%45 = load i32, i32* %5
%46 = load i32, i32* %5
%47 = mul nsw i32 %45, %46
store i32 %47, i32* %6
br label %48
48: ; preds = %65, %44
%49 = load i32, i32* %6
%50 = load i32, i32* %4
%51 = icmp sle i32 %49, %50
br i1 %51, label %52, label %69
52: ; preds = %48
%53 = load i32, i32* %6
%54 = srem i32 %53, 8
%55 = shl i32 1, %54
%56 = load i8*, i8** %3
%57 = load i32, i32* %6
%58 = sdiv i32 %57, 8
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %56, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = or i32 %62, %55
%64 = trunc i32 %63 to i8
store i8 %64, i8* %60
br label %65
65: ; preds = %52
%66 = load i32, i32* %5
%67 = load i32, i32* %6
%68 = add nsw i32 %67, %66
store i32 %68, i32* %6
br label %48
69: ; preds = %48
br label %70
70: ; preds = %69, %43
%71 = load i32, i32* %5
%72 = add nsw i32 %71, 1
store i32 %72, i32* %5
br label %25
73: ; preds = %25
%74 = load i8*, i8** %3
%75 = getelementptr inbounds i8, i8* %74, i64 0
store i8 83, i8* %75
%76 = load i8*, i8** %3
%77 = getelementptr inbounds i8, i8* %76, i64 1
store i8 -41, i8* %77
ret void
}

LLVM IR (-O2):
define void @calc_primes(i8* %0, i32 %1) {
%3 = tail call i32 @mark_low_prime(i8* %0, i32 %1, i32 2)
%4 = tail call i32 @mark_low_prime(i8* %0, i32 %1, i32 3)
%5 = tail call i32 @mark_low_prime(i8* %0, i32 %1, i32 5)
%6 = tail call i32 @mark_low_prime(i8* %0, i32 %1, i32 7)
%7 = tail call i32 @mark_low_prime(i8* %0, i32 %1, i32 11)
%8 = tail call i32 @mark_low_prime(i8* %0, i32 %1, i32 13)
%9 = tail call i32 @sqrtl(i32 %1)
%10 = icmp sgt i32 %9, 17
br i1 %10, label %11, label %41
11: ; preds = %2, %37
%12 = phi i32 [ %38, %37 ], [ 17, %2 ]
%13 = lshr i32 %12, 3
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = and i32 %12, 7
%19 = shl nuw nsw i32 1, %18
%20 = and i32 %19, %17
%21 = icmp ne i32 %20, 0
%22 = mul nsw i32 %12, %12
%23 = icmp sgt i32 %22, %1
%24 = select i1 %21, i1 true, i1 %23
br i1 %24, label %37, label %25
25: ; preds = %11, %25
%26 = phi i32 [ %35, %25 ], [ %22, %11 ]
%27 = and i32 %26, 7
%28 = shl nuw nsw i32 1, %27
%29 = lshr i32 %26, 3
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %0, i64 %30
%32 = load i8, i8* %31
%33 = trunc i32 %28 to i8
%34 = or i8 %32, %33
store i8 %34, i8* %31
%35 = add nuw nsw i32 %26, %12
%36 = icmp sgt i32 %35, %1
br i1 %36, label %37, label %25
37: ; preds = %25, %11
%38 = add nuw nsw i32 %12, 1
%39 = tail call i32 @sqrtl(i32 %1)
%40 = icmp slt i32 %38, %39
br i1 %40, label %11, label %41
41: ; preds = %37, %2
store i8 83, i8* %0
%42 = getelementptr inbounds i8, i8* %0, i64 1
store i8 -41, i8* %42
ret void
}