#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 */
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc != 2)
    printf("Usage: %s [RANGE]...\n", argv[0]);
  else if (!isdigit(argv[1][0]))
    printf("Range must be a number.\n");
  else {
    static int set[2000000];
    long i = 0;
    for (i = 0; i < 2000000; i++)
      set[i] = 1;
    long pos = 0;
    int count = 0;
    long sum = 0;
    for (pos = 2; pos < 2000000; pos++) {
      if (set[pos - 1] != 0) {
        for (i = 2; (i * pos) < 2000000; i++)
          set[(i * pos - 1)] = 0;
        count++;
        sum = sum + pos;
      }
    }
    printf("There are %d primes below 2,000,000.\n", count);
    printf("The sum of these primes is %ld.\n", sum);
  }
  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)
cmpl   $0x2,-0x8(%rbp)
je     115a <main+0x3a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a9 <main+0x189>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1186 <main+0x66>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a4 <main+0x184>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x1e8480,-0x18(%rbp)
jge    11c7 <main+0xa7>
mov    -0x18(%rbp),%rcx
lea    0x2e91(%rip),%rax
movl   $0x1,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1196 <main+0x76>
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x2,-0x20(%rbp)
cmpq   $0x1e8480,-0x20(%rbp)
jge    1281 <main+0x161>
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
lea    0x2e3d(%rip),%rax
cmpl   $0x0,(%rax,%rcx,4)
je     126b <main+0x14b>
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x20(%rbp),%rax
cmp    $0x1e8480,%rax
jge    1256 <main+0x136>
mov    -0x18(%rbp),%rcx
imul   -0x20(%rbp),%rcx
sub    $0x1,%rcx
lea    0x2e02(%rip),%rax
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1215 <main+0xf5>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1270 <main+0x150>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11e6 <main+0xc6>
mov    -0x24(%rbp),%esi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a9 <main+0x189>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1237 <main+0x107>
mov    0x8(%rsi),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1264 <main+0x134>
mov    $0x24,%ecx
lea    0x2ef3(%rip),%r8
movaps 0xe9c(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movaps %xmm0,-0x90(%r8,%rcx,4)
ff ff
movaps %xmm0,-0x80(%r8,%rcx,4)
movaps %xmm0,-0x70(%r8,%rcx,4)
movaps %xmm0,-0x60(%r8,%rcx,4)
movaps %xmm0,-0x50(%r8,%rcx,4)
movaps %xmm0,-0x40(%r8,%rcx,4)
movaps %xmm0,-0x30(%r8,%rcx,4)
movaps %xmm0,-0x20(%r8,%rcx,4)
movaps %xmm0,-0x10(%r8,%rcx,4)
movaps %xmm0,(%r8,%rcx,4)
add    $0x28,%rcx
cmp    $0x1e84a4,%rcx
jne    1170 <main+0x40>
mov    $0x2,%ecx
xor    %r14d,%r14d
lea    0x2e92(%rip),%r9
mov    $0x8,%edi
mov    $0x4,%eax
xor    %esi,%esi
jmp    11ff <main+0xcf>
nopl   0x0(%rax,%rax,1)
add    $0x1,%esi
add    %rcx,%r14
add    $0x1,%rcx
add    $0x8,%r9
add    $0x4,%rdi
add    $0x2,%rax
cmp    $0x1e8480,%rcx
je     1243 <main+0x113>
cmpl   $0x0,-0x4(%r8,%rcx,4)
je     11e6 <main+0xb6>
cmp    $0xf423f,%rcx
ja     11e0 <main+0xb0>
mov    %rax,%rbx
mov    %r9,%rdx
cs nopw 0x0(%rax,%rax,1)
movl   $0x0,(%rdx)
add    %rdi,%rdx
add    %rcx,%rbx
cmp    $0x1e8480,%rbx
jb     1220 <main+0xf0>
jmp    11e0 <main+0xb0>
mov    (%rsi),%rsi
lea    0xdcf(%rip),%rdi
jmp    125b <main+0x12b>
lea    0xddc(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdf4(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1270 <main+0x140>
lea    0xe02(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Usage: %s [RANGE]...\0A\00"
@.str.1 = [25 x i8] c"Range must be a number.\0A\00"
@main.set = internal global [2000000 x i32] zeroinitializer
@.str.2 = [38 x i8] c"There are %d primes below 2,000,000.\0A\00"
@.str.3 = [33 x i8] c"The sum of these primes is %ld.\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
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %78
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = call i32 @isdigit(i8 signext %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %17
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %77
27: ; preds = %17
store i64 0, i64* %6
store i64 0, i64* %6
br label %28
28: ; preds = %34, %27
%29 = load i64, i64* %6
%30 = icmp slt i64 %29, 2000000
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load i64, i64* %6
%33 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* @main.set, i64 0, i64 %32
store i32 1, i32* %33
br label %34
34: ; preds = %31
%35 = load i64, i64* %6
%36 = add nsw i64 %35, 1
store i64 %36, i64* %6
br label %28
37: ; preds = %28
store i64 0, i64* %7
store i32 0, i32* %8
store i64 0, i64* %9
store i64 2, i64* %7
br label %38
38: ; preds = %69, %37
%39 = load i64, i64* %7
%40 = icmp slt i64 %39, 2000000
br i1 %40, label %41, label %72
41: ; preds = %38
%42 = load i64, i64* %7
%43 = sub nsw i64 %42, 1
%44 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* @main.set, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %68
47: ; preds = %41
store i64 2, i64* %6
br label %48
48: ; preds = %59, %47
%49 = load i64, i64* %6
%50 = load i64, i64* %7
%51 = mul nsw i64 %49, %50
%52 = icmp slt i64 %51, 2000000
br i1 %52, label %53, label %62
53: ; preds = %48
%54 = load i64, i64* %6
%55 = load i64, i64* %7
%56 = mul nsw i64 %54, %55
%57 = sub nsw i64 %56, 1
%58 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* @main.set, i64 0, i64 %57
store i32 0, i32* %58
br label %59
59: ; preds = %53
%60 = load i64, i64* %6
%61 = add nsw i64 %60, 1
store i64 %61, i64* %6
br label %48
62: ; preds = %48
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 1
store i32 %64, i32* %8
%65 = load i64, i64* %9
%66 = load i64, i64* %7
%67 = add nsw i64 %65, %66
store i64 %67, i64* %9
br label %68
68: ; preds = %62, %41
br label %69
69: ; preds = %68
%70 = load i64, i64* %7
%71 = add nsw i64 %70, 1
store i64 %71, i64* %7
br label %38
72: ; preds = %38
%73 = load i32, i32* %8
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %73)
%75 = load i64, i64* %9
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i64 %75)
br label %77
77: ; preds = %72, %25
br label %78
78: ; preds = %77, %12
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Usage: %s [RANGE]...\0A\00"
@main.set = internal unnamed_addr global [2000000 x i32] zeroinitializer
@.str.2 = [38 x i8] c"There are %d primes below 2,000,000.\0A\00"
@.str.3 = [33 x i8] c"The sum of these primes is %ld.\0A\00"
@str = [24 x i8] c"Range must be a number.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %74
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = tail call i32 @isdigit(i8 signext %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %41, label %13
13: ; preds = %7, %13
%14 = phi i64 [ %39, %13 ], [ 0, %7 ]
%15 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* @main.set, i64 0, i64 %14
%16 = bitcast i32* %15 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %16
%17 = getelementptr inbounds i32, i32* %15, i64 4
%18 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %18
%19 = add nuw nsw i64 %14, 8
%20 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* @main.set, i64 0, i64 %19
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %21
%22 = getelementptr inbounds i32, i32* %20, i64 4
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %23
%24 = add nuw nsw i64 %14, 16
%25 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* @main.set, i64 0, i64 %24
%26 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %26
%27 = getelementptr inbounds i32, i32* %25, i64 4
%28 = bitcast i32* %27 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %28
%29 = add nuw nsw i64 %14, 24
%30 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* @main.set, i64 0, i64 %29
%31 = bitcast i32* %30 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %31
%32 = getelementptr inbounds i32, i32* %30, i64 4
%33 = bitcast i32* %32 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %33
%34 = add nuw nsw i64 %14, 32
%35 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* @main.set, i64 0, i64 %34
%36 = bitcast i32* %35 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %36
%37 = getelementptr inbounds i32, i32* %35, i64 4
%38 = bitcast i32* %37 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %38
%39 = add nuw nsw i64 %14, 40
%40 = icmp eq i64 %39, 2000000
br i1 %40, label %43, label %13
41: ; preds = %7
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %74
43: ; preds = %13, %66
%44 = phi i64 [ %68, %66 ], [ 0, %13 ]
%45 = phi i32 [ %67, %66 ], [ 0, %13 ]
%46 = phi i64 [ %69, %66 ], [ 2, %13 ]
%47 = add nsw i64 %46, -1
%48 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* @main.set, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = icmp eq i32 %49, 0
br i1 %50, label %66, label %51
51: ; preds = %43
%52 = icmp ult i64 %46, 1000000
br i1 %52, label %53, label %63
53: ; preds = %51
%54 = shl nuw nsw i64 %46, 1
br label %55
55: ; preds = %53, %55
%56 = phi i64 [ %61, %55 ], [ %54, %53 ]
%57 = phi i64 [ %60, %55 ], [ 2, %53 ]
%58 = add nsw i64 %56, -1
%59 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* @main.set, i64 0, i64 %58
store i32 0, i32* %59
%60 = add nuw nsw i64 %57, 1
%61 = mul nuw nsw i64 %60, %46
%62 = icmp ult i64 %61, 2000000
br i1 %62, label %55, label %63
63: ; preds = %55, %51
%64 = add nsw i32 %45, 1
%65 = add nsw i64 %44, %46
br label %66
66: ; preds = %43, %63
%67 = phi i32 [ %64, %63 ], [ %45, %43 ]
%68 = phi i64 [ %65, %63 ], [ %44, %43 ]
%69 = add nuw nsw i64 %46, 1
%70 = icmp eq i64 %69, 2000000
br i1 %70, label %71, label %43
71: ; preds = %66
%72 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %67)
%73 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i64 %68)
br label %74
74: ; preds = %41, %71, %4
ret i32 0
}