#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 EXIT_SUCCESS;
unsigned long long atol(char *);
int /*<<< orphan*/ calc_primes(char *, int);
char *calloc(scalar_t__, int);
int /*<<< orphan*/ count_primes(char *, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
scalar_t__ sqrtl(int);
int main(int argc, char *argv[]) {
  uint64_t max = argc > 1 ? atol(argv[1]) : 1000000000ull;
  char *bitmap = calloc(max / 8 + sqrtl(max) + 1, 1);
  calc_primes(bitmap, max);
  printf("%ld\n", count_primes(bitmap, max));
  free(bitmap);
  return EXIT_SUCCESS;
}


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)
cmpl   $0x1,-0x8(%rbp)
jle    11a6 <main+0x36>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atol@plt>
mov    %rax,-0x28(%rbp)
jmp    11b4 <main+0x44>
mov    $0x3b9aca00,%eax
mov    %rax,-0x28(%rbp)
jmp    11b4 <main+0x44>
mov    -0x28(%rbp),%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <sqrtl@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <calc_primes@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <count_primes@plt>
mov    %eax,%esi
lea    0xdf2(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x3b9aca00,%ebx
cmp    $0x2,%edi
jl     118a <main+0x1a>
mov    0x8(%rsi),%rdi
call   1090 <atol@plt>
mov    %rax,%rbx
lea    0x7(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
sar    $0x3,%eax
movslq %eax,%r14
mov    %ebx,%edi
call   1080 <sqrtl@plt>
lea    (%rax,%r14,1),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebx,%esi
call   1040 <calc_primes@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <count_primes@plt>
lea    0xe31(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%ld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @atol(i8* %13)
br label %16
15: ; preds = %2
br label %16
16: ; preds = %15, %10
%17 = phi i64 [ %14, %10 ], [ 1000000000, %15 ]
%18 = trunc i64 %17 to i32
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = sdiv i32 %19, 8
%21 = sext i32 %20 to i64
%22 = load i32, i32* %6
%23 = call i64 @sqrtl(i32 %22)
%24 = add nsw i64 %21, %23
%25 = add nsw i64 %24, 1
%26 = call i8* @calloc(i64 %25, i32 1)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = load i32, i32* %6
%29 = call i32 @calc_primes(i8* %27, i32 %28)
%30 = load i8*, i8** %7
%31 = load i32, i32* %6
%32 = call i32 @count_primes(i8* %30, i32 %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = load i8*, i8** %7
%35 = call i32 @free(i8* %34)
%36 = load i32, i32* @EXIT_SUCCESS
ret i32 %36
}

LLVM IR (-O2):
@.str = [5 x i8] c"%ld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @atol(i8* %6)
%8 = trunc i64 %7 to i32
br label %9
9: ; preds = %2, %4
%10 = phi i32 [ %8, %4 ], [ 1000000000, %2 ]
%11 = sdiv i32 %10, 8
%12 = sext i32 %11 to i64
%13 = tail call i64 @sqrtl(i32 %10)
%14 = add i64 %13, 1
%15 = add i64 %14, %12
%16 = tail call i8* @calloc(i64 %15, i32 1)
%17 = tail call i32 @calc_primes(i8* %16, i32 %10)
%18 = tail call i32 @count_primes(i8* %16, i32 %10)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = tail call i32 @free(i8* %16)
%21 = load i32, i32* @EXIT_SUCCESS
ret i32 %21
}