#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);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mod_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_sqrt(int /*<<< orphan*/, int /*<<< orphan*/);
int es_primo(mpz_t num) {
  mpz_t max;
  mpz_init(max);
  mpz_t tmp;
  mpz_init(tmp);
  mpz_sqrt(max, num);
  int k = 3;
  mpz_mod_ui(tmp, num, 2);
  if (!mpz_cmp_ui(tmp, 0))
    return !mpz_cmp_ui(num, 2);
  for (; mpz_cmp_ui(max, k) > 0; k += 2) {
    mpz_mod_ui(tmp, num, k);
    if (!mpz_cmp_ui(tmp, 0))
      return 0;
  }
  mpz_clear(max);
  mpz_clear(tmp);
  return 1;
}


x86 assembly (clang, -O0):
<es_primo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0x10(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <mpz_sqrt@plt>
movl   $0x3,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0x2,%edx
call   1030 <mpz_mod_ui@plt>
mov    -0x10(%rbp),%edi
xor    %esi,%esi
call   1050 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    11c4 <es_primo+0x74>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1050 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1236 <es_primo+0xe6>
jmp    11c9 <es_primo+0x79>
mov    -0xc(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1050 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jle    121f <es_primo+0xcf>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <mpz_mod_ui@plt>
mov    -0x10(%rbp),%edi
xor    %esi,%esi
call   1050 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    120c <es_primo+0xbc>
movl   $0x0,-0x4(%rbp)
jmp    1236 <es_primo+0xe6>
jmp    1211 <es_primo+0xc1>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    11c9 <es_primo+0x79>
mov    -0xc(%rbp),%edi
call   1070 <mpz_clear@plt>
mov    -0x10(%rbp),%edi
call   1070 <mpz_clear@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<es_primo>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
call   1040 <mpz_init@plt>
call   1040 <mpz_init@plt>
mov    %r14d,%esi
call   1060 <mpz_sqrt@plt>
mov    %r14d,%esi
mov    $0x2,%edx
call   1030 <mpz_mod_ui@plt>
xor    %esi,%esi
call   1050 <mpz_cmp_ui@plt>
test   %rax,%rax
je     11d6 <es_primo+0x86>
mov    $0x3,%ebp
mov    $0x3,%esi
call   1050 <mpz_cmp_ui@plt>
test   %rax,%rax
jle    11c5 <es_primo+0x75>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14d,%esi
mov    %ebp,%edx
call   1030 <mpz_mod_ui@plt>
xor    %esi,%esi
call   1050 <mpz_cmp_ui@plt>
test   %rax,%rax
je     11eb <es_primo+0x9b>
add    $0x2,%ebp
mov    %ebp,%esi
call   1050 <mpz_cmp_ui@plt>
test   %rax,%rax
jg     11a0 <es_primo+0x50>
call   1070 <mpz_clear@plt>
call   1070 <mpz_clear@plt>
mov    $0x1,%ebx
jmp    11eb <es_primo+0x9b>
mov    %r14d,%edi
mov    $0x2,%esi
call   1050 <mpz_cmp_ui@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @es_primo(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %4
%8 = call i32 @mpz_init(i32 %7)
%9 = load i32, i32* %5
%10 = call i32 @mpz_init(i32 %9)
%11 = load i32, i32* %4
%12 = load i32, i32* %3
%13 = call i32 @mpz_sqrt(i32 %11, i32 %12)
store i32 3, i32* %6
%14 = load i32, i32* %5
%15 = load i32, i32* %3
%16 = call i32 @mpz_mod_ui(i32 %14, i32 %15, i32 2)
%17 = load i32, i32* %5
%18 = call i64 @mpz_cmp_ui(i32 %17, i32 0)
%19 = icmp ne i64 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %1
%21 = load i32, i32* %3
%22 = call i64 @mpz_cmp_ui(i32 %21, i32 2)
%23 = icmp ne i64 %22, 0
%24 = xor i1 %23, true
%25 = zext i1 %24 to i32
store i32 %25, i32* %2
br label %50
26: ; preds = %1
br label %27
27: ; preds = %42, %26
%28 = load i32, i32* %4
%29 = load i32, i32* %6
%30 = call i64 @mpz_cmp_ui(i32 %28, i32 %29)
%31 = icmp sgt i64 %30, 0
br i1 %31, label %32, label %45
32: ; preds = %27
%33 = load i32, i32* %5
%34 = load i32, i32* %3
%35 = load i32, i32* %6
%36 = call i32 @mpz_mod_ui(i32 %33, i32 %34, i32 %35)
%37 = load i32, i32* %5
%38 = call i64 @mpz_cmp_ui(i32 %37, i32 0)
%39 = icmp ne i64 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %32
store i32 0, i32* %2
br label %50
41: ; preds = %32
br label %42
42: ; preds = %41
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 2
store i32 %44, i32* %6
br label %27
45: ; preds = %27
%46 = load i32, i32* %4
%47 = call i32 @mpz_clear(i32 %46)
%48 = load i32, i32* %5
%49 = call i32 @mpz_clear(i32 %48)
store i32 1, i32* %2
br label %50
50: ; preds = %45, %40, %20
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
define i32 @es_primo(i32 %0) {
%2 = tail call i32 @mpz_init(i32 undef)
%3 = tail call i32 @mpz_init(i32 undef)
%4 = tail call i32 @mpz_sqrt(i32 undef, i32 %0)
%5 = tail call i32 @mpz_mod_ui(i32 undef, i32 %0, i32 2)
%6 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = tail call i64 @mpz_cmp_ui(i32 undef, i32 3)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %18, label %24
11: ; preds = %1
%12 = tail call i64 @mpz_cmp_ui(i32 %0, i32 2)
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
br label %27
15: ; preds = %18
%16 = tail call i64 @mpz_cmp_ui(i32 undef, i32 %23)
%17 = icmp sgt i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %8, %15
%19 = phi i32 [ %23, %15 ], [ 3, %8 ]
%20 = tail call i32 @mpz_mod_ui(i32 undef, i32 %0, i32 %19)
%21 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%22 = icmp eq i64 %21, 0
%23 = add nuw nsw i32 %19, 2
br i1 %22, label %27, label %15
24: ; preds = %15, %8
%25 = tail call i32 @mpz_clear(i32 undef)
%26 = tail call i32 @mpz_clear(i32 undef)
br label %27
27: ; preds = %18, %24, %11
%28 = phi i32 [ 1, %24 ], [ %14, %11 ], [ 0, %18 ]
ret i32 %28
}