#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 */
char *EratosthenesSieve(unsigned int const);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  const unsigned int LIMIT = 125000;
  int count = 0;
  char *sieve = NULL;
  sieve = EratosthenesSieve(LIMIT);
  for (int i = 0; i < (LIMIT - 2); i++) {
    if (sieve[i] == 1) {
      count++;
      if (count == 10001) {
        printf("%d", i + 2);
        free(sieve);
        sieve = NULL;
        return 0;
      }
    }
  }
  free(sieve);
  sieve = NULL;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1e848,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x1e848,%edi
call   1050 <EratosthenesSieve@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1e846,-0x1c(%rbp)
jae    11e9 <main+0xb9>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x1,%eax
jne    11d6 <main+0xa6>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x2711,-0xc(%rbp)
jne    11d1 <main+0xa1>
mov    -0x1c(%rbp),%esi
add    $0x2,%esi
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
jmp    1201 <main+0xd1>
jmp    11d6 <main+0xa6>
jmp    11db <main+0xab>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116a <main+0x3a>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x1e848,%edi
call   1050 <EratosthenesSieve@plt>
mov    %rax,%rbx
xor    %eax,%eax
mov    $0x2,%esi
jmp    115d <main+0x2d>
nopw   0x0(%rax,%rax,1)
add    $0x3,%rsi
cmp    $0x1e848,%rsi
je     11aa <main+0x7a>
cmpb   $0x1,-0x2(%rbx,%rsi,1)
jne    116e <main+0x3e>
add    $0x1,%eax
cmp    $0x2711,%eax
je     1191 <main+0x61>
cmpb   $0x1,-0x1(%rbx,%rsi,1)
jne    117f <main+0x4f>
add    $0x1,%eax
cmp    $0x2711,%eax
je     1197 <main+0x67>
cmpb   $0x1,(%rbx,%rsi,1)
jne    1150 <main+0x20>
add    $0x1,%eax
cmp    $0x2711,%eax
jne    1150 <main+0x20>
jmp    119b <main+0x6b>
add    $0xfffffffffffffffe,%rsi
jmp    119b <main+0x6b>
add    $0xffffffffffffffff,%rsi
add    $0x2,%esi
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %1
store i32 125000, i32* %2
store i32 0, i32* %3
store i8* null, i8** %4
%6 = call i8* @EratosthenesSieve(i32 125000)
store i8* %6, i8** %4
store i32 0, i32* %5
br label %7
7: ; preds = %31, %0
%8 = load i32, i32* %5
%9 = icmp ult i32 %8, 124998
br i1 %9, label %10, label %34
10: ; preds = %7
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %30
18: ; preds = %10
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, 10001
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 2
%26 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load i8*, i8** %4
%28 = call i32 @free(i8* %27)
store i8* null, i8** %4
store i32 0, i32* %1
br label %37
29: ; preds = %18
br label %30
30: ; preds = %29, %10
br label %31
31: ; preds = %30
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %7
34: ; preds = %7
%35 = load i8*, i8** %4
%36 = call i32 @free(i8* %35)
store i8* null, i8** %4
store i32 0, i32* %1
br label %37
37: ; preds = %34, %23
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = tail call i8* @EratosthenesSieve(i32 125000)
br label %2
2: ; preds = %34, %0
%3 = phi i64 [ 0, %0 ], [ %36, %34 ]
%4 = phi i32 [ 0, %0 ], [ %35, %34 ]
%5 = getelementptr inbounds i8, i8* %1, i64 %3
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 1
br i1 %7, label %8, label %16
8: ; preds = %2
%9 = add nsw i32 %4, 1
%10 = icmp eq i32 %9, 10001
br i1 %10, label %11, label %16
11: ; preds = %31, %22, %8
%12 = phi i64 [ %3, %8 ], [ %18, %22 ], [ %27, %31 ]
%13 = trunc i64 %12 to i32
%14 = add nuw nsw i32 %13, 2
%15 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %38
16: ; preds = %2, %8
%17 = phi i32 [ %9, %8 ], [ %4, %2 ]
%18 = add nuw nsw i64 %3, 1
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 1
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = add nsw i32 %17, 1
%24 = icmp eq i32 %23, 10001
br i1 %24, label %11, label %25
25: ; preds = %22, %16
%26 = phi i32 [ %23, %22 ], [ %17, %16 ]
%27 = add nuw nsw i64 %3, 2
%28 = getelementptr inbounds i8, i8* %1, i64 %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = add nsw i32 %26, 1
%33 = icmp eq i32 %32, 10001
br i1 %33, label %11, label %34
34: ; preds = %31, %25
%35 = phi i32 [ %32, %31 ], [ %26, %25 ]
%36 = add nuw nsw i64 %3, 3
%37 = icmp eq i64 %36, 124998
br i1 %37, label %38, label %2
38: ; preds = %34, %11
%39 = tail call i32 @free(i8* %1)
ret i32 0
}