#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__ LucasLehmerTest(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_pow_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_sub_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int strtol(char *, int /*<<< orphan*/ *, int);
int main(int ac, char *av[]) {
  int p;
  mpz_t m;
  if (ac < 2) {
    printf("usage : mersenne p\n");
    return (1);
  }
  p = strtol(av[1], NULL, 10);
  mpz_init_set_ui(m, 2);
  mpz_pow_ui(m, m, p);
  mpz_sub_ui(m, m, 1);
  if (LucasLehmerTest(m, p))
    printf("OK\n");
  else
    printf("NG\n");
  mpz_clear(m);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a8 <main+0x38>
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122d <main+0xbd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    $0x2,%esi
call   1070 <mpz_init_set_ui@plt>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1080 <mpz_pow_ui@plt>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x1,%edx
call   1060 <mpz_sub_ui@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <LucasLehmerTest@plt>
cmp    $0x0,%rax
je     1212 <main+0xa2>
lea    0xe0c(%rip),%rdi
call   1030 <printf@plt>
jmp    121e <main+0xae>
lea    0xdff(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
call   1090 <mpz_clear@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     118b <main+0x1b>
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    11e0 <main+0x70>
mov    0x8(%rsi),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%ebp
mov    $0x2,%esi
call   1070 <mpz_init_set_ui@plt>
mov    %ebp,%edx
call   1080 <mpz_pow_ui@plt>
mov    $0x1,%edx
call   1060 <mpz_sub_ui@plt>
mov    %ebp,%esi
call   1040 <LucasLehmerTest@plt>
test   %rax,%rax
lea    0xe35(%rip),%rax
lea    0xe31(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
call   1090 <mpz_clear@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"usage : mersenne p\0A\00"
@.str.1 = [4 x i8] c"OK\0A\00"
@.str.2 = [4 x i8] c"NG\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %37
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @strtol(i8* %15, i32* null, i32 10)
store i32 %16, i32* %6
%17 = load i32, i32* %7
%18 = call i32 @mpz_init_set_ui(i32 %17, i32 2)
%19 = load i32, i32* %7
%20 = load i32, i32* %7
%21 = load i32, i32* %6
%22 = call i32 @mpz_pow_ui(i32 %19, i32 %20, i32 %21)
%23 = load i32, i32* %7
%24 = load i32, i32* %7
%25 = call i32 @mpz_sub_ui(i32 %23, i32 %24, i32 1)
%26 = load i32, i32* %7
%27 = load i32, i32* %6
%28 = call i64 @LucasLehmerTest(i32 %26, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %12
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %34
32: ; preds = %12
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %30
%35 = load i32, i32* %7
%36 = call i32 @mpz_clear(i32 %35)
store i32 0, i32* %3
br label %37
37: ; preds = %34, %10
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@str = [3 x i8] c"NG\00"
@str.3 = [3 x i8] c"OK\00"
@str.4 = [19 x i8] c"usage : mersenne p\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0))
br label %18
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strtol(i8* nocapture %8, i32* null, i32 10)
%10 = tail call i32 @mpz_init_set_ui(i32 undef, i32 2)
%11 = tail call i32 @mpz_pow_ui(i32 undef, i32 undef, i32 %9)
%12 = tail call i32 @mpz_sub_ui(i32 undef, i32 undef, i32 1)
%13 = tail call i64 @LucasLehmerTest(i32 undef, i32 %9)
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @str.3, i64 0, i64 0)
%16 = tail call i32 @puts(i8* dereferenceable(1) %15)
%17 = tail call i32 @mpz_clear(i32 undef)
br label %18
18: ; preds = %6, %4
%19 = phi i32 [ 1, %4 ], [ 0, %6 ]
ret i32 %19
}