#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 rand();
int random_number(int);
int random_block() {
  static int queue[4] = {-1, -1, -1, -1};
  int current;
  int i, j;
  if (queue[0] == -1) {
    queue[0] = random_number(7);
    queue[1] = random_number(7);
    queue[2] = random_number(7);
    queue[3] = random_number(7);
  }
  current = queue[0];
  for (i = 0; i < 4; ++i) {
    queue[i] = queue[i + 1];
  }
  queue[3] = rand() % 7;
  for (j = 0; j < 4; ++j) {
    for (i = 0; i < 3; ++i) {
      if (queue[i] == queue[3]) {
        queue[3] = rand() % 7;
        break;
      }
    }
  }
  return current;
}


x86 assembly (clang, -O0):
<random_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpl   $0xffffffff,0x2f11(%rip)
jne    1175 <random_block+0x55>
mov    $0x7,%edi
call   1030 <random_number@plt>
mov    %eax,0x2efb(%rip)
mov    $0x7,%edi
call   1030 <random_number@plt>
mov    %eax,0x2eef(%rip)
mov    $0x7,%edi
call   1030 <random_number@plt>
mov    %eax,0x2ee3(%rip)
mov    $0x7,%edi
call   1030 <random_number@plt>
mov    %eax,0x2ed7(%rip)
mov    0x2ec5(%rip),%eax
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11be <random_block+0x9e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
lea    0x2ea1(%rip),%rax
mov    (%rax,%rcx,4),%edx
movslq -0x8(%rbp),%rcx
lea    0x2e93(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1185 <random_block+0x65>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,0x2e79(%rip)
movl   $0x0,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jge    124f <random_block+0x12f>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    123c <random_block+0x11c>
movslq -0x8(%rbp),%rcx
lea    0x2e40(%rip),%rax
mov    (%rax,%rcx,4),%eax
cmp    0x2e43(%rip),%eax
jne    1229 <random_block+0x109>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,0x2e28(%rip)
jmp    123c <random_block+0x11c>
jmp    122e <random_block+0x10e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11eb <random_block+0xcb>
jmp    1241 <random_block+0x121>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11da <random_block+0xba>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_block>:
push   %rbx
mov    0x2f19(%rip),%ebx
cmp    $0xffffffff,%ebx
jne    1172 <random_block+0x52>
mov    $0x7,%edi
call   1030 <random_number@plt>
mov    %eax,0x2f04(%rip)
mov    $0x7,%edi
call   1030 <random_number@plt>
mov    %eax,0x2ef8(%rip)
mov    $0x7,%edi
call   1030 <random_number@plt>
mov    %eax,0x2eec(%rip)
mov    $0x7,%edi
call   1030 <random_number@plt>
mov    %eax,0x2ee0(%rip)
mov    0x2ece(%rip),%ebx
movups 0x2ecb(%rip),%xmm0
movaps %xmm0,0x2ec0(%rip)
xor    %eax,%eax
call   1040 <rand@plt>
movslq %eax,%rcx
imul   $0xffffffff92492493,%rcx,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%edx
shr    $0x1f,%edx
sar    $0x2,%eax
add    %edx,%eax
lea    0x0(,%rax,8),%edx
sub    %edx,%eax
add    %ecx,%eax
mov    %eax,0x2e9a(%rip)
mov    0x2e88(%rip),%ecx
cmp    %eax,%ecx
je     11cc <random_block+0xac>
cmp    %eax,0x2e82(%rip)
je     11cc <random_block+0xac>
cmp    %eax,0x2e7e(%rip)
jne    1204 <random_block+0xe4>
xor    %eax,%eax
call   1040 <rand@plt>
movslq %eax,%rcx
imul   $0xffffffff92492493,%rcx,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%edx
shr    $0x1f,%edx
sar    $0x2,%eax
add    %edx,%eax
lea    0x0(,%rax,8),%edx
sub    %edx,%eax
add    %ecx,%eax
mov    %eax,0x2e4e(%rip)
mov    0x2e3c(%rip),%ecx
cmp    %eax,%ecx
je     1218 <random_block+0xf8>
cmp    %eax,0x2e36(%rip)
je     1218 <random_block+0xf8>
cmp    %eax,0x2e32(%rip)
jne    1250 <random_block+0x130>
xor    %eax,%eax
call   1040 <rand@plt>
movslq %eax,%rcx
imul   $0xffffffff92492493,%rcx,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%edx
shr    $0x1f,%edx
sar    $0x2,%eax
add    %edx,%eax
lea    0x0(,%rax,8),%edx
sub    %edx,%eax
add    %ecx,%eax
mov    %eax,0x2e02(%rip)
mov    0x2df0(%rip),%ecx
cmp    %eax,%ecx
je     1264 <random_block+0x144>
cmp    %eax,0x2dea(%rip)
je     1264 <random_block+0x144>
cmp    %eax,0x2de6(%rip)
jne    129c <random_block+0x17c>
xor    %eax,%eax
call   1040 <rand@plt>
movslq %eax,%rcx
imul   $0xffffffff92492493,%rcx,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%edx
shr    $0x1f,%edx
sar    $0x2,%eax
add    %edx,%eax
lea    0x0(,%rax,8),%edx
sub    %edx,%eax
add    %ecx,%eax
mov    %eax,0x2db6(%rip)
mov    0x2da4(%rip),%ecx
cmp    %eax,%ecx
je     12b0 <random_block+0x190>
cmp    %eax,0x2d9e(%rip)
je     12b0 <random_block+0x190>
cmp    %eax,0x2d9a(%rip)
jne    12e1 <random_block+0x1c1>
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0xffffffff92492493,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x2,%ecx
add    %edx,%ecx
lea    0x0(,%rcx,8),%edx
sub    %edx,%ecx
add    %eax,%ecx
mov    %ecx,0x2d6b(%rip)
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@random_block.queue = internal global [4 x i32] [i32 -1, i32 -1, i32 -1, i32 -1]
define i32 @random_block() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = call i32 @random_number(i32 7)
store i32 %7, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 0)
%8 = call i32 @random_number(i32 7)
store i32 %8, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 1)
%9 = call i32 @random_number(i32 7)
store i32 %9, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 2)
%10 = call i32 @random_number(i32 7)
store i32 %10, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 3)
br label %11
11: ; preds = %6, %0
%12 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 0)
store i32 %12, i32* %1
store i32 0, i32* %2
br label %13
13: ; preds = %25, %11
%14 = load i32, i32* %2
%15 = icmp slt i32 %14, 4
br i1 %15, label %16, label %28
16: ; preds = %13
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 %23
store i32 %21, i32* %24
br label %25
25: ; preds = %16
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %13
28: ; preds = %13
%29 = call i32 (...) @rand()
%30 = srem i32 %29, 7
store i32 %30, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 3)
store i32 0, i32* %3
br label %31
31: ; preds = %53, %28
%32 = load i32, i32* %3
%33 = icmp slt i32 %32, 4
br i1 %33, label %34, label %56
34: ; preds = %31
store i32 0, i32* %2
br label %35
35: ; preds = %49, %34
%36 = load i32, i32* %2
%37 = icmp slt i32 %36, 3
br i1 %37, label %38, label %52
38: ; preds = %35
%39 = load i32, i32* %2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 3)
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = call i32 (...) @rand()
%47 = srem i32 %46, 7
store i32 %47, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 3)
br label %52
48: ; preds = %38
br label %49
49: ; preds = %48
%50 = load i32, i32* %2
%51 = add nsw i32 %50, 1
store i32 %51, i32* %2
br label %35
52: ; preds = %45, %35
br label %53
53: ; preds = %52
%54 = load i32, i32* %3
%55 = add nsw i32 %54, 1
store i32 %55, i32* %3
br label %31
56: ; preds = %31
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@random_block.queue = internal unnamed_addr global [4 x i32] [i32 -1, i32 -1, i32 -1, i32 -1]
define i32 @random_block() {
%1 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 0)
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %9
3: ; preds = %0
%4 = tail call i32 @random_number(i32 7)
store i32 %4, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 0)
%5 = tail call i32 @random_number(i32 7)
store i32 %5, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 1)
%6 = tail call i32 @random_number(i32 7)
store i32 %6, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 2)
%7 = tail call i32 @random_number(i32 7)
store i32 %7, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 3)
%8 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 0)
br label %9
9: ; preds = %3, %0
%10 = phi i32 [ %8, %3 ], [ %1, %0 ]
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 7
store i32 %12, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 3)
%13 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 0)
%14 = icmp eq i32 %13, %12
%15 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 1)
%16 = icmp eq i32 %15, %12
%17 = select i1 %14, i1 true, i1 %16
%18 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 2)
%19 = icmp eq i32 %18, %12
%20 = select i1 %17, i1 true, i1 %19
br i1 %20, label %21, label %25
21: ; preds = %9
%22 = tail call i32 (...) @rand()
%23 = srem i32 %22, 7
store i32 %23, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 3)
%24 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 0)
br label %25
25: ; preds = %9, %21
%26 = phi i32 [ %24, %21 ], [ %13, %9 ]
%27 = phi i32 [ %23, %21 ], [ %12, %9 ]
%28 = icmp eq i32 %26, %27
%29 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 1)
%30 = icmp eq i32 %29, %27
%31 = select i1 %28, i1 true, i1 %30
%32 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 2)
%33 = icmp eq i32 %32, %27
%34 = select i1 %31, i1 true, i1 %33
br i1 %34, label %35, label %39
35: ; preds = %25
%36 = tail call i32 (...) @rand()
%37 = srem i32 %36, 7
store i32 %37, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 3)
%38 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 0)
br label %39
39: ; preds = %25, %35
%40 = phi i32 [ %38, %35 ], [ %26, %25 ]
%41 = phi i32 [ %37, %35 ], [ %27, %25 ]
%42 = icmp eq i32 %40, %41
%43 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 1)
%44 = icmp eq i32 %43, %41
%45 = select i1 %42, i1 true, i1 %44
%46 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 2)
%47 = icmp eq i32 %46, %41
%48 = select i1 %45, i1 true, i1 %47
br i1 %48, label %49, label %53
49: ; preds = %39
%50 = tail call i32 (...) @rand()
%51 = srem i32 %50, 7
store i32 %51, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 3)
%52 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 0)
br label %53
53: ; preds = %39, %49
%54 = phi i32 [ %52, %49 ], [ %40, %39 ]
%55 = phi i32 [ %51, %49 ], [ %41, %39 ]
%56 = icmp eq i32 %54, %55
%57 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 1)
%58 = icmp eq i32 %57, %55
%59 = select i1 %56, i1 true, i1 %58
%60 = load i32, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 2)
%61 = icmp eq i32 %60, %55
%62 = select i1 %59, i1 true, i1 %61
br i1 %62, label %63, label %66
63: ; preds = %53
%64 = tail call i32 (...) @rand()
%65 = srem i32 %64, 7
store i32 %65, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @random_block.queue, i64 0, i64 3)
br label %66
66: ; preds = %53, %63
ret i32 %10
}