#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*/ free(int *);
scalar_t__ isprime(int, int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char const *argv[]) {
  int *p_arr = malloc(10001 * sizeof(int));
  int candidate = 3;
  int p_idx = 1;
  p_arr[0] = 2;
  for (int i = 1; i < 10001; ++i) {
    p_arr[i] = 0;
  }
  do {
    if (isprime(candidate, p_arr)) {
      p_arr[p_idx] = candidate;
      p_idx++;
    }
    candidate += 2;
  } while (p_arr[10001 - 1] == 0);
  printf("The answer to Euler Problem 7 is %i\n", p_arr[10001 - 1]);
  free(p_arr);
  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)
mov    $0x9c44,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x3,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x2,(%rax)
movl   $0x1,-0x24(%rbp)
cmpl   $0x2711,-0x24(%rbp)
jge    11ad <main+0x6d>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1183 <main+0x43>
jmp    11b2 <main+0x72>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <isprime@plt>
cmp    $0x0,%rax
je     11df <main+0x9f>
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x0,0x9c40(%rax)
je     11b2 <main+0x72>
mov    -0x18(%rbp),%rax
mov    0x9c40(%rax),%esi
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x9c44,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
movl   $0x2,(%rax)
lea    0x4(%rax),%rdi
mov    $0x9c40,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    $0x1,%ebx
mov    $0x3,%ebp
jmp    119e <main+0x4e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x2,%ebp
mov    0x9c40(%r14),%esi
test   %esi,%esi
jne    11b9 <main+0x69>
mov    %ebp,%edi
mov    %r14,%rsi
call   1060 <isprime@plt>
test   %rax,%rax
je     1190 <main+0x40>
movslq %ebx,%rbx
mov    %ebp,(%r14,%rbx,4)
add    $0x1,%ebx
jmp    1190 <main+0x40>
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"The answer to Euler Problem 7 is %i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32* @malloc(i32 40004)
store i32* %10, i32** %6
store i32 3, i32* %7
store i32 1, i32* %8
%11 = load i32*, i32** %6
%12 = getelementptr inbounds i32, i32* %11, i64 0
store i32 2, i32* %12
store i32 1, i32* %9
br label %13
13: ; preds = %21, %2
%14 = load i32, i32* %9
%15 = icmp slt i32 %14, 10001
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i32*, i32** %6
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
store i32 0, i32* %20
br label %21
21: ; preds = %16
%22 = load i32, i32* %9
%23 = add nsw i32 %22, 1
store i32 %23, i32* %9
br label %13
24: ; preds = %13
br label %25
25: ; preds = %41, %24
%26 = load i32, i32* %7
%27 = load i32*, i32** %6
%28 = call i64 @isprime(i32 %26, i32* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %25
%31 = load i32, i32* %7
%32 = load i32*, i32** %6
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
store i32 %31, i32* %35
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
br label %38
38: ; preds = %30, %25
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 2
store i32 %40, i32* %7
br label %41
41: ; preds = %38
%42 = load i32*, i32** %6
%43 = getelementptr inbounds i32, i32* %42, i64 10000
%44 = load i32, i32* %43
%45 = icmp eq i32 %44, 0
br i1 %45, label %25, label %46
46: ; preds = %41
%47 = load i32*, i32** %6
%48 = getelementptr inbounds i32, i32* %47, i64 10000
%49 = load i32, i32* %48
%50 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %49)
%51 = load i32*, i32** %6
%52 = call i32 @free(i32* %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"The answer to Euler Problem 7 is %i\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @malloc(i32 40004)
store i32 2, i32* %3
%4 = getelementptr i32, i32* %3, i64 1
%5 = bitcast i32* %4 to i8*
%6 = getelementptr inbounds i32, i32* %3, i64 10000
br label %7
7: ; preds = %2, %16
%8 = phi i32 [ %18, %16 ], [ 3, %2 ]
%9 = phi i32 [ %17, %16 ], [ 1, %2 ]
%10 = tail call i64 @isprime(i32 %8, i32* %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = sext i32 %9 to i64
%14 = getelementptr inbounds i32, i32* %3, i64 %13
store i32 %8, i32* %14
%15 = add nsw i32 %9, 1
br label %16
16: ; preds = %12, %7
%17 = phi i32 [ %15, %12 ], [ %9, %7 ]
%18 = add nuw nsw i32 %8, 2
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 0
br i1 %20, label %7, label %21
21: ; preds = %16
%22 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %19)
%23 = tail call i32 @free(i32* %3)
ret i32 0
}