#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;
char *aligned_alloc(int, int);
unsigned long long atol(char *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ calc_primes(char *, 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 = aligned_alloc(32, max / 8 + 32 * 16 * 2 + 1);
  bzero(bitmap, max / 8 + 32 * 16 * 2 + 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   1070 <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
mov    %eax,%esi
add    $0x400,%esi
add    $0x1,%esi
mov    $0x20,%edi
call   1090 <aligned_alloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
add    $0x400,%esi
add    $0x1,%esi
call   1080 <bzero@plt>
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    0xde1(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x3b9aca00,%ebx
cmp    $0x2,%edi
jl     118a <main+0x1a>
mov    0x8(%rsi),%rdi
call   1070 <atol@plt>
mov    %rax,%rbx
lea    0x7(%rbx),%ebp
test   %ebx,%ebx
cmovns %ebx,%ebp
sar    $0x3,%ebp
add    $0x401,%ebp
mov    $0x20,%edi
mov    %ebp,%esi
call   1090 <aligned_alloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebp,%esi
call   1080 <bzero@plt>
mov    %r14,%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
pop    %rbx
pop    %r14
pop    %rbp
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, 1024
%22 = add nsw i32 %21, 1
%23 = call i8* @aligned_alloc(i32 32, i32 %22)
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = load i32, i32* %6
%26 = sdiv i32 %25, 8
%27 = add nsw i32 %26, 1024
%28 = add nsw i32 %27, 1
%29 = call i32 @bzero(i8* %24, i32 %28)
%30 = load i8*, i8** %7
%31 = load i32, i32* %6
%32 = call i32 @calc_primes(i8* %30, i32 %31)
%33 = load i8*, i8** %7
%34 = load i32, i32* %6
%35 = call i32 @count_primes(i8* %33, i32 %34)
%36 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %35)
%37 = load i8*, i8** %7
%38 = call i32 @free(i8* %37)
%39 = load i32, i32* @EXIT_SUCCESS
ret i32 %39
}

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, 1025
%13 = tail call align 32 i8* @aligned_alloc(i32 32, i32 %12)
%14 = tail call i32 @bzero(i8* %13, i32 %12)
%15 = tail call i32 @calc_primes(i8* %13, i32 %10)
%16 = tail call i32 @count_primes(i8* %13, i32 %10)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = tail call i32 @free(i8* %13)
%19 = load i32, i32* @EXIT_SUCCESS
ret i32 %19
}