#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 */
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
scalar_t__ malloc(int);
scalar_t__ mpz_cmp_ui(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mod_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_set_si(int /*<<< orphan*/, int);
int /*<<< orphan*/ p(long, int /*<<< orphan*/ *, int /*<<< orphan*/);
long euler_problem_78() {
  long pcsize = 200000;
  mpz_t *pcache = (mpz_t *)malloc(sizeof(mpz_t) * pcsize);
  for (long i = 0; i < pcsize; ++i) {
    mpz_init(pcache[i]);
  }
  mpz_set_si(pcache[0], 1);
  mpz_set_si(pcache[1], 1);
  mpz_t pr;
  mpz_init(pr);
  mpz_t md;
  mpz_init(md);
  for (long i = 0; i < 100000; ++i) {
    p(i, pcache, pr);
    mpz_mod_ui(md, pr, 1000000);
    if (mpz_cmp_ui(md, 0) == 0) {
      return i;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<euler_problem_78>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x30d40,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11ba <euler_problem_78+0x5a>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1060 <mpz_init@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    118b <euler_problem_78+0x2b>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1030 <mpz_set_si@plt>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
mov    $0x1,%esi
call   1030 <mpz_set_si@plt>
mov    -0x24(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x28(%rbp),%edi
call   1060 <mpz_init@plt>
movq   $0x0,-0x30(%rbp)
cmpq   $0x186a0,-0x30(%rbp)
jge    1258 <euler_problem_78+0xf8>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <p@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    $0xf4240,%edx
call   1050 <mpz_mod_ui@plt>
mov    -0x28(%rbp),%edi
xor    %esi,%esi
call   1080 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    1242 <euler_problem_78+0xe2>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1260 <euler_problem_78+0x100>
jmp    1247 <euler_problem_78+0xe7>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11f3 <euler_problem_78+0x93>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euler_problem_78>:
push   %r14
push   %rbx
push   %rax
mov    $0xc3500,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14,%rbx,4),%edi
call   1060 <mpz_init@plt>
add    $0x1,%rbx
cmp    $0x30d40,%rbx
jne    1180 <euler_problem_78+0x20>
mov    (%r14),%edi
mov    $0x1,%esi
call   1030 <mpz_set_si@plt>
mov    0x4(%r14),%edi
mov    $0x1,%esi
call   1030 <mpz_set_si@plt>
call   1060 <mpz_init@plt>
call   1060 <mpz_init@plt>
xor    %ebx,%ebx
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <p@plt>
mov    $0xf4240,%edx
call   1050 <mpz_mod_ui@plt>
xor    %esi,%esi
call   1080 <mpz_cmp_ui@plt>
test   %rax,%rax
je     11f0 <euler_problem_78+0x90>
add    $0x1,%rbx
cmp    $0x186a0,%rbx
jne    11c0 <euler_problem_78+0x60>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i64 @euler_problem_78() {
%1 = tail call i64 @malloc(i32 800000)
%2 = inttoptr i64 %1 to i32*
br label %11
3: ; preds = %11
%4 = load i32, i32* %2
%5 = tail call i32 @mpz_set_si(i32 %4, i32 1)
%6 = getelementptr inbounds i32, i32* %2, i64 1
%7 = load i32, i32* %6
%8 = tail call i32 @mpz_set_si(i32 %7, i32 1)
%9 = tail call i32 @mpz_init(i32 undef)
%10 = tail call i32 @mpz_init(i32 undef)
br label %18
11: ; preds = %0, %11
%12 = phi i64 [ 0, %0 ], [ %16, %11 ]
%13 = getelementptr inbounds i32, i32* %2, i64 %12
%14 = load i32, i32* %13
%15 = tail call i32 @mpz_init(i32 %14)
%16 = add nuw nsw i64 %12, 1
%17 = icmp eq i64 %16, 200000
br i1 %17, label %3, label %11
18: ; preds = %3, %24
%19 = phi i64 [ 0, %3 ], [ %25, %24 ]
%20 = tail call i32 @p(i64 %19, i32* %2, i32 undef)
%21 = tail call i32 @mpz_mod_ui(i32 undef, i32 undef, i32 1000000)
%22 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %18
%25 = add nuw nsw i64 %19, 1
%26 = icmp eq i64 %25, 100000
br i1 %26, label %27, label %18
27: ; preds = %18, %24
%28 = phi i64 [ %19, %18 ], [ 0, %24 ]
ret i64 %28
}