#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_ui(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_mod(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_sub_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int LucasLehmerTest(mpz_t m, int p) {
  int i, ret;
  mpz_t s;
  mpz_init_set_ui(s, 4);
  for (i = 2; i <= p - 1; i++) {
    mpz_mul(s, s, s);
    mpz_sub_ui(s, s, 2);
    mpz_mod(s, s, m);
  }
  ret = (mpz_cmp_ui(s, 0) == 0);
  mpz_clear(s);
  return (ret);
}


x86 assembly (clang, -O0):
<LucasLehmerTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x4,%esi
call   1060 <mpz_init_set_ui@plt>
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     11cd <LucasLehmerTest+0x6d>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <mpz_mul@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    $0x2,%edx
call   1040 <mpz_sub_ui@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1070 <mpz_mod@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1182 <LucasLehmerTest+0x22>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LucasLehmerTest>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
mov    $0x4,%esi
call   1060 <mpz_init_set_ui@plt>
cmp    $0x3,%ebx
jl     119b <LucasLehmerTest+0x3b>
add    $0xfffffffe,%ebx
nopl   0x0(%rax)
call   1030 <mpz_mul@plt>
mov    $0x2,%edx
call   1040 <mpz_sub_ui@plt>
mov    %ebp,%edx
call   1070 <mpz_mod@plt>
add    $0xffffffff,%ebx
jne    1180 <LucasLehmerTest+0x20>
xor    %esi,%esi
call   1050 <mpz_cmp_ui@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
call   1080 <mpz_clear@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @LucasLehmerTest(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %7
%9 = call i32 @mpz_init_set_ui(i32 %8, i32 4)
store i32 2, i32* %5
br label %10
10: ; preds = %27, %2
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
%14 = icmp sle i32 %11, %13
br i1 %14, label %15, label %30
15: ; preds = %10
%16 = load i32, i32* %7
%17 = load i32, i32* %7
%18 = load i32, i32* %7
%19 = call i32 @mpz_mul(i32 %16, i32 %17, i32 %18)
%20 = load i32, i32* %7
%21 = load i32, i32* %7
%22 = call i32 @mpz_sub_ui(i32 %20, i32 %21, i32 2)
%23 = load i32, i32* %7
%24 = load i32, i32* %7
%25 = load i32, i32* %3
%26 = call i32 @mpz_mod(i32 %23, i32 %24, i32 %25)
br label %27
27: ; preds = %15
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %10
30: ; preds = %10
%31 = load i32, i32* %7
%32 = call i64 @mpz_cmp_ui(i32 %31, i32 0)
%33 = icmp eq i64 %32, 0
%34 = zext i1 %33 to i32
store i32 %34, i32* %6
%35 = load i32, i32* %7
%36 = call i32 @mpz_clear(i32 %35)
%37 = load i32, i32* %6
ret i32 %37
}

LLVM IR (-O2):
define i32 @LucasLehmerTest(i32 %0, i32 %1) {
%3 = tail call i32 @mpz_init_set_ui(i32 undef, i32 4)
%4 = icmp sgt i32 %1, 2
br i1 %4, label %5, label %12
5: ; preds = %2, %5
%6 = phi i32 [ %10, %5 ], [ 2, %2 ]
%7 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
%8 = tail call i32 @mpz_sub_ui(i32 undef, i32 undef, i32 2)
%9 = tail call i32 @mpz_mod(i32 undef, i32 undef, i32 %0)
%10 = add nuw nsw i32 %6, 1
%11 = icmp eq i32 %10, %1
br i1 %11, label %12, label %5
12: ; preds = %5, %2
%13 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
%16 = tail call i32 @mpz_clear(i32 undef)
ret i32 %15
}