#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_rgb2yuv(int);
int /*<<< orphan*/ printf(char *, ...);
int prog_rgb2yuv(int);
int rand();
int RGB_2_YUV_AUTOTEST() {
  int i, j;
  printf("LAUNCHING THE (RGB_2_YUV) RESOURCE TEST...\n");
  for (j = 0; j < 10; j++) {
    int op1 = ((rand() % 256) << 16) | ((rand() % 256) << 8) | (rand() % 256);
    int res1 = instr_rgb2yuv(op1);
    int res2 = prog_rgb2yuv(op1);
    if (res1 != res2) {
      printf("- TEST OF THE (RGB_2_YUV) RESOURCE => FAILED !\n");
      printf("  + %d COMPUTATION BEFORE ERROR... !\n", j);
      printf("  + INPUT DATA         = (%d, %d, %d)\n", (op1 >> 16),
             ((op1 >> 8) & 0xFF), (op1 & 0xFF));
      printf("  + INSTRUCTION RESULT = (%d, %d, %d)\n", (res1 >> 16),
             ((res1 >> 8) & 0xFF), (res1 & 0xFF));
      printf("  + C CODE RESULT      = (%d, %d, %d)\n", (res2 >> 16),
             ((res2 >> 8) & 0xFF), (res2 & 0xFF));
      return 0;
    }
  }
  printf("- TEST OF THE (RGB_2_YUV) RESOURCE => OK\n");
  return 1;
}


x86 assembly (clang, -O0):
<RGB_2_YUV_AUTOTEST>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    1288 <RGB_2_YUV_AUTOTEST+0x148>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
shl    $0x10,%edx
mov    %edx,-0x20(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x100,%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    $0x100,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
or     %edx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <instr_rgb2yuv@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <prog_rgb2yuv@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1275 <RGB_2_YUV_AUTOTEST+0x135>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
sar    $0x10,%esi
mov    -0x10(%rbp),%edx
sar    $0x8,%edx
and    $0xff,%edx
mov    -0x10(%rbp),%ecx
and    $0xff,%ecx
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
sar    $0x10,%esi
mov    -0x14(%rbp),%edx
sar    $0x8,%edx
and    $0xff,%edx
mov    -0x14(%rbp),%ecx
and    $0xff,%ecx
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
sar    $0x10,%esi
mov    -0x18(%rbp),%edx
sar    $0x8,%edx
and    $0xff,%edx
mov    -0x18(%rbp),%ecx
and    $0xff,%ecx
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129d <RGB_2_YUV_AUTOTEST+0x15d>
jmp    127a <RGB_2_YUV_AUTOTEST+0x13a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115d <RGB_2_YUV_AUTOTEST+0x1d>
lea    0xe68(%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):
<RGB_2_YUV_AUTOTEST>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xf39(%rip),%rdi
call   1030 <puts@plt>
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebp
lea    0xff(%rbp),%eax
test   %ebp,%ebp
cmovns %ebp,%eax
and    $0xff00,%eax
sub    %eax,%ebp
shl    $0x10,%ebp
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebx
lea    0xff(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xffff00,%eax
sub    %eax,%ebx
shl    $0x8,%ebx
or     %ebp,%ebx
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebp
lea    0xff(%rbp),%eax
test   %ebp,%ebp
cmovns %ebp,%eax
and    $0xffffff00,%eax
sub    %eax,%ebp
or     %ebp,%ebx
mov    %ebx,%edi
call   1060 <instr_rgb2yuv@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1050 <prog_rgb2yuv@plt>
cmp    %eax,%r14d
jne    1202 <RGB_2_YUV_AUTOTEST+0xb2>
add    $0x1,%r15d
cmp    $0xa,%r15d
jne    1170 <RGB_2_YUV_AUTOTEST+0x20>
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
jmp    1282 <RGB_2_YUV_AUTOTEST+0x132>
mov    %r14d,%r13d
lea    0xee3(%rip),%rdi
mov    %eax,%r12d
call   1030 <puts@plt>
lea    0xde5(%rip),%rdi
xor    %r14d,%r14d
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
sar    $0x10,%eax
movzbl %bh,%edx
movzbl %bpl,%ecx
lea    0xdeb(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13d,%ecx
mov    %r13d,%eax
sar    $0x10,%eax
movzbl %ch,%edx
movzbl %cl,%ecx
lea    0xdf3(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12d,%ecx
mov    %r12d,%eax
sar    $0x10,%eax
movzbl %ch,%edx
movzbl %cl,%ecx
lea    0xdfb(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"LAUNCHING THE (RGB_2_YUV) RESOURCE TEST...\0A\00"
@.str.1 = [48 x i8] c"- TEST OF THE (RGB_2_YUV) RESOURCE => FAILED !\0A\00"
@.str.2 = [38 x i8] c" + %d COMPUTATION BEFORE ERROR... !\0A\00"
@.str.3 = [39 x i8] c" + INPUT DATA = (%d, %d, %d)\0A\00"
@.str.4 = [39 x i8] c" + INSTRUCTION RESULT = (%d, %d, %d)\0A\00"
@.str.5 = [39 x i8] c" + C CODE RESULT = (%d, %d, %d)\0A\00"
@.str.6 = [42 x i8] c"- TEST OF THE (RGB_2_YUV) RESOURCE => OK\0A\00"
define i32 @RGB_2_YUV_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 ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %8
8: ; preds = %58, %0
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 10
br i1 %10, label %11, label %61
11: ; preds = %8
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 256
%14 = shl i32 %13, 16
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 256
%17 = shl i32 %16, 8
%18 = or i32 %14, %17
%19 = call i32 (...) @rand()
%20 = srem i32 %19, 256
%21 = or i32 %18, %20
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = call i32 @instr_rgb2yuv(i32 %22)
store i32 %23, i32* %5
%24 = load i32, i32* %4
%25 = call i32 @prog_rgb2yuv(i32 %24)
store i32 %25, i32* %6
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %57
29: ; preds = %11
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* %3
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %4
%34 = ashr i32 %33, 16
%35 = load i32, i32* %4
%36 = ashr i32 %35, 8
%37 = and i32 %36, 255
%38 = load i32, i32* %4
%39 = and i32 %38, 255
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %37, i32 %39)
%41 = load i32, i32* %5
%42 = ashr i32 %41, 16
%43 = load i32, i32* %5
%44 = ashr i32 %43, 8
%45 = and i32 %44, 255
%46 = load i32, i32* %5
%47 = and i32 %46, 255
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %42, i32 %45, i32 %47)
%49 = load i32, i32* %6
%50 = ashr i32 %49, 16
%51 = load i32, i32* %6
%52 = ashr i32 %51, 8
%53 = and i32 %52, 255
%54 = load i32, i32* %6
%55 = and i32 %54, 255
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 %50, i32 %53, i32 %55)
store i32 0, i32* %1
br label %63
57: ; preds = %11
br label %58
58: ; preds = %57
%59 = load i32, i32* %3
%60 = add nsw i32 %59, 1
store i32 %60, i32* %3
br label %8
61: ; preds = %8
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %63
63: ; preds = %61, %29
%64 = load i32, i32* %1
ret i32 %64
}

LLVM IR (-O2):
@.str.2 = [38 x i8] c" + %d COMPUTATION BEFORE ERROR... !\0A\00"
@.str.3 = [39 x i8] c" + INPUT DATA = (%d, %d, %d)\0A\00"
@.str.4 = [39 x i8] c" + INSTRUCTION RESULT = (%d, %d, %d)\0A\00"
@.str.5 = [39 x i8] c" + C CODE RESULT = (%d, %d, %d)\0A\00"
@str = [43 x i8] c"LAUNCHING THE (RGB_2_YUV) RESOURCE TEST...\00"
@str.7 = [41 x i8] c"- TEST OF THE (RGB_2_YUV) RESOURCE => OK\00"
@str.8 = [47 x i8] c"- TEST OF THE (RGB_2_YUV) RESOURCE => FAILED !\00"
define i32 @RGB_2_YUV_AUTOTEST() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %0, %35
%3 = phi i32 [ 0, %0 ], [ %36, %35 ]
%4 = tail call i32 (...) @rand()
%5 = srem i32 %4, 256
%6 = shl nsw i32 %5, 16
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 256
%9 = shl nsw i32 %8, 8
%10 = or i32 %9, %6
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 256
%13 = or i32 %10, %12
%14 = tail call i32 @instr_rgb2yuv(i32 %13)
%15 = tail call i32 @prog_rgb2yuv(i32 %13)
%16 = icmp eq i32 %14, %15
br i1 %16, label %35, label %17
17: ; preds = %2
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.8, i64 0, i64 0))
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%20 = ashr i32 %13, 16
%21 = lshr i32 %13, 8
%22 = and i32 %21, 255
%23 = and i32 %12, 255
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 %22, i32 %23)
%25 = ashr i32 %14, 16
%26 = lshr i32 %14, 8
%27 = and i32 %26, 255
%28 = and i32 %14, 255
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %25, i32 %27, i32 %28)
%30 = ashr i32 %15, 16
%31 = lshr i32 %15, 8
%32 = and i32 %31, 255
%33 = and i32 %15, 255
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 %30, i32 %32, i32 %33)
br label %40
35: ; preds = %2
%36 = add nuw nsw i32 %3, 1
%37 = icmp eq i32 %36, 10
br i1 %37, label %38, label %2
38: ; preds = %35
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.7, i64 0, i64 0))
br label %40
40: ; preds = %17, %38
%41 = phi i32 [ 0, %17 ], [ 1, %38 ]
ret i32 %41
}