#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 */

/* Variables and functions */
long atol(char const *);
int /*<<< orphan*/ prime_sieve(long);
int /*<<< orphan*/ printf(char *);
int main(int argc, const char **argv) {
  printf("Limit\tCount\tMicros\n");
  if (argc > 1) {
    long limit = atol(argv[1]);
    if (limit > 0) {
      prime_sieve(limit);
    }
  } else {
    long limit = 100;
    for (int l = 2; l <= 7; l++) {
      prime_sieve(limit);
      limit *= 10;
    }
  }
  return 0;
}


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)
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jle    1186 <main+0x56>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atol@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    1181 <main+0x51>
mov    -0x18(%rbp),%rdi
call   1040 <prime_sieve@plt>
jmp    11c4 <main+0x94>
movq   $0x64,-0x20(%rbp)
movl   $0x2,-0x24(%rbp)
cmpl   $0x7,-0x24(%rbp)
jg     11bf <main+0x8f>
mov    -0x20(%rbp),%rdi
call   1040 <prime_sieve@plt>
imul   $0xa,-0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1195 <main+0x65>
jmp    11c4 <main+0x94>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x1,%ebp
jle    115c <main+0x2c>
mov    0x8(%rbx),%rdi
call   1050 <atol@plt>
mov    %rax,%rdi
test   %rax,%rax
jg     1193 <main+0x63>
jmp    1198 <main+0x68>
mov    $0x64,%edi
call   1040 <prime_sieve@plt>
mov    $0x3e8,%edi
call   1040 <prime_sieve@plt>
mov    $0x2710,%edi
call   1040 <prime_sieve@plt>
mov    $0x186a0,%edi
call   1040 <prime_sieve@plt>
mov    $0xf4240,%edi
call   1040 <prime_sieve@plt>
mov    $0x989680,%edi
call   1040 <prime_sieve@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Limit\09Count\09Micros\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %23
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i64 @atol(i8* %15)
store i64 %16, i64* %6
%17 = load i64, i64* %6
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i64, i64* %6
%21 = call i32 @prime_sieve(i64 %20)
br label %22
22: ; preds = %19, %12
br label %36
23: ; preds = %2
store i64 100, i64* %7
store i32 2, i32* %8
br label %24
24: ; preds = %32, %23
%25 = load i32, i32* %8
%26 = icmp sle i32 %25, 7
br i1 %26, label %27, label %35
27: ; preds = %24
%28 = load i64, i64* %7
%29 = call i32 @prime_sieve(i64 %28)
%30 = load i64, i64* %7
%31 = mul nsw i64 %30, 10
store i64 %31, i64* %7
br label %32
32: ; preds = %27
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
br label %24
35: ; preds = %24
br label %36
36: ; preds = %35, %22
ret i32 0
}

LLVM IR (-O2):
@str = [19 x i8] c"Limit\09Count\09Micros\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%4 = icmp sgt i32 %0, 1
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i32 @prime_sieve(i64 100)
%7 = tail call i32 @prime_sieve(i64 1000)
%8 = tail call i32 @prime_sieve(i64 10000)
%9 = tail call i32 @prime_sieve(i64 100000)
%10 = tail call i32 @prime_sieve(i64 1000000)
br label %16
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i64 @atol(i8* %13)
%15 = icmp sgt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11, %5
%17 = phi i64 [ 10000000, %5 ], [ %14, %11 ]
%18 = tail call i32 @prime_sieve(i64 %17)
br label %19
19: ; preds = %16, %11
ret i32 0
}