#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 */
typedef scalar_t__ const int16_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, scalar_t__ const, ...);
int validate_s16(int16_t *act, const int16_t *ref, int size) {
  int test_passed = true;
  int count = 0;
  int total = 0;
  for (int i = 0; i < size; ++i) {
    total++;
    if (act[i] != ref[i]) {
      count++;
      printf("ERROR at pos %d: Act: %d Ref: %d\r\n", i, act[i], ref[i]);
      test_passed = false;
    } else {
    }
  }
  if (!test_passed) {
    printf("%d of %d failed\r\n", count, total);
  }
  return test_passed;
}


x86 assembly (clang, -O0):
<validate_s16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c8 <validate_s16+0xb8>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x10(%rbp),%rcx
movslq -0x24(%rbp),%rdx
cmp    (%rcx,%rdx,8),%rax
je     11b0 <validate_s16+0xa0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
jmp    11b5 <validate_s16+0xa5>
jmp    11b5 <validate_s16+0xa5>
jmp    11ba <validate_s16+0xaa>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113f <validate_s16+0x2f>
cmpl   $0x0,-0x18(%rbp)
jne    11e7 <validate_s16+0xd7>
mov    -0x1c(%rbp),%esi
movslq -0x20(%rbp),%rdx
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_s16>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    11c3 <validate_s16+0xb3>
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %edx,%r14d
mov    %r14,(%rsp)
neg    %r14
mov    $0x1,%r15d
xor    %r13d,%r13d
xor    %r12d,%r12d
xor    %eax,%eax
add    $0x1,%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    -0x8(%rbp,%r13,8),%rdx
mov    -0x8(%rbx,%r13,8),%rcx
cmp    %rcx,%rdx
jne    1180 <validate_s16+0x70>
lea    (%r14,%r13,1),%rcx
add    $0x1,%rcx
add    $0x1,%r13
cmp    $0x1,%rcx
jne    1150 <validate_s16+0x40>
jmp    11a5 <validate_s16+0x95>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r12d
lea    -0x1(%r13),%esi
xor    %r15d,%r15d
lea    0xe6e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%al
mov    %r14,%rcx
add    %r13,%rcx
jne    1141 <validate_s16+0x31>
jmp    11a9 <validate_s16+0x99>
test   $0x1,%al
je     11c9 <validate_s16+0xb9>
lea    0xe73(%rip),%rdi
xor    %r15d,%r15d
mov    %r12d,%esi
mov    (%rsp),%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11c9 <validate_s16+0xb9>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"ERROR at pos %d: Act: %d Ref: %d\0D\0A\00"
@.str.1 = [18 x i8] c"%d of %d failed\0D\0A\00"
define i32 @validate_s16(i64* %0, i64* %1, i32 %2) {
%4 = alloca i64*
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i64* %0, i64** %4
store i64* %1, i64** %5
store i32 %2, i32* %6
store i32 1, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %11
11: ; preds = %46, %3
%12 = load i32, i32* %10
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %49
15: ; preds = %11
%16 = load i32, i32* %9
%17 = add nsw i32 %16, 1
store i32 %17, i32* %9
%18 = load i64*, i64** %4
%19 = load i32, i32* %10
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i64, i64* %18, i64 %20
%22 = load i64, i64* %21
%23 = load i64*, i64** %5
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i64, i64* %23, i64 %25
%27 = load i64, i64* %26
%28 = icmp ne i64 %22, %27
br i1 %28, label %29, label %44
29: ; preds = %15
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
%32 = load i32, i32* %10
%33 = load i64*, i64** %4
%34 = load i32, i32* %10
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i64, i64* %33, i64 %35
%37 = load i64, i64* %36
%38 = load i64*, i64** %5
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i64, i64* %38, i64 %40
%42 = load i64, i64* %41
%43 = call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %32, i64 %37, i64 %42)
store i32 0, i32* %7
br label %45
44: ; preds = %15
br label %45
45: ; preds = %44, %29
br label %46
46: ; preds = %45
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
br label %11
49: ; preds = %11
%50 = load i32, i32* %7
%51 = icmp ne i32 %50, 0
br i1 %51, label %57, label %52
52: ; preds = %49
%53 = load i32, i32* %8
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %53, i64 %55)
br label %57
57: ; preds = %52, %49
%58 = load i32, i32* %7
ret i32 %58
}

LLVM IR (-O2):
@.str = [35 x i8] c"ERROR at pos %d: Act: %d Ref: %d\0D\0A\00"
@.str.1 = [18 x i8] c"%d of %d failed\0D\0A\00"
define i32 @validate_s16(i64* nocapture %0, i64* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %32
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %23, %5
%8 = phi i64 [ %15, %23 ], [ 0, %5 ]
%9 = phi i32 [ %24, %23 ], [ 0, %5 ]
%10 = phi i1 [ true, %23 ], [ false, %5 ]
%11 = phi i32 [ 0, %23 ], [ 1, %5 ]
br label %13
12: ; preds = %21
br i1 %10, label %28, label %32
13: ; preds = %7, %21
%14 = phi i64 [ %15, %21 ], [ %8, %7 ]
%15 = add nuw nsw i64 %14, 1
%16 = getelementptr inbounds i64, i64* %0, i64 %14
%17 = load i64, i64* %16
%18 = getelementptr inbounds i64, i64* %1, i64 %14
%19 = load i64, i64* %18
%20 = icmp eq i64 %17, %19
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = icmp eq i64 %15, %6
br i1 %22, label %12, label %13
23: ; preds = %13
%24 = add nuw nsw i32 %9, 1
%25 = trunc i64 %14 to i32
%26 = tail call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %25, i64 %17, i64 %19)
%27 = icmp eq i64 %15, %6
br i1 %27, label %28, label %7
28: ; preds = %23, %12
%29 = phi i32 [ %9, %12 ], [ %24, %23 ]
%30 = zext i32 %2 to i64
%31 = tail call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %29, i64 %30)
br label %32
32: ; preds = %3, %28, %12
%33 = phi i32 [ 0, %28 ], [ %11, %12 ], [ 1, %3 ]
ret i32 %33
}