#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 */
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
scalar_t__ mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ mpz_cmp_ui(int /*<<< orphan*/, int);
scalar_t__ mpz_even_p(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_fdiv_q_2exp(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set(int /*<<< orphan*/, int /*<<< orphan*/);
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_sub_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int millerRabinStep(mpz_t a, mpz_t n) {
  int i = 1;
  int s = 0;
  mpz_t aPOWER;
  mpz_t d;
  mpz_t nMinusOne;
  mpz_init(nMinusOne);
  mpz_sub_ui(nMinusOne, n, 1);
  mpz_init_set(d, nMinusOne);
  while (mpz_even_p(d)) {
    mpz_fdiv_q_2exp(d, d, 1);
    s++;
  }
  mpz_init(aPOWER);
  mpz_powm(aPOWER, a, d, n);
  if (mpz_cmp_ui(aPOWER, 1) == 0) {
    mpz_clear(aPOWER);
    mpz_clear(d);
    mpz_clear(nMinusOne);
    return 1;
  }
  for (i = 0; i < s - 1; i++) {
    if (mpz_cmp(aPOWER, nMinusOne) == 0) {
      mpz_clear(aPOWER);
      mpz_clear(d);
      mpz_clear(nMinusOne);
      return 1;
    }
    mpz_powm_ui(aPOWER, aPOWER, 2, n);
  }
  if (mpz_cmp(aPOWER, nMinusOne) == 0) {
    mpz_clear(aPOWER);
    mpz_clear(d);
    mpz_clear(nMinusOne);
    return 1;
  }
  mpz_clear(aPOWER);
  mpz_clear(d);
  mpz_clear(nMinusOne);
  return 0;
}


x86 assembly (clang, -O0):
<millerRabinStep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0x20(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x1,%edx
call   1060 <mpz_sub_ui@plt>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   10c0 <mpz_init_set@plt>
mov    -0x1c(%rbp),%edi
call   1080 <mpz_even_p@plt>
cmp    $0x0,%rax
je     120f <millerRabinStep+0x6f>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   1050 <mpz_fdiv_q_2exp@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11df <millerRabinStep+0x3f>
mov    -0x18(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1030 <mpz_powm@plt>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1070 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    1263 <millerRabinStep+0xc3>
mov    -0x18(%rbp),%edi
call   10b0 <mpz_clear@plt>
mov    -0x1c(%rbp),%edi
call   10b0 <mpz_clear@plt>
mov    -0x20(%rbp),%edi
call   10b0 <mpz_clear@plt>
movl   $0x1,-0x4(%rbp)
jmp    132d <millerRabinStep+0x18d>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12d5 <millerRabinStep+0x135>
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%esi
call   10a0 <mpz_cmp@plt>
cmp    $0x0,%rax
jne    12b4 <millerRabinStep+0x114>
mov    -0x18(%rbp),%edi
call   10b0 <mpz_clear@plt>
mov    -0x1c(%rbp),%edi
call   10b0 <mpz_clear@plt>
mov    -0x20(%rbp),%edi
call   10b0 <mpz_clear@plt>
movl   $0x1,-0x4(%rbp)
jmp    132d <millerRabinStep+0x18d>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%ecx
mov    $0x2,%edx
call   1090 <mpz_powm_ui@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    126a <millerRabinStep+0xca>
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%esi
call   10a0 <mpz_cmp@plt>
cmp    $0x0,%rax
jne    130e <millerRabinStep+0x16e>
mov    -0x18(%rbp),%edi
call   10b0 <mpz_clear@plt>
mov    -0x1c(%rbp),%edi
call   10b0 <mpz_clear@plt>
mov    -0x20(%rbp),%edi
call   10b0 <mpz_clear@plt>
movl   $0x1,-0x4(%rbp)
jmp    132d <millerRabinStep+0x18d>
mov    -0x18(%rbp),%edi
call   10b0 <mpz_clear@plt>
mov    -0x1c(%rbp),%edi
call   10b0 <mpz_clear@plt>
mov    -0x20(%rbp),%edi
call   10b0 <mpz_clear@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<millerRabinStep>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%r14d
call   1040 <mpz_init@plt>
mov    %ebx,%esi
mov    $0x1,%edx
call   1060 <mpz_sub_ui@plt>
call   10c0 <mpz_init_set@plt>
call   1080 <mpz_even_p@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11e7 <millerRabinStep+0x47>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edx
call   1050 <mpz_fdiv_q_2exp@plt>
add    $0x1,%ebp
call   1080 <mpz_even_p@plt>
test   %rax,%rax
jne    11d0 <millerRabinStep+0x30>
call   1040 <mpz_init@plt>
mov    %r14d,%esi
mov    %ebx,%ecx
call   1030 <mpz_powm@plt>
mov    $0x1,%r14d
mov    $0x1,%esi
call   1070 <mpz_cmp_ui@plt>
test   %rax,%rax
je     124a <millerRabinStep+0xaa>
cmp    $0x2,%ebp
jl     123b <millerRabinStep+0x9b>
add    $0xffffffff,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   10a0 <mpz_cmp@plt>
test   %rax,%rax
je     1261 <millerRabinStep+0xc1>
mov    $0x2,%edx
mov    %ebx,%ecx
call   1090 <mpz_powm_ui@plt>
add    $0xffffffff,%ebp
jne    1220 <millerRabinStep+0x80>
call   10a0 <mpz_cmp@plt>
xor    %r14d,%r14d
test   %rax,%rax
sete   %r14b
call   10b0 <mpz_clear@plt>
call   10b0 <mpz_clear@plt>
call   10b0 <mpz_clear@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
call   10b0 <mpz_clear@plt>
call   10b0 <mpz_clear@plt>
call   10b0 <mpz_clear@plt>
mov    $0x1,%r14d
jmp    1259 <millerRabinStep+0xb9>

LLVM IR (-O0):
define i32 @millerRabinStep(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 1, i32* %6
store i32 0, i32* %7
%11 = load i32, i32* %10
%12 = call i32 @mpz_init(i32 %11)
%13 = load i32, i32* %10
%14 = load i32, i32* %5
%15 = call i32 @mpz_sub_ui(i32 %13, i32 %14, i32 1)
%16 = load i32, i32* %9
%17 = load i32, i32* %10
%18 = call i32 @mpz_init_set(i32 %16, i32 %17)
br label %19
19: ; preds = %23, %2
%20 = load i32, i32* %9
%21 = call i64 @mpz_even_p(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i32, i32* %9
%25 = load i32, i32* %9
%26 = call i32 @mpz_fdiv_q_2exp(i32 %24, i32 %25, i32 1)
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %19
29: ; preds = %19
%30 = load i32, i32* %8
%31 = call i32 @mpz_init(i32 %30)
%32 = load i32, i32* %8
%33 = load i32, i32* %4
%34 = load i32, i32* %9
%35 = load i32, i32* %5
%36 = call i32 @mpz_powm(i32 %32, i32 %33, i32 %34, i32 %35)
%37 = load i32, i32* %8
%38 = call i64 @mpz_cmp_ui(i32 %37, i32 1)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %29
%41 = load i32, i32* %8
%42 = call i32 @mpz_clear(i32 %41)
%43 = load i32, i32* %9
%44 = call i32 @mpz_clear(i32 %43)
%45 = load i32, i32* %10
%46 = call i32 @mpz_clear(i32 %45)
store i32 1, i32* %3
br label %92
47: ; preds = %29
store i32 0, i32* %6
br label %48
48: ; preds = %70, %47
%49 = load i32, i32* %6
%50 = load i32, i32* %7
%51 = sub nsw i32 %50, 1
%52 = icmp slt i32 %49, %51
br i1 %52, label %53, label %73
53: ; preds = %48
%54 = load i32, i32* %8
%55 = load i32, i32* %10
%56 = call i64 @mpz_cmp(i32 %54, i32 %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %65
58: ; preds = %53
%59 = load i32, i32* %8
%60 = call i32 @mpz_clear(i32 %59)
%61 = load i32, i32* %9
%62 = call i32 @mpz_clear(i32 %61)
%63 = load i32, i32* %10
%64 = call i32 @mpz_clear(i32 %63)
store i32 1, i32* %3
br label %92
65: ; preds = %53
%66 = load i32, i32* %8
%67 = load i32, i32* %8
%68 = load i32, i32* %5
%69 = call i32 @mpz_powm_ui(i32 %66, i32 %67, i32 2, i32 %68)
br label %70
70: ; preds = %65
%71 = load i32, i32* %6
%72 = add nsw i32 %71, 1
store i32 %72, i32* %6
br label %48
73: ; preds = %48
%74 = load i32, i32* %8
%75 = load i32, i32* %10
%76 = call i64 @mpz_cmp(i32 %74, i32 %75)
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %85
78: ; preds = %73
%79 = load i32, i32* %8
%80 = call i32 @mpz_clear(i32 %79)
%81 = load i32, i32* %9
%82 = call i32 @mpz_clear(i32 %81)
%83 = load i32, i32* %10
%84 = call i32 @mpz_clear(i32 %83)
store i32 1, i32* %3
br label %92
85: ; preds = %73
%86 = load i32, i32* %8
%87 = call i32 @mpz_clear(i32 %86)
%88 = load i32, i32* %9
%89 = call i32 @mpz_clear(i32 %88)
%90 = load i32, i32* %10
%91 = call i32 @mpz_clear(i32 %90)
store i32 0, i32* %3
br label %92
92: ; preds = %85, %78, %58, %40
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
define i32 @millerRabinStep(i32 %0, i32 %1) {
%3 = tail call i32 @mpz_init(i32 undef)
%4 = tail call i32 @mpz_sub_ui(i32 undef, i32 %1, i32 1)
%5 = tail call i32 @mpz_init_set(i32 undef, i32 undef)
%6 = tail call i64 @mpz_even_p(i32 undef)
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %2, %8
%9 = phi i32 [ %11, %8 ], [ 0, %2 ]
%10 = tail call i32 @mpz_fdiv_q_2exp(i32 undef, i32 undef, i32 1)
%11 = add nuw nsw i32 %9, 1
%12 = tail call i64 @mpz_even_p(i32 undef)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %8
14: ; preds = %8, %2
%15 = phi i32 [ 0, %2 ], [ %11, %8 ]
%16 = tail call i32 @mpz_init(i32 undef)
%17 = tail call i32 @mpz_powm(i32 undef, i32 %0, i32 undef, i32 %1)
%18 = tail call i64 @mpz_cmp_ui(i32 undef, i32 1)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %14
%21 = add i32 %15, -1
%22 = icmp sgt i32 %15, 1
br i1 %22, label %27, label %39
23: ; preds = %14
%24 = tail call i32 @mpz_clear(i32 undef)
%25 = tail call i32 @mpz_clear(i32 undef)
%26 = tail call i32 @mpz_clear(i32 undef)
br label %46
27: ; preds = %20, %35
%28 = phi i32 [ %37, %35 ], [ 0, %20 ]
%29 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = tail call i32 @mpz_clear(i32 undef)
%33 = tail call i32 @mpz_clear(i32 undef)
%34 = tail call i32 @mpz_clear(i32 undef)
br label %46
35: ; preds = %27
%36 = tail call i32 @mpz_powm_ui(i32 undef, i32 undef, i32 2, i32 %1)
%37 = add nuw nsw i32 %28, 1
%38 = icmp eq i32 %37, %21
br i1 %38, label %39, label %27
39: ; preds = %35, %20
%40 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%41 = icmp eq i64 %40, 0
%42 = tail call i32 @mpz_clear(i32 undef)
%43 = tail call i32 @mpz_clear(i32 undef)
%44 = tail call i32 @mpz_clear(i32 undef)
%45 = zext i1 %41 to i32
br label %46
46: ; preds = %39, %31, %23
%47 = phi i32 [ 1, %23 ], [ 1, %31 ], [ %45, %39 ]
ret i32 %47
}