#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 */

/* Variables and functions */
int expModular(int, int, int);
int geraNumeroMax(int);
int primalidade(int n) {
  int b = n - 1;
  int i = 0;
  int a = 0;
  int result;
  while (i <= 100) {
    a = geraNumeroMax(n - 1);
    result = expModular(a, b, n);
    if (result != 1 % n) {
      return 0;
    }
    i++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<primalidade>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x10(%rbp)
jg     119f <primalidade+0x7f>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1030 <geraNumeroMax@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1040 <expModular@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x1,%eax
cltd
idivl  -0x8(%rbp)
mov    -0x1c(%rbp),%eax
cmp    %edx,%eax
je     1191 <primalidade+0x71>
movl   $0x0,-0x4(%rbp)
jmp    11a6 <primalidade+0x86>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1142 <primalidade+0x22>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<primalidade>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
lea    -0x1(%r14),%ebp
mov    $0x65,%ebx
mov    %ebp,%edi
call   1030 <geraNumeroMax@plt>
mov    %eax,%edi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <expModular@plt>
mov    %eax,%esi
xor    %ecx,%ecx
mov    $0x1,%eax
xor    %edx,%edx
idiv   %r14d
cmp    %edx,%esi
jne    115f <primalidade+0x3f>
add    $0xffffffff,%ebx
jne    1130 <primalidade+0x10>
mov    $0x1,%ecx
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @primalidade(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = sub nsw i32 %8, 1
store i32 %9, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %10
10: ; preds = %26, %1
%11 = load i32, i32* %5
%12 = icmp sle i32 %11, 100
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = load i32, i32* %3
%15 = sub nsw i32 %14, 1
%16 = call i32 @geraNumeroMax(i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = load i32, i32* %3
%20 = call i32 @expModular(i32 %17, i32 %18, i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = load i32, i32* %3
%23 = srem i32 1, %22
%24 = icmp ne i32 %21, %23
br i1 %24, label %25, label %26
25: ; preds = %13
store i32 0, i32* %2
br label %30
26: ; preds = %13
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %10
29: ; preds = %10
store i32 1, i32* %2
br label %30
30: ; preds = %29, %25
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @primalidade(i32 %0) {
%2 = add nsw i32 %0, -1
br label %6
3: ; preds = %6
%4 = add nuw nsw i32 %7, 1
%5 = icmp eq i32 %4, 101
br i1 %5, label %12, label %6
6: ; preds = %1, %3
%7 = phi i32 [ 0, %1 ], [ %4, %3 ]
%8 = tail call i32 @geraNumeroMax(i32 %2)
%9 = tail call i32 @expModular(i32 %8, i32 %2, i32 %0)
%10 = srem i32 1, %0
%11 = icmp eq i32 %9, %10
br i1 %11, label %3, label %12
12: ; preds = %3, %6
%13 = phi i32 [ 0, %6 ], [ 1, %3 ]
ret i32 %13
}