#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 instr_mod(int, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int MODULUS_32b_AUTOTEST() {
  printf("LAUNCHING THE (MODULUS) RESOURCE TEST...\n");
  int i, j;
  for (j = 0; j < 10; j++) {
    int op1 = rand() % 65536;
    int op2 = rand() % 65536;
    int res1 = instr_mod(op1, op2);
    int res3 = instr_mod(op1, op2);
    if (res1 != res3) {
      printf("- TEST OF THE (MODULUS) RESOURCE => FAILED !\n");
      printf("  + %d COMPUTATION BEFORE ERROR... !\n", j);
      printf("  + INSTRUCTION RESULT (%d l %d) => %d\n", op1, op2, res1);
      printf("  + C CODE RESULT      (%d l %d) => %d\n", op2, op1, res3);
      return 0;
    }
  }
  printf("- TEST OF THE (MODULUS) RESOURCE => OK\n");
  return 1;
}


x86 assembly (clang, -O0):
<MODULUS_32b_AUTOTEST>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    120f <MODULUS_32b_AUTOTEST+0xdf>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x10000,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x10000,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <instr_mod@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <instr_mod@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11fc <MODULUS_32b_AUTOTEST+0xcc>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1224 <MODULUS_32b_AUTOTEST+0xf4>
jmp    1201 <MODULUS_32b_AUTOTEST+0xd1>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114d <MODULUS_32b_AUTOTEST+0x1d>
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MODULUS_32b_AUTOTEST>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xf24(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ebx
lea    0xffff(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xffff0000,%eax
sub    %eax,%ebx
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ebp
lea    0xffff(%rbp),%eax
test   %ebp,%ebp
cmovns %ebp,%eax
and    $0xffff0000,%eax
sub    %eax,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <instr_mod@plt>
mov    %eax,%r12d
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <instr_mod@plt>
cmp    %eax,%r12d
jne    11ce <MODULUS_32b_AUTOTEST+0x8e>
add    $0x1,%r14d
cmp    $0xa,%r14d
jne    1160 <MODULUS_32b_AUTOTEST+0x20>
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r13d
jmp    121b <MODULUS_32b_AUTOTEST+0xdb>
mov    %eax,%r15d
lea    0xeee(%rip),%rdi
call   1030 <puts@plt>
lea    0xe1c(%rip),%rdi
xor    %r13d,%r13d
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe2e(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe41(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"LAUNCHING THE (MODULUS) RESOURCE TEST...\0A\00"
@.str.1 = [46 x i8] c"- TEST OF THE (MODULUS) RESOURCE => FAILED !\0A\00"
@.str.2 = [38 x i8] c" + %d COMPUTATION BEFORE ERROR... !\0A\00"
@.str.3 = [40 x i8] c" + INSTRUCTION RESULT (%d l %d) => %d\0A\00"
@.str.4 = [40 x i8] c" + C CODE RESULT (%d l %d) => %d\0A\00"
@.str.5 = [40 x i8] c"- TEST OF THE (MODULUS) RESOURCE => OK\0A\00"
define i32 @MODULUS_32b_AUTOTEST() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %9
9: ; preds = %39, %0
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %42
12: ; preds = %9
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 65536
store i32 %14, i32* %4
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 65536
store i32 %16, i32* %5
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = call i32 @instr_mod(i32 %17, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = call i32 @instr_mod(i32 %20, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %38
26: ; preds = %12
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %31, i32 %32)
%34 = load i32, i32* %5
%35 = load i32, i32* %4
%36 = load i32, i32* %7
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 %34, i32 %35, i32 %36)
store i32 0, i32* %1
br label %44
38: ; preds = %12
br label %39
39: ; preds = %38
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %9
42: ; preds = %9
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %44
44: ; preds = %42, %26
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str.2 = [38 x i8] c" + %d COMPUTATION BEFORE ERROR... !\0A\00"
@.str.3 = [40 x i8] c" + INSTRUCTION RESULT (%d l %d) => %d\0A\00"
@.str.4 = [40 x i8] c" + C CODE RESULT (%d l %d) => %d\0A\00"
@str = [41 x i8] c"LAUNCHING THE (MODULUS) RESOURCE TEST...\00"
@str.6 = [39 x i8] c"- TEST OF THE (MODULUS) RESOURCE => OK\00"
@str.7 = [45 x i8] c"- TEST OF THE (MODULUS) RESOURCE => FAILED !\00"
define i32 @MODULUS_32b_AUTOTEST() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %0, %16
%3 = phi i32 [ 0, %0 ], [ %17, %16 ]
%4 = tail call i32 (...) @rand()
%5 = srem i32 %4, 65536
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 65536
%8 = tail call i32 @instr_mod(i32 %5, i32 %7)
%9 = tail call i32 @instr_mod(i32 %5, i32 %7)
%10 = icmp eq i32 %8, %9
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.7, i64 0, i64 0))
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %5, i32 %7, i32 %8)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 %7, i32 %5, i32 %9)
br label %21
16: ; preds = %2
%17 = add nuw nsw i32 %3, 1
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %2
19: ; preds = %16
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.6, i64 0, i64 0))
br label %21
21: ; preds = %11, %19
%22 = phi i32 [ 0, %11 ], [ 1, %19 ]
ret i32 %22
}