#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 findPrimes(unsigned int p[1000], int count) {
  static unsigned int c = 5;
  static int last = -1;
  int i, r, goalIndex = last + count;
  if (last == -1) {
    p[0] = 2;
    p[1] = 3;
    last = 1;
  }
  if (goalIndex > 1000)
    goalIndex = 1000;
  for (; last < goalIndex; c += 2) {
    r = (int)(sqrt(c)) + 1;
    for (i = 1; p[i] < r; i++) {
      if ((c % p[i]) == 0) {
        break;
      }
    }
    if (p[i] >= r) {
      last++;
      p[last] = c;
    }
  }
  return last;
}


x86 assembly (clang, -O0):
<findPrimes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2f07(%rip),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,0x2efa(%rip)
jne    1157 <findPrimes+0x47>
mov    -0x8(%rbp),%rax
movl   $0x2,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x3,0x4(%rax)
movl   $0x1,0x2ed5(%rip)
cmpl   $0x3e8,-0x18(%rbp)
jle    116b <findPrimes+0x5b>
movl   $0x3e8,-0x18(%rbp)
jmp    1170 <findPrimes+0x60>
mov    0x2eb6(%rip),%eax
cmp    -0x18(%rbp),%eax
jge    1238 <findPrimes+0x128>
mov    0x2ea3(%rip),%eax
cvtsi2sd %rax,%xmm0
call   1030 <sqrt@plt>
cvttsd2si %xmm0,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x14(%rbp),%eax
jae    11e8 <findPrimes+0xd8>
mov    0x2e6e(%rip),%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rsi
xor    %edx,%edx
divl   (%rcx,%rsi,4)
cmp    $0x0,%edx
jne    11d5 <findPrimes+0xc5>
jmp    11e8 <findPrimes+0xd8>
jmp    11da <findPrimes+0xca>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a0 <findPrimes+0x90>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x14(%rbp),%eax
jb     121f <findPrimes+0x10f>
mov    0x2e2a(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e21(%rip)
mov    0x2e17(%rip),%edx
mov    -0x8(%rbp),%rax
movslq 0x2e10(%rip),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1224 <findPrimes+0x114>
mov    0x2dfe(%rip),%eax
add    $0x2,%eax
mov    %eax,0x2df5(%rip)
jmp    1170 <findPrimes+0x60>
mov    0x2dee(%rip),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findPrimes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2f0c(%rip),%eax
add    %eax,%esi
cmp    $0xffffffff,%eax
jne    1143 <findPrimes+0x33>
movabs $0x300000002,%rax
mov    %rax,(%rbx)
movl   $0x1,0x2eee(%rip)
mov    $0x1,%eax
cmp    $0x3e8,%esi
mov    $0x3e8,%r15d
cmovl  %esi,%r15d
cmp    %r15d,%eax
jge    11f8 <findPrimes+0xe8>
mov    0x2ec6(%rip),%ecx
lea    0x8(%rbx),%r14
xorpd  %xmm1,%xmm1
jmp    1193 <findPrimes+0x83>
nopl   0x0(%rax)
movslq 0x2eb5(%rip),%rdx
lea    0x1(%rdx),%rax
mov    %eax,0x2eab(%rip)
mov    %ecx,0x4(%rbx,%rdx,4)
add    $0x2,%ecx
mov    %ecx,0x2e9a(%rip)
cmp    %r15d,%eax
jge    11f8 <findPrimes+0xe8>
mov    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
ucomisd %xmm1,%xmm0
jb     11b0 <findPrimes+0xa0>
sqrtsd %xmm0,%xmm0
jmp    11b9 <findPrimes+0xa9>
nopl   0x0(%rax)
call   1030 <sqrt@plt>
xorpd  %xmm1,%xmm1
cvttsd2si %xmm0,%esi
add    $0x1,%esi
mov    0x4(%rbx),%ebp
mov    0x2e5f(%rip),%ecx
mov    %r14,%rdi
cmp    %esi,%ebp
jae    1170 <findPrimes+0x60>
mov    %ecx,%eax
xor    %edx,%edx
div    %ebp
test   %edx,%edx
je     11f0 <findPrimes+0xe0>
mov    (%rdi),%ebp
add    $0x4,%rdi
cmp    %esi,%ebp
jb     11d0 <findPrimes+0xc0>
jmp    1170 <findPrimes+0x60>
cs nopw 0x0(%rax,%rax,1)
mov    0x2e36(%rip),%eax
jmp    1185 <findPrimes+0x75>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@findPrimes.c = internal global i32 5
@findPrimes.last = internal global i32 -1
define i32 @findPrimes(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = load i32, i32* @findPrimes.last
%9 = load i32, i32* %4
%10 = add nsw i32 %8, %9
store i32 %10, i32* %7
%11 = load i32, i32* @findPrimes.last
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32*, i32** %3
%15 = getelementptr inbounds i32, i32* %14, i64 0
store i32 2, i32* %15
%16 = load i32*, i32** %3
%17 = getelementptr inbounds i32, i32* %16, i64 1
store i32 3, i32* %17
store i32 1, i32* @findPrimes.last
br label %18
18: ; preds = %13, %2
%19 = load i32, i32* %7
%20 = icmp sgt i32 %19, 1000
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 1000, i32* %7
br label %22
22: ; preds = %21, %18
br label %23
23: ; preds = %72, %22
%24 = load i32, i32* @findPrimes.last
%25 = load i32, i32* %7
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %75
27: ; preds = %23
%28 = load i32, i32* @findPrimes.c
%29 = uitofp i32 %28 to double
%30 = call double @sqrt(double %29)
%31 = fptosi double %30 to i32
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
store i32 1, i32* %5
br label %33
33: ; preds = %52, %27
%34 = load i32*, i32** %3
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = load i32, i32* %6
%40 = icmp ult i32 %38, %39
br i1 %40, label %41, label %55
41: ; preds = %33
%42 = load i32, i32* @findPrimes.c
%43 = load i32*, i32** %3
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
%48 = urem i32 %42, %47
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %41
br label %55
51: ; preds = %41
br label %52
52: ; preds = %51
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %33
55: ; preds = %50, %33
%56 = load i32*, i32** %3
%57 = load i32, i32* %5
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
%60 = load i32, i32* %59
%61 = load i32, i32* %6
%62 = icmp uge i32 %60, %61
br i1 %62, label %63, label %71
63: ; preds = %55
%64 = load i32, i32* @findPrimes.last
%65 = add nsw i32 %64, 1
store i32 %65, i32* @findPrimes.last
%66 = load i32, i32* @findPrimes.c
%67 = load i32*, i32** %3
%68 = load i32, i32* @findPrimes.last
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %67, i64 %69
store i32 %66, i32* %70
br label %71
71: ; preds = %63, %55
br label %72
72: ; preds = %71
%73 = load i32, i32* @findPrimes.c
%74 = add i32 %73, 2
store i32 %74, i32* @findPrimes.c
br label %23
75: ; preds = %23
%76 = load i32, i32* @findPrimes.last
ret i32 %76
}

LLVM IR (-O2):
@findPrimes.c = internal unnamed_addr global i32 5
@findPrimes.last = internal unnamed_addr global i32 -1
define i32 @findPrimes(i32* nocapture %0, i32 %1) {
%3 = load i32, i32* @findPrimes.last
%4 = add nsw i32 %3, %1
%5 = icmp eq i32 %3, -1
br i1 %5, label %6, label %8
6: ; preds = %2
store i32 2, i32* %0
%7 = getelementptr inbounds i32, i32* %0, i64 1
store i32 3, i32* %7
store i32 1, i32* @findPrimes.last
br label %8
8: ; preds = %6, %2
%9 = phi i32 [ 1, %6 ], [ %3, %2 ]
%10 = icmp slt i32 %4, 1000
%11 = select i1 %10, i32 %4, i32 1000
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %46
13: ; preds = %8
%14 = getelementptr inbounds i32, i32* %0, i64 1
%15 = load i32, i32* @findPrimes.c
br label %16
16: ; preds = %13, %42
%17 = phi i32 [ %15, %13 ], [ %44, %42 ]
%18 = uitofp i32 %17 to double
%19 = tail call double @sqrt(double %18)
%20 = fptosi double %19 to i32
%21 = add nsw i32 %20, 1
%22 = load i32, i32* %14
%23 = icmp ult i32 %22, %21
%24 = load i32, i32* @findPrimes.c
br i1 %23, label %29, label %35
25: ; preds = %29
%26 = getelementptr inbounds i32, i32* %0, i64 %34
%27 = load i32, i32* %26
%28 = icmp ult i32 %27, %21
br i1 %28, label %29, label %35
29: ; preds = %16, %25
%30 = phi i64 [ %34, %25 ], [ 1, %16 ]
%31 = phi i32 [ %27, %25 ], [ %22, %16 ]
%32 = urem i32 %24, %31
%33 = icmp eq i32 %32, 0
%34 = add nuw i64 %30, 1
br i1 %33, label %40, label %25
35: ; preds = %25, %16
%36 = load i32, i32* @findPrimes.last
%37 = add nsw i32 %36, 1
store i32 %37, i32* @findPrimes.last
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %0, i64 %38
store i32 %24, i32* %39
br label %42
40: ; preds = %29
%41 = load i32, i32* @findPrimes.last
br label %42
42: ; preds = %40, %35
%43 = phi i32 [ %41, %40 ], [ %37, %35 ]
%44 = add i32 %24, 2
store i32 %44, i32* @findPrimes.c
%45 = icmp slt i32 %43, %11
br i1 %45, label %16, label %46
46: ; preds = %42, %8
%47 = phi i32 [ %9, %8 ], [ %43, %42 ]
ret i32 %47
}