#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(int, int);
int /*<<< orphan*/ count_primes(char *, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  uint64_t max = argc > 1 ? atol(argv[1]) : 1000000000ull;
  char *bitmap = calloc(1, max / 8 + 32 * 1024);
  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    1196 <main+0x36>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atol@plt>
mov    %rax,-0x28(%rbp)
jmp    11a4 <main+0x44>
mov    $0x3b9aca00,%eax
mov    %rax,-0x28(%rbp)
jmp    11a4 <main+0x44>
mov    -0x28(%rbp),%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
add    $0x8000,%esi
mov    $0x1,%edi
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    0xe13(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2dde(%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     117a <main+0x1a>
mov    0x8(%rsi),%rdi
call   1080 <atol@plt>
mov    %rax,%rbx
lea    0x7(%rbx),%esi
test   %ebx,%ebx
cmovns %ebx,%esi
sar    $0x3,%esi
add    $0x8000,%esi
mov    $0x1,%edi
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    0xe4d(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2e17(%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 = add nsw i32 %20, 32768
%22 = call i8* @calloc(i32 1, i32 %21)
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = load i32, i32* %6
%25 = call i32 @calc_primes(i8* %23, i32 %24)
%26 = load i8*, i8** %7
%27 = load i32, i32* %6
%28 = call i32 @count_primes(i8* %26, i32 %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i8*, i8** %7
%31 = call i32 @free(i8* %30)
%32 = load i32, i32* @EXIT_SUCCESS
ret i32 %32
}

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 = add nsw i32 %11, 32768
%13 = tail call i8* @calloc(i32 1, i32 %12)
%14 = tail call i32 @calc_primes(i8* %13, i32 %10)
%15 = tail call i32 @count_primes(i8* %13, i32 %10)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = tail call i32 @free(i8* %13)
%18 = load i32, i32* @EXIT_SUCCESS
ret i32 %18
}