#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 factorCnt(int);
int factorCnt2(int, int *, int);
int /*<<< orphan*/ free(int *);
int *primes(int, int *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int primes_n;
  int *prime = primes((1000 * 1000 * 5), &primes_n);
  int i, cnt = 0;
  int n0, n1;
  n1 = factorCnt(2);
  for (i = 2; i != 1000 * 1000 * 10; i++) {
    n0 = n1, n1 = factorCnt2(i + 1, prime, primes_n);
    cnt += n0 == n1;
  }
  printf("%d\n", cnt);
  free(prime);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4c4b40,%edi
lea    -0x8(%rbp),%rsi
call   1070 <primes@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x2,%edi
call   1060 <factorCnt@plt>
mov    %eax,-0x20(%rbp)
movl   $0x2,-0x14(%rbp)
cmpl   $0x989680,-0x14(%rbp)
je     11d6 <main+0x86>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1050 <factorCnt2@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118c <main+0x3c>
mov    -0x18(%rbp),%esi
lea    0xe20(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%rsi
mov    $0x4c4b40,%edi
call   1070 <primes@plt>
mov    %rax,%r14
mov    $0x2,%edi
call   1060 <factorCnt@plt>
mov    %eax,%r15d
xor    %ebp,%ebp
mov    $0x3,%ebx
nopl   (%rax)
mov    0x4(%rsp),%edx
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <factorCnt2@plt>
xor    %ecx,%ecx
cmp    %eax,%r15d
sete   %cl
add    %ecx,%ebp
add    $0x1,%ebx
mov    %eax,%r15d
cmp    $0x989681,%ebx
jne    1180 <main+0x30>
lea    0xe53(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32* @primes(i32 5000000, i32* %1)
%4 = call i32 @factorCnt(i32 2)
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ %4, %0 ], [ %11, %5 ]
%7 = phi i32 [ 2, %0 ], [ %9, %5 ]
%8 = phi i32 [ 0, %0 ], [ %14, %5 ]
%9 = add nuw nsw i32 %7, 1
%10 = load i32, i32* %1
%11 = call i32 @factorCnt2(i32 %9, i32* %3, i32 %10)
%12 = icmp eq i32 %6, %11
%13 = zext i1 %12 to i32
%14 = add nuw nsw i32 %8, %13
%15 = icmp eq i32 %9, 10000000
br i1 %15, label %16, label %5
16: ; preds = %5
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
%18 = call i32 @free(i32* %3)
ret i32 0
}