#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 /*<<< orphan*/ mpz_t;

/* Variables and functions */
scalar_t__ floor(int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ gmp_printf(char *, int /*<<< orphan*/);
int *malloc(int);
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                              unsigned long);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ sqrt(unsigned long const);
int Problem010(void) {
  unsigned long int const limit = 2000000;
  unsigned long int search_lim = (unsigned long int)floor(sqrt(limit));
  unsigned long int i, j;
  mpz_t sum;
  int *sieve;
  mpz_init(sum);
  sieve = malloc(sizeof(int) * (limit + 1));
  for (i = 0; i < limit; i++) {
    sieve[i] = 1;
  }
  sieve[0] = sieve[1] = 0;
  for (i = 2; i <= search_lim; i++) {
    if (sieve[i]) {
      for (j = i + i; j < limit; j += i) {
        sieve[j] = 0;
      }
    }
  }
  for (i = 1; i < limit; i++) {
    if (sieve[i]) {
      mpz_add_ui(sum, sum, i);
    }
  }
  gmp_printf("%30Zd", sum);
  mpz_clear(sum);
  free(sieve);
  return 0;
}


x86 assembly (clang, -O0):
<Problem010>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x1e8480,-0x8(%rbp)
mov    $0x1e8480,%edi
call   1090 <sqrt@plt>
mov    %eax,%edi
call   10a0 <floor@plt>
mov    %rax,-0x10(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <mpz_init@plt>
mov    $0x7a1204,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x1e8480,-0x18(%rbp)
jae    11f1 <Problem010+0x71>
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11c3 <Problem010+0x43>
mov    -0x30(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     1283 <Problem010+0x103>
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     126d <Problem010+0xed>
mov    -0x18(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x1e8480,-0x20(%rbp)
jae    1268 <Problem010+0xe8>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    123a <Problem010+0xba>
jmp    126d <Problem010+0xed>
jmp    1272 <Problem010+0xf2>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    120e <Problem010+0x8e>
movq   $0x1,-0x18(%rbp)
cmpq   $0x1e8480,-0x18(%rbp)
jae    12d0 <Problem010+0x150>
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     12ba <Problem010+0x13a>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <mpz_add_ui@plt>
jmp    12bf <Problem010+0x13f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    128b <Problem010+0x10b>
mov    -0x24(%rbp),%esi
lea    0xd26(%rip),%rdi
call   1080 <gmp_printf@plt>
mov    -0x24(%rbp),%edi
call   1070 <mpz_clear@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Problem010>:
push   %r15
push   %r14
push   %rbx
mov    $0x1e8480,%edi
call   1090 <sqrt@plt>
mov    %eax,%edi
call   10a0 <floor@plt>
mov    %rax,%r14
call   1050 <mpz_init@plt>
mov    $0x7a1204,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x3c,%eax
movaps 0xe49(%rip),%xmm0
nopw   0x0(%rax,%rax,1)
movups %xmm0,-0xf0(%r15,%rax,4)
ff ff
movups %xmm0,-0xe0(%r15,%rax,4)
ff ff
movups %xmm0,-0xd0(%r15,%rax,4)
ff ff
movups %xmm0,-0xc0(%r15,%rax,4)
ff ff
movups %xmm0,-0xb0(%r15,%rax,4)
ff ff
movups %xmm0,-0xa0(%r15,%rax,4)
ff ff
movups %xmm0,-0x90(%r15,%rax,4)
ff ff
movups %xmm0,-0x80(%r15,%rax,4)
movups %xmm0,-0x70(%r15,%rax,4)
movups %xmm0,-0x60(%r15,%rax,4)
movups %xmm0,-0x50(%r15,%rax,4)
movups %xmm0,-0x40(%r15,%rax,4)
movups %xmm0,-0x30(%r15,%rax,4)
movups %xmm0,-0x20(%r15,%rax,4)
movups %xmm0,-0x10(%r15,%rax,4)
movups %xmm0,(%r15,%rax,4)
add    $0x40,%rax
cmp    $0x1e84bc,%rax
jne    11c0 <Problem010+0x40>
movq   $0x0,(%r15)
cmp    $0x2,%r14
jae    129f <Problem010+0x11f>
mov    $0x1,%ebx
jmp    126d <Problem010+0xed>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cmp    $0x1e8480,%rbx
je     127e <Problem010+0xfe>
cmpl   $0x0,(%r15,%rbx,4)
je     1260 <Problem010+0xe0>
mov    %rbx,%rdx
call   1040 <mpz_add_ui@plt>
jmp    1260 <Problem010+0xe0>
lea    0xd8b(%rip),%rdi
call   1080 <gmp_printf@plt>
call   1070 <mpz_clear@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r15,%rax
add    $0x10,%rax
mov    $0x2,%edx
mov    $0x8,%ecx
jmp    12d8 <Problem010+0x158>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rdx),%rsi
add    $0x8,%rax
add    $0x4,%rcx
cmp    %r14,%rdx
mov    %rsi,%rdx
je     124d <Problem010+0xcd>
cmpl   $0x0,(%r15,%rdx,4)
je     12c0 <Problem010+0x140>
lea    (%rdx,%rdx,1),%rsi
cmp    $0x1e847f,%rsi
ja     12c0 <Problem010+0x140>
mov    %rax,%rdi
nop
movl   $0x0,(%rdi)
add    %rdx,%rsi
add    %rcx,%rdi
cmp    $0x1e8480,%rsi
jb     12f0 <Problem010+0x170>
jmp    12c0 <Problem010+0x140>

LLVM IR (-O0):
@.str = [6 x i8] c"%30Zd\00"
define i32 @Problem010() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32*
store i64 2000000, i64* %1
%7 = call i32 @sqrt(i64 2000000)
%8 = call i64 @floor(i32 %7)
store i64 %8, i64* %2
%9 = load i32, i32* %5
%10 = call i32 @mpz_init(i32 %9)
%11 = call i32* @malloc(i32 8000004)
store i32* %11, i32** %6
store i64 0, i64* %3
br label %12
12: ; preds = %19, %0
%13 = load i64, i64* %3
%14 = icmp ult i64 %13, 2000000
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32*, i32** %6
%17 = load i64, i64* %3
%18 = getelementptr inbounds i32, i32* %16, i64 %17
store i32 1, i32* %18
br label %19
19: ; preds = %15
%20 = load i64, i64* %3
%21 = add i64 %20, 1
store i64 %21, i64* %3
br label %12
22: ; preds = %12
%23 = load i32*, i32** %6
%24 = getelementptr inbounds i32, i32* %23, i64 1
store i32 0, i32* %24
%25 = load i32*, i32** %6
%26 = getelementptr inbounds i32, i32* %25, i64 0
store i32 0, i32* %26
store i64 2, i64* %3
br label %27
27: ; preds = %54, %22
%28 = load i64, i64* %3
%29 = load i64, i64* %2
%30 = icmp ule i64 %28, %29
br i1 %30, label %31, label %57
31: ; preds = %27
%32 = load i32*, i32** %6
%33 = load i64, i64* %3
%34 = getelementptr inbounds i32, i32* %32, i64 %33
%35 = load i32, i32* %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %53
37: ; preds = %31
%38 = load i64, i64* %3
%39 = load i64, i64* %3
%40 = add i64 %38, %39
store i64 %40, i64* %4
br label %41
41: ; preds = %48, %37
%42 = load i64, i64* %4
%43 = icmp ult i64 %42, 2000000
br i1 %43, label %44, label %52
44: ; preds = %41
%45 = load i32*, i32** %6
%46 = load i64, i64* %4
%47 = getelementptr inbounds i32, i32* %45, i64 %46
store i32 0, i32* %47
br label %48
48: ; preds = %44
%49 = load i64, i64* %3
%50 = load i64, i64* %4
%51 = add i64 %50, %49
store i64 %51, i64* %4
br label %41
52: ; preds = %41
br label %53
53: ; preds = %52, %31
br label %54
54: ; preds = %53
%55 = load i64, i64* %3
%56 = add i64 %55, 1
store i64 %56, i64* %3
br label %27
57: ; preds = %27
store i64 1, i64* %3
br label %58
58: ; preds = %73, %57
%59 = load i64, i64* %3
%60 = icmp ult i64 %59, 2000000
br i1 %60, label %61, label %76
61: ; preds = %58
%62 = load i32*, i32** %6
%63 = load i64, i64* %3
%64 = getelementptr inbounds i32, i32* %62, i64 %63
%65 = load i32, i32* %64
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %61
%68 = load i32, i32* %5
%69 = load i32, i32* %5
%70 = load i64, i64* %3
%71 = call i32 @mpz_add_ui(i32 %68, i32 %69, i64 %70)
br label %72
72: ; preds = %67, %61
br label %73
73: ; preds = %72
%74 = load i64, i64* %3
%75 = add i64 %74, 1
store i64 %75, i64* %3
br label %58
76: ; preds = %58
%77 = load i32, i32* %5
%78 = call i32 @gmp_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %77)
%79 = load i32, i32* %5
%80 = call i32 @mpz_clear(i32 %79)
%81 = load i32*, i32** %6
%82 = call i32 @free(i32* %81)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%30Zd\00"
define i32 @Problem010() {
%1 = tail call i32 @sqrt(i64 2000000)
%2 = tail call i64 @floor(i32 %1)
%3 = tail call i32 @mpz_init(i32 undef)
%4 = tail call i32* @malloc(i32 8000004)
br label %5
5: ; preds = %5, %0
%6 = phi i64 [ 0, %0 ], [ %46, %5 ]
%7 = getelementptr inbounds i32, i32* %4, i64 %6
%8 = bitcast i32* %7 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %8
%9 = getelementptr inbounds i32, i32* %7, i64 4
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %10
%11 = or i64 %6, 8
%12 = getelementptr inbounds i32, i32* %4, i64 %11
%13 = bitcast i32* %12 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %13
%14 = getelementptr inbounds i32, i32* %12, i64 4
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %15
%16 = or i64 %6, 16
%17 = getelementptr inbounds i32, i32* %4, i64 %16
%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 = getelementptr inbounds i32, i32* %17, i64 4
%20 = bitcast i32* %19 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %20
%21 = or i64 %6, 24
%22 = getelementptr inbounds i32, i32* %4, i64 %21
%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 = getelementptr inbounds i32, i32* %22, i64 4
%25 = bitcast i32* %24 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %25
%26 = or i64 %6, 32
%27 = getelementptr inbounds i32, i32* %4, i64 %26
%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 = getelementptr inbounds i32, i32* %27, i64 4
%30 = bitcast i32* %29 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %30
%31 = or i64 %6, 40
%32 = getelementptr inbounds i32, i32* %4, i64 %31
%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 = getelementptr inbounds i32, i32* %32, i64 4
%35 = bitcast i32* %34 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %35
%36 = or i64 %6, 48
%37 = getelementptr inbounds i32, i32* %4, i64 %36
%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 = getelementptr inbounds i32, i32* %37, i64 4
%40 = bitcast i32* %39 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %40
%41 = or i64 %6, 56
%42 = getelementptr inbounds i32, i32* %4, i64 %41
%43 = bitcast i32* %42 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %43
%44 = getelementptr inbounds i32, i32* %42, i64 4
%45 = bitcast i32* %44 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %45
%46 = add nuw nsw i64 %6, 64
%47 = icmp eq i64 %46, 2000000
br i1 %47, label %48, label %5
48: ; preds = %5
%49 = getelementptr inbounds i32, i32* %4, i64 1
store i32 0, i32* %49
store i32 0, i32* %4
%50 = icmp ult i64 %2, 2
br i1 %50, label %67, label %51
51: ; preds = %48, %64
%52 = phi i64 [ %65, %64 ], [ 2, %48 ]
%53 = getelementptr inbounds i32, i32* %4, i64 %52
%54 = load i32, i32* %53
%55 = icmp ne i32 %54, 0
%56 = shl i64 %52, 1
%57 = icmp ult i64 %56, 2000000
%58 = select i1 %55, i1 %57, i1 false
br i1 %58, label %59, label %64
59: ; preds = %51, %59
%60 = phi i64 [ %62, %59 ], [ %56, %51 ]
%61 = getelementptr inbounds i32, i32* %4, i64 %60
store i32 0, i32* %61
%62 = add i64 %60, %52
%63 = icmp ult i64 %62, 2000000
br i1 %63, label %59, label %64
64: ; preds = %59, %51
%65 = add nuw i64 %52, 1
%66 = icmp eq i64 %52, %2
br i1 %66, label %67, label %51
67: ; preds = %64, %48
br label %68
68: ; preds = %67, %75
%69 = phi i64 [ %76, %75 ], [ 1, %67 ]
%70 = getelementptr inbounds i32, i32* %4, i64 %69
%71 = load i32, i32* %70
%72 = icmp eq i32 %71, 0
br i1 %72, label %75, label %73
73: ; preds = %68
%74 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i64 %69)
br label %75
75: ; preds = %68, %73
%76 = add nuw nsw i64 %69, 1
%77 = icmp eq i64 %76, 2000000
br i1 %77, label %78, label %68
78: ; preds = %75
%79 = tail call i32 @gmp_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 undef)
%80 = tail call i32 @mpz_clear(i32 undef)
%81 = tail call i32 @free(i32* %4)
ret i32 0
}