#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 /*<<< orphan*/ printf(char *, ...);
void clQueue_validate(unsigned int *queue, unsigned int head,
                      unsigned int tail) {
  unsigned int start = queue[1];
  unsigned int index, count;
  printf("\nValidating:\n");
  printf("Head: %08x\n", head);
  printf("Tail: %08x\n", tail);
  printf("Start: %08x\n\n", start);
  index = (head - start) >> 2;
  for (count = 0; count <= (8 * 8 * 8); count++) {
    if (queue[index] == 0) {
      if (queue[index + 1] == tail) {
        printf("Queue valid.\n");
      } else {
        printf("Queue invalid: Tail != last item\n");
        printf("Tail: %08x\n", tail);
        printf("Item: %08x\n", queue[index + 1]);
      }
      printf("Items: %u\n\n", count + 1);
      return;
    }
    index = (queue[index] - start) >> 2;
  }
  printf("Queue invalid: circular dependency\n\n");
}


x86 assembly (clang, -O0):
<clQueue_validate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x14(%rbp)
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
sub    -0x14(%rbp),%eax
shr    $0x2,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x200,-0x1c(%rbp)
ja     123f <clQueue_validate+0x12f>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
cmpl   $0x0,(%rax,%rcx,4)
jne    121e <clQueue_validate+0x10e>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,4),%eax
cmp    -0x10(%rbp),%eax
jne    11c9 <clQueue_validate+0xb9>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1205 <clQueue_validate+0xf5>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,4),%esi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <clQueue_validate+0x13d>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
sub    -0x14(%rbp),%eax
shr    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1180 <clQueue_validate+0x70>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clQueue_validate>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x4(%rdi),%r12d
lea    0xf03(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb9(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb3(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
sub    %r12d,%ebp
shr    $0x2,%ebp
mov    (%r14,%rbp,4),%ecx
test   %ecx,%ecx
je     11c9 <clQueue_validate+0xa9>
sub    %r12d,%ecx
shr    $0x2,%ecx
mov    (%r14,%rcx,4),%eax
test   %eax,%eax
je     11cd <clQueue_validate+0xad>
sub    %r12d,%eax
shr    $0x2,%eax
mov    (%r14,%rax,4),%ebp
test   %ebp,%ebp
je     11d4 <clQueue_validate+0xb4>
add    $0x3,%ebx
cmp    $0x201,%ebx
jne    1180 <clQueue_validate+0x60>
lea    0xe8f(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
mov    %ebp,%eax
jmp    11d7 <clQueue_validate+0xb7>
add    $0x1,%ebx
mov    %ecx,%eax
jmp    11d7 <clQueue_validate+0xb7>
add    $0x2,%ebx
mov    %eax,%ebp
cmp    %r15d,0x4(%r14,%rbp,4)
jne    11ee <clQueue_validate+0xce>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
jmp    1221 <clQueue_validate+0x101>
add    $0x1,%rbp
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
lea    0xe07(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14,%rbp,4),%esi
lea    0xe0c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
lea    0xe07(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"\0AValidating:\0A\00"
@.str.1 = [12 x i8] c"Head: %08x\0A\00"
@.str.2 = [12 x i8] c"Tail: %08x\0A\00"
@.str.3 = [14 x i8] c"Start: %08x\0A\0A\00"
@.str.4 = [14 x i8] c"Queue valid.\0A\00"
@.str.5 = [34 x i8] c"Queue invalid: Tail != last item\0A\00"
@.str.6 = [12 x i8] c"Item: %08x\0A\00"
@.str.7 = [12 x i8] c"Items: %u\0A\0A\00"
@.str.8 = [37 x i8] c"Queue invalid: circular dependency\0A\0A\00"
define void @clQueue_validate(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32*, i32** %4
%11 = getelementptr inbounds i32, i32* %10, i64 1
%12 = load i32, i32* %11
store i32 %12, i32* %7
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %6
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %7
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %5
%21 = load i32, i32* %7
%22 = sub i32 %20, %21
%23 = lshr i32 %22, 2
store i32 %23, i32* %8
store i32 0, i32* %9
br label %24
24: ; preds = %69, %3
%25 = load i32, i32* %9
%26 = icmp ule i32 %25, 512
br i1 %26, label %27, label %72
27: ; preds = %24
%28 = load i32*, i32** %4
%29 = load i32, i32* %8
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %60
34: ; preds = %27
%35 = load i32*, i32** %4
%36 = load i32, i32* %8
%37 = add i32 %36, 1
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %35, i64 %38
%40 = load i32, i32* %39
%41 = load i32, i32* %6
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %34
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %56
45: ; preds = %34
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
%47 = load i32, i32* %6
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %47)
%49 = load i32*, i32** %4
%50 = load i32, i32* %8
%51 = add i32 %50, 1
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %49, i64 %52
%54 = load i32, i32* %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %45, %43
%57 = load i32, i32* %9
%58 = add i32 %57, 1
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %58)
br label %74
60: ; preds = %27
%61 = load i32*, i32** %4
%62 = load i32, i32* %8
%63 = zext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
%65 = load i32, i32* %64
%66 = load i32, i32* %7
%67 = sub i32 %65, %66
%68 = lshr i32 %67, 2
store i32 %68, i32* %8
br label %69
69: ; preds = %60
%70 = load i32, i32* %9
%71 = add i32 %70, 1
store i32 %71, i32* %9
br label %24
72: ; preds = %24
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
br label %74
74: ; preds = %72, %56
ret void
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"Head: %08x\0A\00"
@.str.2 = [12 x i8] c"Tail: %08x\0A\00"
@.str.3 = [14 x i8] c"Start: %08x\0A\0A\00"
@.str.6 = [12 x i8] c"Item: %08x\0A\00"
@.str.7 = [12 x i8] c"Items: %u\0A\0A\00"
@str = [13 x i8] c"\0AValidating:\00"
@str.9 = [36 x i8] c"Queue invalid: circular dependency\0A\00"
@str.10 = [33 x i8] c"Queue invalid: Tail != last item\00"
@str.11 = [13 x i8] c"Queue valid.\00"
define void @clQueue_validate(i32* nocapture %0, i32 %1, i32 %2) {
%4 = getelementptr inbounds i32, i32* %0, i64 1
%5 = load i32, i32* %4
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %2)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %5)
br label %10
10: ; preds = %55, %3
%11 = phi i32 [ %1, %3 ], [ %53, %55 ]
%12 = phi i32 [ 0, %3 ], [ %56, %55 ]
%13 = sub i32 %11, %5
%14 = lshr i32 %13, 2
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %23, label %41
19: ; preds = %48
%20 = add nuw nsw i32 %12, 2
br label %23
21: ; preds = %41
%22 = add nuw nsw i32 %12, 1
br label %23
23: ; preds = %10, %21, %19
%24 = phi i32 [ %20, %19 ], [ %22, %21 ], [ %12, %10 ]
%25 = phi i32 [ %50, %19 ], [ %43, %21 ], [ %14, %10 ]
%26 = add nuw nsw i32 %25, 1
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %0, i64 %27
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, %2
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.11, i64 0, i64 0))
br label %38
33: ; preds = %23
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.10, i64 0, i64 0))
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %2)
%36 = load i32, i32* %28
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %33, %31
%39 = add nuw nsw i32 %24, 1
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %39)
br label %60
41: ; preds = %10
%42 = sub i32 %17, %5
%43 = lshr i32 %42, 2
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %0, i64 %44
%46 = load i32, i32* %45
%47 = icmp eq i32 %46, 0
br i1 %47, label %21, label %48
48: ; preds = %41
%49 = sub i32 %46, %5
%50 = lshr i32 %49, 2
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %0, i64 %51
%53 = load i32, i32* %52
%54 = icmp eq i32 %53, 0
br i1 %54, label %19, label %55
55: ; preds = %48
%56 = add nuw nsw i32 %12, 3
%57 = icmp eq i32 %56, 513
br i1 %57, label %58, label %10
58: ; preds = %55
%59 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.9, i64 0, i64 0))
br label %60
60: ; preds = %58, %38
ret void
}