#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_rbyte(int);
int /*<<< orphan*/ printf(char *, ...);
int prog_rbyte(int);
int rand();
int REVERSE_BYTE_32b_AUTOTEST() {
  printf("LAUNCHING THE (REVERSE_BYTE) RESOURCE TEST...\n");
  int i, j;
  for (j = 0; j < 10; j++) {
    int op1 = (rand() % 255) << 24 | (rand() % 255) << 16 |
              (rand() % 255) << 8 | (rand() % 255);
    int res1 = instr_rbyte(op1);
    int res2 = prog_rbyte(op1);
    if (res1 != res2) {
      printf("- TEST OF THE REVERSE_BYTE RESOURCE => FAILED !\n");
      printf("  + OPERANDE 1         [%8x]\n", op1);
      printf("  + INSTRUCTION RESULT (%8x)\n", res1);
      printf("  + C CODE RESULT      (%8x)\n", res2);
      return 0;
    }
  }
  printf("- TEST OF THE REVERSE_BYTE RESOURCE => OK\n");
  return 1;
}


x86 assembly (clang, -O0):
<REVERSE_BYTE_32b_AUTOTEST>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    1249 <REVERSE_BYTE_32b_AUTOTEST+0x109>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
shl    $0x18,%edx
mov    %edx,-0x24(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    -0x24(%rbp),%eax
shl    $0x10,%edx
or     %edx,%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%eax
shl    $0x8,%edx
or     %edx,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
or     %edx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <instr_rbyte@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <prog_rbyte@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1236 <REVERSE_BYTE_32b_AUTOTEST+0xf6>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    125e <REVERSE_BYTE_32b_AUTOTEST+0x11e>
jmp    123b <REVERSE_BYTE_32b_AUTOTEST+0xfb>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115d <REVERSE_BYTE_32b_AUTOTEST+0x1d>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<REVERSE_BYTE_32b_AUTOTEST>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xefc(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%r15d
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rbx
shr    $0x20,%rbx
add    %eax,%ebx
mov    %ebx,%ecx
shr    $0x1f,%ecx
shr    $0x7,%ebx
add    %ecx,%ebx
add    %eax,%ebx
shl    $0x18,%ebx
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%r14
shr    $0x20,%r14
add    %eax,%r14d
mov    %r14d,%ecx
shr    $0x1f,%ecx
sar    $0x7,%r14d
add    %ecx,%r14d
mov    %r14d,%ecx
shl    $0x8,%ecx
sub    %ecx,%r14d
add    %eax,%r14d
shl    $0x10,%r14d
or     %ebx,%r14d
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rbp
shr    $0x20,%rbp
add    %eax,%ebp
mov    %ebp,%ecx
shr    $0x1f,%ecx
sar    $0x7,%ebp
add    %ecx,%ebp
mov    %ebp,%ecx
shl    $0x8,%ecx
sub    %ecx,%ebp
add    %eax,%ebp
shl    $0x8,%ebp
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rbx
shr    $0x20,%rbx
add    %eax,%ebx
mov    %ebx,%ecx
shr    $0x1f,%ecx
sar    $0x7,%ebx
add    %ecx,%ebx
mov    %ebx,%ecx
shl    $0x8,%ecx
sub    %ecx,%ebx
add    %eax,%ebx
or     %ebp,%ebx
or     %r14d,%ebx
mov    %ebx,%edi
call   1030 <instr_rbyte@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1060 <prog_rbyte@plt>
cmp    %eax,%ebp
jne    1258 <REVERSE_BYTE_32b_AUTOTEST+0x108>
add    $0xffffffff,%r15d
jne    1170 <REVERSE_BYTE_32b_AUTOTEST+0x20>
lea    0xe3d(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
jmp    129b <REVERSE_BYTE_32b_AUTOTEST+0x14b>
mov    %eax,%r14d
lea    0xe50(%rip),%rdi
call   1040 <puts@plt>
lea    0xd92(%rip),%rdi
xor    %r15d,%r15d
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd9d(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdab(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.2 = [30 x i8] c" + OPERANDE 1 [%8x]\0A\00"
@.str.3 = [30 x i8] c" + INSTRUCTION RESULT (%8x)\0A\00"
@.str.4 = [30 x i8] c" + C CODE RESULT (%8x)\0A\00"
@str = [46 x i8] c"LAUNCHING THE (REVERSE_BYTE) RESOURCE TEST...\00"
@str.6 = [42 x i8] c"- TEST OF THE REVERSE_BYTE RESOURCE => OK\00"
@str.7 = [48 x i8] c"- TEST OF THE REVERSE_BYTE RESOURCE => FAILED !\00"
define i32 @REVERSE_BYTE_32b_AUTOTEST() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %5
2: ; preds = %5
%3 = add nuw nsw i32 %6, 1
%4 = icmp eq i32 %3, 10
br i1 %4, label %29, label %5
5: ; preds = %0, %2
%6 = phi i32 [ 0, %0 ], [ %3, %2 ]
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 255
%9 = shl i32 %8, 24
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, 255
%12 = shl nsw i32 %11, 16
%13 = or i32 %12, %9
%14 = tail call i32 (...) @rand()
%15 = srem i32 %14, 255
%16 = shl nsw i32 %15, 8
%17 = or i32 %13, %16
%18 = tail call i32 (...) @rand()
%19 = srem i32 %18, 255
%20 = or i32 %17, %19
%21 = tail call i32 @instr_rbyte(i32 %20)
%22 = tail call i32 @prog_rbyte(i32 %20)
%23 = icmp eq i32 %21, %22
br i1 %23, label %2, label %24
24: ; preds = %5
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.7, i64 0, i64 0))
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %22)
br label %31
29: ; preds = %2
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.6, i64 0, i64 0))
br label %31
31: ; preds = %24, %29
%32 = phi i32 [ 0, %24 ], [ 1, %29 ]
ret i32 %32
}