#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 */
unsigned int Euclide(unsigned int, unsigned int);
unsigned int atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  unsigned n1;
  unsigned n2;
  unsigned inv_n1_mod_n2;
  if (argc != 3) {
    printf("Usage: %s nb_to_invert modulo\n", argv[0]);
    printf("       nb_to_invert and modulo must be relatively prime\n");
    return 1;
  }
  n1 = atoi(argv[1]);
  n2 = atoi(argv[2]);
  inv_n1_mod_n2 = Euclide(n1, n2);
  printf("Res: %-10u i.e. (1/%u) %% %u = %u\n", inv_n1_mod_n2, n1, n2,
         inv_n1_mod_n2);
  printf("     %-10s i.e. (%u*%u) %% %u = 1\n", "", n1, inv_n1_mod_n2, n2);
  if ((unsigned)((n1 * inv_n1_mod_n2) % n2) != 1)
    printf("\n*** CHECK ERROR %u instead of 1\n", (n1 * inv_n1_mod_n2) % n2);
  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   $0x3,-0x8(%rbp)
je     117f <main+0x4f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121f <main+0xef>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <Euclide@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xea2(%rip),%rdi
lea    0xebd(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
imul   -0x1c(%rbp),%eax
xor    %edx,%edx
divl   -0x18(%rbp)
cmp    $0x1,%edx
je     1218 <main+0xe8>
mov    -0x14(%rbp),%eax
imul   -0x1c(%rbp),%eax
xor    %edx,%edx
divl   -0x18(%rbp)
mov    %edx,%esi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11ce <main+0x8e>
mov    0x8(%rbx),%rdi
call   1050 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
call   1050 <atoi@plt>
mov    %eax,%ebx
mov    %r15d,%edi
mov    %eax,%esi
call   1060 <Euclide@plt>
mov    %eax,%ebp
lea    0xea6(%rip),%rdi
xor    %r14d,%r14d
mov    %eax,%esi
mov    %r15d,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
lea    0xec9(%rip),%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
imul   %r15d,%ebp
mov    %ebp,%eax
xor    %edx,%edx
div    %ebx
cmp    $0x1,%edx
je     11f1 <main+0xb1>
lea    0xea5(%rip),%rdi
xor    %r14d,%r14d
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f1 <main+0xb1>
mov    (%rbx),%rsi
lea    0xe28(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Usage: %s nb_to_invert modulo\0A\00"
@.str.1 = [57 x i8] c" nb_to_invert and modulo must be relatively prime\0A\00"
@.str.2 = [35 x i8] c"Res: %-10u i.e. (1/%u) %% %u = %u\0A\00"
@.str.3 = [35 x i8] c" %-10s i.e. (%u*%u) %% %u = 1\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [34 x i8] c"\0A*** CHECK ERROR %u instead of 1\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %52
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %7
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = call i32 @Euclide(i32 %26, i32 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %30, i32 %31, i32 %32)
%34 = load i32, i32* %6
%35 = load i32, i32* %8
%36 = load i32, i32* %7
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 %34, i32 %35, i32 %36)
%38 = load i32, i32* %6
%39 = load i32, i32* %8
%40 = mul i32 %38, %39
%41 = load i32, i32* %7
%42 = urem i32 %40, %41
%43 = icmp ne i32 %42, 1
br i1 %43, label %44, label %51
44: ; preds = %17
%45 = load i32, i32* %6
%46 = load i32, i32* %8
%47 = mul i32 %45, %46
%48 = load i32, i32* %7
%49 = urem i32 %47, %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %44, %17
store i32 0, i32* %3
br label %52
52: ; preds = %51, %11
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str = [31 x i8] c"Usage: %s nb_to_invert modulo\0A\00"
@.str.2 = [35 x i8] c"Res: %-10u i.e. (1/%u) %% %u = %u\0A\00"
@.str.3 = [35 x i8] c" %-10s i.e. (%u*%u) %% %u = 1\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [34 x i8] c"\0A*** CHECK ERROR %u instead of 1\0A\00"
@str = [56 x i8] c" nb_to_invert and modulo must be relatively prime\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
br label %23
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = tail call i32 @Euclide(i32 %11, i32 %14)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %15, i32 %11, i32 %14, i32 %15)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 %11, i32 %15, i32 %14)
%18 = mul i32 %15, %11
%19 = urem i32 %18, %14
%20 = icmp eq i32 %19, 1
br i1 %20, label %23, label %21
21: ; preds = %8
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %19)
br label %23
23: ; preds = %8, %21, %4
%24 = phi i32 [ 1, %4 ], [ 0, %21 ], [ 0, %8 ]
ret i32 %24
}