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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ ifc(char);
char *mpf_get_str(int /*<<< orphan*/, int *, int, int /*<<< orphan*/,
                  int /*<<< orphan*/);
int /*<<< orphan*/ mpf_init2(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpf_set_ui(int /*<<< orphan*/, long);
int /*<<< orphan*/ mpf_sqrt(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ mpz_cmp_ui(int /*<<< orphan*/, long);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, long);
int /*<<< orphan*/ mpz_sqrt(int /*<<< orphan*/, int /*<<< orphan*/);
int euler_problem_80() {
  mpz_t chk;
  mpz_init(chk);
  mpf_t n;
  mpf_init2(n, 2000);
  mp_exp_t e = 1;
  long sum = 0;
  for (long i = 2; i < 100; ++i) {
    mpz_set_ui(chk, i);
    mpz_sqrt(chk, chk);
    mpz_mul(chk, chk, chk);
    if (mpz_cmp_ui(chk, i) == 0) {
      continue;
    }
    mpf_set_ui(n, i);
    mpf_sqrt(n, n);
    char *str = mpf_get_str(0, &e, 10, 0, n);
    int cnt = -1;
    for (int i = 0; i < 100; ++i) {
      sum += ifc(str[i]);
    }
    free(str);
  }
  return sum;
}


x86 assembly (clang, -O0):
<euler_problem_80>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    -0x4(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x8(%rbp),%edi
mov    $0x7d0,%esi
call   10d0 <mpf_init2@plt>
movl   $0x1,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x2,-0x20(%rbp)
cmpq   $0x64,-0x20(%rbp)
jge    12b9 <euler_problem_80+0x109>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   10b0 <mpz_set_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   10a0 <mpz_sqrt@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1070 <mpz_mul@plt>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1090 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    122f <euler_problem_80+0x7f>
jmp    12a8 <euler_problem_80+0xf8>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1080 <mpf_set_ui@plt>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <mpf_sqrt@plt>
mov    -0x8(%rbp),%r8d
xor    %ecx,%ecx
lea    -0xc(%rbp),%rsi
mov    $0xa,%edx
mov    %ecx,%edi
call   10c0 <mpf_get_str@plt>
mov    %rax,-0x28(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x64,-0x30(%rbp)
jge    129f <euler_problem_80+0xef>
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <ifc@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    126e <euler_problem_80+0xbe>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11e4 <euler_problem_80+0x34>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euler_problem_80>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
call   1060 <mpz_init@plt>
mov    $0x7d0,%esi
call   10d0 <mpf_init2@plt>
movl   $0x1,0xc(%rsp)
mov    $0x2,%r14d
xor    %r13d,%r13d
lea    0xc(%rsp),%r15
jmp    11fa <euler_problem_80+0x4a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r14
cmp    $0x64,%r14
je     1261 <euler_problem_80+0xb1>
mov    %r14,%rsi
call   10b0 <mpz_set_ui@plt>
call   10a0 <mpz_sqrt@plt>
call   1070 <mpz_mul@plt>
mov    %r14,%rsi
call   1090 <mpz_cmp_ui@plt>
test   %rax,%rax
je     11f0 <euler_problem_80+0x40>
mov    %r14,%rsi
call   1080 <mpf_set_ui@plt>
call   1050 <mpf_sqrt@plt>
xor    %edi,%edi
mov    %r15,%rsi
mov    $0xa,%edx
xor    %ecx,%ecx
call   10c0 <mpf_get_str@plt>
mov    %rax,%r12
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl (%r12,%rbx,1),%edi
call   1040 <ifc@plt>
add    %rax,%r13
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1240 <euler_problem_80+0x90>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    11f0 <euler_problem_80+0x40>
mov    %r13d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @euler_problem_80() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = load i32, i32* %1
%10 = call i32 @mpz_init(i32 %9)
%11 = load i32, i32* %2
%12 = call i32 @mpf_init2(i32 %11, i32 2000)
store i32 1, i32* %3
store i64 0, i64* %4
store i64 2, i64* %5
br label %13
13: ; preds = %59, %0
%14 = load i64, i64* %5
%15 = icmp slt i64 %14, 100
br i1 %15, label %16, label %62
16: ; preds = %13
%17 = load i32, i32* %1
%18 = load i64, i64* %5
%19 = call i32 @mpz_set_ui(i32 %17, i64 %18)
%20 = load i32, i32* %1
%21 = load i32, i32* %1
%22 = call i32 @mpz_sqrt(i32 %20, i32 %21)
%23 = load i32, i32* %1
%24 = load i32, i32* %1
%25 = load i32, i32* %1
%26 = call i32 @mpz_mul(i32 %23, i32 %24, i32 %25)
%27 = load i32, i32* %1
%28 = load i64, i64* %5
%29 = call i64 @mpz_cmp_ui(i32 %27, i64 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %16
br label %59
32: ; preds = %16
%33 = load i32, i32* %2
%34 = load i64, i64* %5
%35 = call i32 @mpf_set_ui(i32 %33, i64 %34)
%36 = load i32, i32* %2
%37 = load i32, i32* %2
%38 = call i32 @mpf_sqrt(i32 %36, i32 %37)
%39 = load i32, i32* %2
%40 = call i8* @mpf_get_str(i32 0, i32* %3, i32 10, i32 0, i32 %39)
store i8* %40, i8** %6
store i32 -1, i32* %7
store i32 0, i32* %8
br label %41
41: ; preds = %53, %32
%42 = load i32, i32* %8
%43 = icmp slt i32 %42, 100
br i1 %43, label %44, label %56
44: ; preds = %41
%45 = load i8*, i8** %6
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = call i64 @ifc(i8 signext %49)
%51 = load i64, i64* %4
%52 = add nsw i64 %51, %50
store i64 %52, i64* %4
br label %53
53: ; preds = %44
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %41
56: ; preds = %41
%57 = load i8*, i8** %6
%58 = call i32 @free(i8* %57)
br label %59
59: ; preds = %56, %31
%60 = load i64, i64* %5
%61 = add nsw i64 %60, 1
store i64 %61, i64* %5
br label %13
62: ; preds = %13
%63 = load i64, i64* %4
%64 = trunc i64 %63 to i32
ret i32 %64
}

LLVM IR (-O2):
define i32 @euler_problem_80() {
%1 = alloca i32
%2 = tail call i32 @mpz_init(i32 undef)
%3 = tail call i32 @mpf_init2(i32 undef, i32 2000)
%4 = bitcast i32* %1 to i8*
store i32 1, i32* %1
br label %7
5: ; preds = %30
%6 = trunc i64 %31 to i32
ret i32 %6
7: ; preds = %0, %30
%8 = phi i64 [ 2, %0 ], [ %32, %30 ]
%9 = phi i64 [ 0, %0 ], [ %31, %30 ]
%10 = call i32 @mpz_set_ui(i32 undef, i64 %8)
%11 = call i32 @mpz_sqrt(i32 undef, i32 undef)
%12 = call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
%13 = call i64 @mpz_cmp_ui(i32 undef, i64 %8)
%14 = icmp eq i64 %13, 0
br i1 %14, label %30, label %15
15: ; preds = %7
%16 = call i32 @mpf_set_ui(i32 undef, i64 %8)
%17 = call i32 @mpf_sqrt(i32 undef, i32 undef)
%18 = call i8* @mpf_get_str(i32 0, i32* %1, i32 10, i32 0, i32 undef)
br label %21
19: ; preds = %21
%20 = call i32 @free(i8* %18)
br label %30
21: ; preds = %15, %21
%22 = phi i64 [ 0, %15 ], [ %28, %21 ]
%23 = phi i64 [ %9, %15 ], [ %27, %21 ]
%24 = getelementptr inbounds i8, i8* %18, i64 %22
%25 = load i8, i8* %24
%26 = call i64 @ifc(i8 signext %25)
%27 = add nsw i64 %26, %23
%28 = add nuw nsw i64 %22, 1
%29 = icmp eq i64 %28, 100
br i1 %29, label %19, label %21
30: ; preds = %7, %19
%31 = phi i64 [ %9, %7 ], [ %27, %19 ]
%32 = add nuw nsw i64 %8, 1
%33 = icmp eq i64 %32, 100
br i1 %33, label %5, label %7
}