#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__ mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ mpz_cmp_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_powm(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_powm_ui(int /*<<< orphan*/, int /*<<< orphan*/, int,
                               int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, unsigned long);
int mrcore(mpz_t min_one, mpz_t a, unsigned long int a_given,
           unsigned long int k, mpz_t b0, mpz_t b, mpz_t m, mpz_t n) {
  unsigned long int i;
  mpz_set_ui(a, a_given);
  mpz_powm(b0, a, m, n);
  if (mpz_cmp_ui(b0, 1) == 0 || mpz_cmp(b0, min_one) == 0) {
    return 1;
  }
  mpz_set(b, b0);
  for (i = 1; i <= k - 1; i++) {
    mpz_powm_ui(b, b, 2, n);
    if (mpz_cmp_ui(b, 1) == 0) {
      return 0;
    } else if (mpz_cmp(b, min_one) == 0) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<mrcore>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1080 <mpz_set_ui@plt>
mov    -0x24(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    0x10(%rbp),%edx
mov    0x18(%rbp),%ecx
call   1030 <mpz_powm@plt>
mov    -0x24(%rbp),%edi
mov    $0x1,%esi
call   1050 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
je     11cd <mrcore+0x6d>
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1070 <mpz_cmp@plt>
cmp    $0x0,%rax
jne    11d9 <mrcore+0x79>
movl   $0x1,-0x4(%rbp)
jmp    127a <mrcore+0x11a>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1040 <mpz_set@plt>
movq   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
ja     1273 <mrcore+0x113>
mov    -0x28(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    0x18(%rbp),%ecx
mov    $0x2,%edx
call   1060 <mpz_powm_ui@plt>
mov    -0x28(%rbp),%edi
mov    $0x1,%esi
call   1050 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    1237 <mrcore+0xd7>
movl   $0x0,-0x4(%rbp)
jmp    127a <mrcore+0x11a>
mov    -0x28(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1070 <mpz_cmp@plt>
cmp    $0x0,%rax
jne    1258 <mrcore+0xf8>
movl   $0x1,-0x4(%rbp)
jmp    127a <mrcore+0x11a>
jmp    125d <mrcore+0xfd>
jmp    1262 <mrcore+0x102>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11ec <mrcore+0x8c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mrcore>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%ebx
mov    %r8d,%r15d
mov    %rcx,%r14
mov    %esi,%ebp
mov    %edi,%r13d
mov    0x48(%rsp),%r12d
mov    %esi,%edi
mov    %rdx,%rsi
call   1080 <mpz_set_ui@plt>
mov    %r15d,%edi
mov    %ebp,%esi
mov    0x40(%rsp),%edx
mov    %r12d,%ecx
call   1030 <mpz_powm@plt>
mov    $0x1,%r12d
mov    %r15d,%edi
mov    $0x1,%esi
call   1050 <mpz_cmp_ui@plt>
test   %rax,%rax
je     1222 <mrcore+0xc2>
mov    %r15d,%edi
mov    %r13d,%esi
call   1070 <mpz_cmp@plt>
test   %rax,%rax
je     1222 <mrcore+0xc2>
mov    %ebx,%edi
mov    %r15d,%esi
call   1040 <mpz_set@plt>
xor    %r12d,%r12d
add    $0xffffffffffffffff,%r14
je     1222 <mrcore+0xc2>
mov    $0x1,%ebp
mov    0x48(%rsp),%r15d
xchg   %ax,%ax
mov    %ebx,%edi
mov    %ebx,%esi
mov    $0x2,%edx
mov    %r15d,%ecx
call   1060 <mpz_powm_ui@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1050 <mpz_cmp_ui@plt>
test   %rax,%rax
je     1222 <mrcore+0xc2>
mov    %ebx,%edi
mov    %r13d,%esi
call   1070 <mpz_cmp@plt>
test   %rax,%rax
je     121c <mrcore+0xbc>
add    $0x1,%rbp
cmp    %r14,%rbp
jbe    11e0 <mrcore+0x80>
jmp    1222 <mrcore+0xc2>
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mrcore(i32 %0, i32 %1, i64 %2, i64 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i64
store i32 %0, i32* %10
store i32 %1, i32* %11
store i64 %2, i64* %12
store i64 %3, i64* %13
store i32 %4, i32* %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
%19 = load i32, i32* %11
%20 = load i64, i64* %12
%21 = call i32 @mpz_set_ui(i32 %19, i64 %20)
%22 = load i32, i32* %14
%23 = load i32, i32* %11
%24 = load i32, i32* %16
%25 = load i32, i32* %17
%26 = call i32 @mpz_powm(i32 %22, i32 %23, i32 %24, i32 %25)
%27 = load i32, i32* %14
%28 = call i64 @mpz_cmp_ui(i32 %27, i32 1)
%29 = icmp eq i64 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %8
%31 = load i32, i32* %14
%32 = load i32, i32* %10
%33 = call i64 @mpz_cmp(i32 %31, i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30, %8
store i32 1, i32* %9
br label %66
36: ; preds = %30
%37 = load i32, i32* %15
%38 = load i32, i32* %14
%39 = call i32 @mpz_set(i32 %37, i32 %38)
store i64 1, i64* %18
br label %40
40: ; preds = %62, %36
%41 = load i64, i64* %18
%42 = load i64, i64* %13
%43 = sub i64 %42, 1
%44 = icmp ule i64 %41, %43
br i1 %44, label %45, label %65
45: ; preds = %40
%46 = load i32, i32* %15
%47 = load i32, i32* %15
%48 = load i32, i32* %17
%49 = call i32 @mpz_powm_ui(i32 %46, i32 %47, i32 2, i32 %48)
%50 = load i32, i32* %15
%51 = call i64 @mpz_cmp_ui(i32 %50, i32 1)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %45
store i32 0, i32* %9
br label %66
54: ; preds = %45
%55 = load i32, i32* %15
%56 = load i32, i32* %10
%57 = call i64 @mpz_cmp(i32 %55, i32 %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %54
store i32 1, i32* %9
br label %66
60: ; preds = %54
br label %61
61: ; preds = %60
br label %62
62: ; preds = %61
%63 = load i64, i64* %18
%64 = add i64 %63, 1
store i64 %64, i64* %18
br label %40
65: ; preds = %40
store i32 0, i32* %9
br label %66
66: ; preds = %65, %59, %53, %35
%67 = load i32, i32* %9
ret i32 %67
}

LLVM IR (-O2):
define i32 @mrcore(i32 %0, i32 %1, i64 %2, i64 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = tail call i32 @mpz_set_ui(i32 %1, i64 %2)
%10 = tail call i32 @mpz_powm(i32 %4, i32 %1, i32 %6, i32 %7)
%11 = tail call i64 @mpz_cmp_ui(i32 %4, i32 1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %31, label %13
13: ; preds = %8
%14 = tail call i64 @mpz_cmp(i32 %4, i32 %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %31, label %16
16: ; preds = %13
%17 = tail call i32 @mpz_set(i32 %5, i32 %4)
%18 = add i64 %3, -1
%19 = icmp eq i64 %18, 0
br i1 %19, label %31, label %22
20: ; preds = %27
%21 = icmp ugt i64 %30, %18
br i1 %21, label %31, label %22
22: ; preds = %16, %20
%23 = phi i64 [ %30, %20 ], [ 1, %16 ]
%24 = tail call i32 @mpz_powm_ui(i32 %5, i32 %5, i32 2, i32 %7)
%25 = tail call i64 @mpz_cmp_ui(i32 %5, i32 1)
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %22
%28 = tail call i64 @mpz_cmp(i32 %5, i32 %0)
%29 = icmp eq i64 %28, 0
%30 = add i64 %23, 1
br i1 %29, label %31, label %20
31: ; preds = %22, %27, %20, %16, %8, %13
%32 = phi i32 [ 1, %13 ], [ 1, %8 ], [ 0, %16 ], [ 0, %22 ], [ 1, %27 ], [ 0, %20 ]
ret i32 %32
}