#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(max / 8 / 2 + 1, 1);
  calc_primes(bitmap, max);
  printf("%ld\n", count_primes(bitmap, (max - 1) / 2 + 1));
  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    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0x1,%edi
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),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
add    $0x1,%esi
call   1050 <count_primes@plt>
mov    %eax,%esi
lea    0xdfe(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2dc9(%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    0xf(%rbx),%edi
test   %ebx,%ebx
cmovns %ebx,%edi
sar    $0x4,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebx,%esi
call   1040 <calc_primes@plt>
mov    %ebx,%eax
add    $0xffffffff,%eax
shr    $0x1f,%eax
lea    (%rbx,%rax,1),%esi
add    $0xffffffff,%esi
sar    %esi
add    $0x1,%esi
mov    %r14,%rdi
call   1050 <count_primes@plt>
lea    0xe3f(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2e09(%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 = sdiv i32 %20, 2
%22 = add nsw i32 %21, 1
%23 = call i8* @calloc(i32 %22, i32 1)
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = load i32, i32* %6
%26 = call i32 @calc_primes(i8* %24, i32 %25)
%27 = load i8*, i8** %7
%28 = load i32, i32* %6
%29 = sub nsw i32 %28, 1
%30 = sdiv i32 %29, 2
%31 = add nsw i32 %30, 1
%32 = call i32 @count_primes(i8* %27, 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, 16
%12 = add nsw i32 %11, 1
%13 = tail call i8* @calloc(i32 %12, i32 1)
%14 = tail call i32 @calc_primes(i8* %13, i32 %10)
%15 = add nsw i32 %10, -1
%16 = sdiv i32 %15, 2
%17 = add nsw i32 %16, 1
%18 = tail call i32 @count_primes(i8* %13, i32 %17)
%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* %13)
%21 = load i32, i32* @EXIT_SUCCESS
ret i32 %21
}