#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int a, p, inv, aux, b;
  printf("\nAlgebra A - 2015/2\n\nTrabalho Pratico - Parte 2 Exercicio "
         "1\n\nAutor: Ronald Davi Rodrigues Pereira - 2015004437\n\nCalculo do "
         "inverso de um numero\n\n");
  printf("Insira o número 'a' de qual devera ser calculado o inverso:\n>");
  scanf("%d", &a);
  printf("Insira o numero primo 'p' para o calculo do inverso de 'a':\n>");
  scanf("%d", &p);
  if (a % p == 0) {
    printf("P eh um divisor de A.\n");
    return 0;
  } else {
    for (b = 0; b < p; b++) {
      aux = (a * b) % p;
      if ((aux % p) == 1) {
        printf("\na = %d\np = %d\nInverso de a = %d\n", a, p, b);
        printf("\nO inverso de %d em %d eh %d, pois %d * %d eh equivalente a 1 "
               "(mod %d)\n",
               a, p, b, a, b, p);
        break;
      }
    }
    if (b == p)
      printf("\nO numero a = %d nao possui inverso em p = %d\n", a, p);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf7f(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xf72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf61(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11a3 <main+0x83>
lea    0xf82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1254 <main+0x134>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1228 <main+0x108>
mov    -0x8(%rbp),%eax
imul   -0x18(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x1,%edx
jne    1215 <main+0xf5>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xf45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%r8d
mov    -0x18(%rbp),%r9d
mov    -0xc(%rbp),%eax
lea    0xf45(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1228 <main+0x108>
jmp    121a <main+0xfa>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11aa <main+0x8a>
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1248 <main+0x128>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xf52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <main+0x12d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xfdb(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb6(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee5(%rip),%r14
lea    0x14(%rsp),%rsi
mov    %r14,%rdi
call   1050 <scanf@plt>
lea    0xed4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1050 <scanf@plt>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%ecx
mov    %esi,%eax
cltd
idiv   %ecx
test   %edx,%edx
je     11b5 <main+0x85>
test   %ecx,%ecx
jle    11fa <main+0xca>
xor    %edi,%edi
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %edi,%eax
cltd
idiv   %ecx
cmp    $0x1,%edx
je     11c3 <main+0x93>
add    $0x1,%ebx
add    %esi,%edi
cmp    %ebx,%ecx
jne    11a0 <main+0x70>
jmp    11fe <main+0xce>
lea    0xfee(%rip),%rdi
call   1030 <puts@plt>
jmp    1212 <main+0xe2>
lea    0xeb6(%rip),%rdi
mov    %ecx,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
mov    %edx,(%rsp)
lea    0xebb(%rip),%rdi
mov    %ebx,%ecx
mov    %esi,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%ecx
cmp    %ecx,%ebx
jne    1212 <main+0xe2>
mov    0x14(%rsp),%esi
lea    0xee1(%rip),%rdi
mov    %ecx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [146 x i8] c"\0AAlgebra A - 2015/2\0A\0ATrabalho Pratico - Parte 2 Exercicio 1\0A\0AAutor: Ronald Davi Rodrigues Pereira - 2015004437\0A\0ACalculo do inverso de um numero\0A\0A\00"
@.str.1 = [63 x i8] c"Insira o n\C3\BAmero 'a' de qual devera ser calculado o inverso:\0A>\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [62 x i8] c"Insira o numero primo 'p' para o calculo do inverso de 'a':\0A>\00"
@.str.4 = [23 x i8] c"P eh um divisor de A.\0A\00"
@.str.5 = [34 x i8] c"\0Aa = %d\0Ap = %d\0AInverso de a = %d\0A\00"
@.str.6 = [72 x i8] c"\0AO inverso de %d em %d eh %d, pois %d * %d eh equivalente a 1 (mod %d)\0A\00"
@.str.7 = [47 x i8] c"\0AO numero a = %d nao possui inverso em p = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = srem i32 %12, %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %59
18: ; preds = %0
store i32 0, i32* %6
br label %19
19: ; preds = %46, %18
%20 = load i32, i32* %6
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %49
23: ; preds = %19
%24 = load i32, i32* %2
%25 = load i32, i32* %6
%26 = mul nsw i32 %24, %25
%27 = load i32, i32* %3
%28 = srem i32 %26, %27
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = load i32, i32* %3
%31 = srem i32 %29, %30
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %45
33: ; preds = %23
%34 = load i32, i32* %2
%35 = load i32, i32* %3
%36 = load i32, i32* %6
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %34, i32 %35, i32 %36)
%38 = load i32, i32* %2
%39 = load i32, i32* %3
%40 = load i32, i32* %6
%41 = load i32, i32* %2
%42 = load i32, i32* %6
%43 = load i32, i32* %3
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.6, i64 0, i64 0), i32 %38, i32 %39, i32 %40, i32 %41, i32 %42, i32 %43)
br label %49
45: ; preds = %23
br label %46
46: ; preds = %45
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %19
49: ; preds = %33, %19
%50 = load i32, i32* %6
%51 = load i32, i32* %3
%52 = icmp eq i32 %50, %51
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = load i32, i32* %2
%55 = load i32, i32* %3
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i32 %54, i32 %55)
br label %57
57: ; preds = %53, %49
br label %58
58: ; preds = %57
store i32 0, i32* %1
br label %59
59: ; preds = %58, %16
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
@.str.1 = [63 x i8] c"Insira o n\C3\BAmero 'a' de qual devera ser calculado o inverso:\0A>\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [62 x i8] c"Insira o numero primo 'p' para o calculo do inverso de 'a':\0A>\00"
@.str.5 = [34 x i8] c"\0Aa = %d\0Ap = %d\0AInverso de a = %d\0A\00"
@.str.6 = [72 x i8] c"\0AO inverso de %d em %d eh %d, pois %d * %d eh equivalente a 1 (mod %d)\0A\00"
@.str.7 = [47 x i8] c"\0AO numero a = %d nao possui inverso em p = %d\0A\00"
@str = [145 x i8] c"\0AAlgebra A - 2015/2\0A\0ATrabalho Pratico - Parte 2 Exercicio 1\0A\0AAutor: Ronald Davi Rodrigues Pereira - 2015004437\0A\0ACalculo do inverso de um numero\0A\00"
@str.8 = [22 x i8] c"P eh um divisor de A.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([145 x i8], [145 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %1
%11 = load i32, i32* %2
%12 = srem i32 %10, %11
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %0
%15 = icmp sgt i32 %11, 0
br i1 %15, label %18, label %32
16: ; preds = %0
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0))
br label %40
18: ; preds = %14, %29
%19 = phi i32 [ %30, %29 ], [ 0, %14 ]
%20 = mul nsw i32 %19, %10
%21 = srem i32 %20, %11
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %10, i32 %11, i32 %19)
%25 = load i32, i32* %1
%26 = load i32, i32* %2
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str.6, i64 0, i64 0), i32 %25, i32 %26, i32 %19, i32 %25, i32 %19, i32 %26)
%28 = load i32, i32* %2
br label %32
29: ; preds = %18
%30 = add nuw nsw i32 %19, 1
%31 = icmp eq i32 %30, %11
br i1 %31, label %36, label %18
32: ; preds = %14, %23
%33 = phi i32 [ %28, %23 ], [ %11, %14 ]
%34 = phi i32 [ %19, %23 ], [ 0, %14 ]
%35 = icmp eq i32 %34, %33
br i1 %35, label %36, label %40
36: ; preds = %29, %32
%37 = phi i32 [ %33, %32 ], [ %11, %29 ]
%38 = load i32, i32* %1
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i32 %38, i32 %37)
br label %40
40: ; preds = %36, %32, %16
ret i32 0
}