#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 a(long, long *, long *);
scalar_t__ is_prime(long);
scalar_t__ malloc(int);
long euler_problem_77() {
  long pcnt = 2000;
  long *primes = (long *)malloc(sizeof(long) * pcnt);
  primes[0] = 2;
  long count = 1;
  for (long i = 3; count < pcnt; i += 2) {
    if (is_prime(i)) {
      primes[count] = i;
      ++count;
    }
  }
  long acount = 10000;
  long *acache = (long *)malloc(sizeof(long) * acount);
  for (long i = 0; i < acount; ++i) {
    acache[i] = 0;
  }
  acache[0] = 1;
  acache[1] = 0;
  for (long i = 4;; ++i) {
    if (a(i, primes, acache) > 5000) {
      return i;
    }
  }
}


x86 assembly (clang, -O0):
<euler_problem_77>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x7d0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x2,(%rax)
movq   $0x1,-0x18(%rbp)
movq   $0x3,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    11c1 <euler_problem_77+0x91>
mov    -0x20(%rbp),%rdi
call   1030 <is_prime@plt>
cmp    $0x0,%rax
je     11ab <euler_problem_77+0x7b>
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11b0 <euler_problem_77+0x80>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    116e <euler_problem_77+0x3e>
movq   $0x2710,-0x28(%rbp)
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    1213 <euler_problem_77+0xe3>
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11e4 <euler_problem_77+0xb4>
mov    -0x30(%rbp),%rax
movq   $0x1,(%rax)
mov    -0x30(%rbp),%rax
movq   $0x0,0x8(%rax)
movq   $0x4,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <a@plt>
cmp    $0x1388,%eax
jle    1258 <euler_problem_77+0x128>
mov    -0x40(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret
jmp    125d <euler_problem_77+0x12d>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1232 <euler_problem_77+0x102>

x86 assembly (clang, -O2):
<euler_problem_77>:
push   %r15
push   %r14
push   %rbx
mov    $0x3e80,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
movq   $0x2,(%rax)
mov    $0x3,%ebx
mov    $0x1,%r15d
jmp    117d <euler_problem_77+0x3d>
cs nopw 0x0(%rax,%rax,1)
add    $0x2,%rbx
cmp    $0x7d0,%r15
jge    1194 <euler_problem_77+0x54>
mov    %rbx,%rdi
call   1040 <is_prime@plt>
test   %rax,%rax
je     1170 <euler_problem_77+0x30>
mov    %rbx,(%r14,%r15,8)
add    $0x1,%r15
jmp    1170 <euler_problem_77+0x30>
mov    $0x13880,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    $0x13880,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
movaps 0xe49(%rip),%xmm0
movups %xmm0,(%r15)
mov    $0x3,%ebx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <a@plt>
cmp    $0x1389,%eax
jl     11c0 <euler_problem_77+0x80>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @euler_problem_77() {
%1 = alloca i64
%2 = alloca i64*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i64
store i64 2000, i64* %1
%9 = load i64, i64* %1
%10 = mul i64 8, %9
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i64*
store i64* %13, i64** %2
%14 = load i64*, i64** %2
%15 = getelementptr inbounds i64, i64* %14, i64 0
store i64 2, i64* %15
store i64 1, i64* %3
store i64 3, i64* %4
br label %16
16: ; preds = %32, %0
%17 = load i64, i64* %3
%18 = load i64, i64* %1
%19 = icmp slt i64 %17, %18
br i1 %19, label %20, label %35
20: ; preds = %16
%21 = load i64, i64* %4
%22 = call i64 @is_prime(i64 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %20
%25 = load i64, i64* %4
%26 = load i64*, i64** %2
%27 = load i64, i64* %3
%28 = getelementptr inbounds i64, i64* %26, i64 %27
store i64 %25, i64* %28
%29 = load i64, i64* %3
%30 = add nsw i64 %29, 1
store i64 %30, i64* %3
br label %31
31: ; preds = %24, %20
br label %32
32: ; preds = %31
%33 = load i64, i64* %4
%34 = add nsw i64 %33, 2
store i64 %34, i64* %4
br label %16
35: ; preds = %16
store i64 10000, i64* %5
%36 = load i64, i64* %5
%37 = mul i64 8, %36
%38 = trunc i64 %37 to i32
%39 = call i64 @malloc(i32 %38)
%40 = inttoptr i64 %39 to i64*
store i64* %40, i64** %6
store i64 0, i64* %7
br label %41
41: ; preds = %49, %35
%42 = load i64, i64* %7
%43 = load i64, i64* %5
%44 = icmp slt i64 %42, %43
br i1 %44, label %45, label %52
45: ; preds = %41
%46 = load i64*, i64** %6
%47 = load i64, i64* %7
%48 = getelementptr inbounds i64, i64* %46, i64 %47
store i64 0, i64* %48
br label %49
49: ; preds = %45
%50 = load i64, i64* %7
%51 = add nsw i64 %50, 1
store i64 %51, i64* %7
br label %41
52: ; preds = %41
%53 = load i64*, i64** %6
%54 = getelementptr inbounds i64, i64* %53, i64 0
store i64 1, i64* %54
%55 = load i64*, i64** %6
%56 = getelementptr inbounds i64, i64* %55, i64 1
store i64 0, i64* %56
store i64 4, i64* %8
br label %57
57: ; preds = %66, %52
%58 = load i64, i64* %8
%59 = load i64*, i64** %2
%60 = load i64*, i64** %6
%61 = call i32 @a(i64 %58, i64* %59, i64* %60)
%62 = icmp sgt i32 %61, 5000
br i1 %62, label %63, label %65
63: ; preds = %57
%64 = load i64, i64* %8
ret i64 %64
65: ; preds = %57
br label %66
66: ; preds = %65
%67 = load i64, i64* %8
%68 = add nsw i64 %67, 1
store i64 %68, i64* %8
br label %57
}

LLVM IR (-O2):
define i64 @euler_problem_77() {
%1 = tail call i64 @malloc(i32 16000)
%2 = inttoptr i64 %1 to i64*
store i64 2, i64* %2
br label %8
3: ; preds = %16
%4 = tail call i64 @malloc(i32 80000)
%5 = inttoptr i64 %4 to i64*
%6 = inttoptr i64 %4 to i8*
%7 = inttoptr i64 %4 to <2 x i64>*
store <2 x i64> <i64 1, i64 0>, <2 x i64>* %7
br label %20
8: ; preds = %0, %16
%9 = phi i64 [ 1, %0 ], [ %17, %16 ]
%10 = phi i64 [ 3, %0 ], [ %18, %16 ]
%11 = tail call i64 @is_prime(i64 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = getelementptr inbounds i64, i64* %2, i64 %9
store i64 %10, i64* %14
%15 = add nsw i64 %9, 1
br label %16
16: ; preds = %8, %13
%17 = phi i64 [ %15, %13 ], [ %9, %8 ]
%18 = add nuw nsw i64 %10, 2
%19 = icmp slt i64 %17, 2000
br i1 %19, label %8, label %3
20: ; preds = %20, %3
%21 = phi i64 [ 4, %3 ], [ %24, %20 ]
%22 = tail call i32 @a(i64 %21, i64* %2, i64* %5)
%23 = icmp sgt i32 %22, 5000
%24 = add nuw nsw i64 %21, 1
br i1 %23, label %25, label %20
25: ; preds = %20
ret i64 %21
}