#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*/ delay_ms(int);
int /*<<< orphan*/ fill(int);
scalar_t__ getvoxel(unsigned char, unsigned char, int /*<<< orphan*/);
int rand();
int /*<<< orphan*/ sendvoxel_z(unsigned char, unsigned char, int, int);
int /*<<< orphan*/ setvoxel(unsigned char, unsigned char, int);
void sendvoxels_rand_z(int iterations, int delay, int wait) {
  unsigned char loop = 16;
  unsigned char x, y, last_x, last_y, i;
  fill(0x00);
  for (x = 0; x < 4; x++) {
    for (y = 0; y < 4; y++) {
      if (rand() % 2 == 0) {
        setvoxel(x, y, 0);
      } else {
        setvoxel(x, y, 3);
      }
    }
  }
  for (i = 0; i < iterations; i++) {
    x = rand() % 4;
    y = rand() % 4;
    if (y != last_y && x != last_x) {
      if (getvoxel(x, y, 0)) {
        sendvoxel_z(x, y, 0, delay);
      } else {
        sendvoxel_z(x, y, 3, delay);
      }
      delay_ms(wait);
      last_y = y;
      last_x = x;
    }
  }
}


x86 assembly (clang, -O0):
<sendvoxels_rand_z>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movb   $0x10,-0xd(%rbp)
xor    %edi,%edi
call   1040 <fill@plt>
movb   $0x0,-0xe(%rbp)
movzbl -0xe(%rbp),%eax
cmp    $0x4,%eax
jge    1204 <sendvoxels_rand_z+0xa4>
movb   $0x0,-0xf(%rbp)
movzbl -0xf(%rbp),%eax
cmp    $0x4,%eax
jge    11f2 <sendvoxels_rand_z+0x92>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11cc <sendvoxels_rand_z+0x6c>
mov    -0xe(%rbp),%al
xor    %edx,%edx
movzbl %al,%edi
movzbl -0xf(%rbp),%esi
call   1050 <setvoxel@plt>
jmp    11e0 <sendvoxels_rand_z+0x80>
mov    -0xe(%rbp),%al
mov    $0x3,%edx
movzbl %al,%edi
movzbl -0xf(%rbp),%esi
call   1050 <setvoxel@plt>
jmp    11e5 <sendvoxels_rand_z+0x85>
mov    -0xf(%rbp),%al
add    $0x1,%al
mov    %al,-0xf(%rbp)
jmp    1191 <sendvoxels_rand_z+0x31>
jmp    11f7 <sendvoxels_rand_z+0x97>
mov    -0xe(%rbp),%al
add    $0x1,%al
mov    %al,-0xe(%rbp)
jmp    1180 <sendvoxels_rand_z+0x20>
movb   $0x0,-0x12(%rbp)
movzbl -0x12(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12d6 <sendvoxels_rand_z+0x176>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0xe(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0xf(%rbp)
movzbl -0xf(%rbp),%eax
movzbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
je     12c4 <sendvoxels_rand_z+0x164>
movzbl -0xe(%rbp),%eax
movzbl -0x10(%rbp),%ecx
cmp    %ecx,%eax
je     12c4 <sendvoxels_rand_z+0x164>
mov    -0xe(%rbp),%al
xor    %edx,%edx
movzbl %al,%edi
movzbl -0xf(%rbp),%esi
call   1030 <getvoxel@plt>
cmp    $0x0,%rax
je     1295 <sendvoxels_rand_z+0x135>
mov    -0xe(%rbp),%sil
mov    -0xf(%rbp),%al
mov    -0x8(%rbp),%ecx
xor    %edx,%edx
movzbl %sil,%edi
movzbl %al,%esi
call   1070 <sendvoxel_z@plt>
jmp    12b0 <sendvoxels_rand_z+0x150>
mov    -0xe(%rbp),%sil
mov    -0xf(%rbp),%al
mov    -0x8(%rbp),%ecx
mov    $0x3,%edx
movzbl %sil,%edi
movzbl %al,%esi
call   1070 <sendvoxel_z@plt>
mov    -0xc(%rbp),%edi
call   1060 <delay_ms@plt>
mov    -0xf(%rbp),%al
mov    %al,-0x11(%rbp)
mov    -0xe(%rbp),%al
mov    %al,-0x10(%rbp)
jmp    12c9 <sendvoxels_rand_z+0x169>
mov    -0x12(%rbp),%al
add    $0x1,%al
mov    %al,-0x12(%rbp)
jmp    1208 <sendvoxels_rand_z+0xa8>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendvoxels_rand_z>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0x10(%rsp)
mov    %esi,0xc(%rsp)
mov    %edi,%ebx
xor    %edi,%edi
call   1040 <fill@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
xor    %edi,%edi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
xor    %edi,%edi
mov    $0x1,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
xor    %edi,%edi
mov    $0x2,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
xor    %edi,%edi
mov    $0x3,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
mov    $0x1,%edi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
mov    $0x1,%edi
mov    $0x1,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
mov    $0x1,%edi
mov    $0x2,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
mov    $0x1,%edi
mov    $0x3,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
mov    $0x2,%edi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
mov    $0x2,%edi
mov    $0x1,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
mov    $0x2,%edi
mov    $0x2,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
mov    $0x2,%edi
mov    $0x3,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
mov    $0x3,%edi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
mov    $0x3,%edi
mov    $0x1,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
mov    $0x3,%edi
mov    $0x2,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
xor    %eax,%eax
call   1080 <rand@plt>
and    $0x1,%eax
neg    %eax
and    $0x3,%eax
mov    $0x3,%edi
mov    $0x3,%esi
mov    %eax,%edx
call   1050 <setvoxel@plt>
mov    %ebx,0x14(%rsp)
test   %ebx,%ebx
jle    1414 <sendvoxels_rand_z+0x2b4>
mov    $0x1,%r15b
jmp    1392 <sendvoxels_rand_z+0x232>
nopl   0x0(%rax,%rax,1)
movzbl %r15b,%eax
lea    0x1(%rax),%r15d
cmp    0x14(%rsp),%eax
jge    1414 <sendvoxels_rand_z+0x2b4>
xor    %eax,%eax
call   1080 <rand@plt>
mov    %eax,%ebp
lea    0x3(%rbp),%r12d
test   %eax,%eax
cmovns %eax,%r12d
xor    %eax,%eax
call   1080 <rand@plt>
mov    %eax,%ebx
lea    0x3(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xfc,%eax
sub    %eax,%ebx
cmp    %bl,%r13b
je     1380 <sendvoxels_rand_z+0x220>
and    $0xfc,%r12d
sub    %r12d,%ebp
cmp    %bpl,%r14b
je     1380 <sendvoxels_rand_z+0x220>
movzbl %bpl,%r13d
movzbl %bl,%r14d
mov    %r13d,%edi
mov    %r14d,%esi
xor    %edx,%edx
call   1030 <getvoxel@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,2),%edx
mov    %r13d,%edi
mov    %r14d,%esi
mov    0xc(%rsp),%ecx
call   1070 <sendvoxel_z@plt>
mov    0x10(%rsp),%edi
call   1060 <delay_ms@plt>
mov    %ebp,%r14d
mov    %ebx,%r13d
jmp    1380 <sendvoxels_rand_z+0x220>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @sendvoxels_rand_z(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i8 16, i8* %7
%13 = call i32 @fill(i32 0)
store i8 0, i8* %8
br label %14
14: ; preds = %40, %3
%15 = load i8, i8* %8
%16 = zext i8 %15 to i32
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %43
18: ; preds = %14
store i8 0, i8* %9
br label %19
19: ; preds = %36, %18
%20 = load i8, i8* %9
%21 = zext i8 %20 to i32
%22 = icmp slt i32 %21, 4
br i1 %22, label %23, label %39
23: ; preds = %19
%24 = call i32 (...) @rand()
%25 = srem i32 %24, 2
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i8, i8* %8
%29 = load i8, i8* %9
%30 = call i32 @setvoxel(i8 zeroext %28, i8 zeroext %29, i32 0)
br label %35
31: ; preds = %23
%32 = load i8, i8* %8
%33 = load i8, i8* %9
%34 = call i32 @setvoxel(i8 zeroext %32, i8 zeroext %33, i32 3)
br label %35
35: ; preds = %31, %27
br label %36
36: ; preds = %35
%37 = load i8, i8* %9
%38 = add i8 %37, 1
store i8 %38, i8* %9
br label %19
39: ; preds = %19
br label %40
40: ; preds = %39
%41 = load i8, i8* %8
%42 = add i8 %41, 1
store i8 %42, i8* %8
br label %14
43: ; preds = %14
store i8 0, i8* %12
br label %44
44: ; preds = %88, %43
%45 = load i8, i8* %12
%46 = zext i8 %45 to i32
%47 = load i32, i32* %4
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %91
49: ; preds = %44
%50 = call i32 (...) @rand()
%51 = srem i32 %50, 4
%52 = trunc i32 %51 to i8
store i8 %52, i8* %8
%53 = call i32 (...) @rand()
%54 = srem i32 %53, 4
%55 = trunc i32 %54 to i8
store i8 %55, i8* %9
%56 = load i8, i8* %9
%57 = zext i8 %56 to i32
%58 = load i8, i8* %11
%59 = zext i8 %58 to i32
%60 = icmp ne i32 %57, %59
br i1 %60, label %61, label %87
61: ; preds = %49
%62 = load i8, i8* %8
%63 = zext i8 %62 to i32
%64 = load i8, i8* %10
%65 = zext i8 %64 to i32
%66 = icmp ne i32 %63, %65
br i1 %66, label %67, label %87
67: ; preds = %61
%68 = load i8, i8* %8
%69 = load i8, i8* %9
%70 = call i64 @getvoxel(i8 zeroext %68, i8 zeroext %69, i32 0)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %77
72: ; preds = %67
%73 = load i8, i8* %8
%74 = load i8, i8* %9
%75 = load i32, i32* %5
%76 = call i32 @sendvoxel_z(i8 zeroext %73, i8 zeroext %74, i32 0, i32 %75)
br label %82
77: ; preds = %67
%78 = load i8, i8* %8
%79 = load i8, i8* %9
%80 = load i32, i32* %5
%81 = call i32 @sendvoxel_z(i8 zeroext %78, i8 zeroext %79, i32 3, i32 %80)
br label %82
82: ; preds = %77, %72
%83 = load i32, i32* %6
%84 = call i32 @delay_ms(i32 %83)
%85 = load i8, i8* %9
store i8 %85, i8* %11
%86 = load i8, i8* %8
store i8 %86, i8* %10
br label %87
87: ; preds = %82, %61, %49
br label %88
88: ; preds = %87
%89 = load i8, i8* %12
%90 = add i8 %89, 1
store i8 %90, i8* %12
br label %44
91: ; preds = %44
ret void
}

LLVM IR (-O2):
define void @sendvoxels_rand_z(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @fill(i32 0)
%5 = tail call i32 (...) @rand()
%6 = and i32 %5, 1
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i32 0, i32 3
%9 = tail call i32 @setvoxel(i8 zeroext 0, i8 zeroext 0, i32 %8)
%10 = tail call i32 (...) @rand()
%11 = and i32 %10, 1
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 0, i32 3
%14 = tail call i32 @setvoxel(i8 zeroext 0, i8 zeroext 1, i32 %13)
%15 = tail call i32 (...) @rand()
%16 = and i32 %15, 1
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i32 0, i32 3
%19 = tail call i32 @setvoxel(i8 zeroext 0, i8 zeroext 2, i32 %18)
%20 = tail call i32 (...) @rand()
%21 = and i32 %20, 1
%22 = icmp eq i32 %21, 0
%23 = select i1 %22, i32 0, i32 3
%24 = tail call i32 @setvoxel(i8 zeroext 0, i8 zeroext 3, i32 %23)
%25 = tail call i32 (...) @rand()
%26 = and i32 %25, 1
%27 = icmp eq i32 %26, 0
%28 = select i1 %27, i32 0, i32 3
%29 = tail call i32 @setvoxel(i8 zeroext 1, i8 zeroext 0, i32 %28)
%30 = tail call i32 (...) @rand()
%31 = and i32 %30, 1
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, i32 0, i32 3
%34 = tail call i32 @setvoxel(i8 zeroext 1, i8 zeroext 1, i32 %33)
%35 = tail call i32 (...) @rand()
%36 = and i32 %35, 1
%37 = icmp eq i32 %36, 0
%38 = select i1 %37, i32 0, i32 3
%39 = tail call i32 @setvoxel(i8 zeroext 1, i8 zeroext 2, i32 %38)
%40 = tail call i32 (...) @rand()
%41 = and i32 %40, 1
%42 = icmp eq i32 %41, 0
%43 = select i1 %42, i32 0, i32 3
%44 = tail call i32 @setvoxel(i8 zeroext 1, i8 zeroext 3, i32 %43)
%45 = tail call i32 (...) @rand()
%46 = and i32 %45, 1
%47 = icmp eq i32 %46, 0
%48 = select i1 %47, i32 0, i32 3
%49 = tail call i32 @setvoxel(i8 zeroext 2, i8 zeroext 0, i32 %48)
%50 = tail call i32 (...) @rand()
%51 = and i32 %50, 1
%52 = icmp eq i32 %51, 0
%53 = select i1 %52, i32 0, i32 3
%54 = tail call i32 @setvoxel(i8 zeroext 2, i8 zeroext 1, i32 %53)
%55 = tail call i32 (...) @rand()
%56 = and i32 %55, 1
%57 = icmp eq i32 %56, 0
%58 = select i1 %57, i32 0, i32 3
%59 = tail call i32 @setvoxel(i8 zeroext 2, i8 zeroext 2, i32 %58)
%60 = tail call i32 (...) @rand()
%61 = and i32 %60, 1
%62 = icmp eq i32 %61, 0
%63 = select i1 %62, i32 0, i32 3
%64 = tail call i32 @setvoxel(i8 zeroext 2, i8 zeroext 3, i32 %63)
%65 = tail call i32 (...) @rand()
%66 = and i32 %65, 1
%67 = icmp eq i32 %66, 0
%68 = select i1 %67, i32 0, i32 3
%69 = tail call i32 @setvoxel(i8 zeroext 3, i8 zeroext 0, i32 %68)
%70 = tail call i32 (...) @rand()
%71 = and i32 %70, 1
%72 = icmp eq i32 %71, 0
%73 = select i1 %72, i32 0, i32 3
%74 = tail call i32 @setvoxel(i8 zeroext 3, i8 zeroext 1, i32 %73)
%75 = tail call i32 (...) @rand()
%76 = and i32 %75, 1
%77 = icmp eq i32 %76, 0
%78 = select i1 %77, i32 0, i32 3
%79 = tail call i32 @setvoxel(i8 zeroext 3, i8 zeroext 2, i32 %78)
%80 = tail call i32 (...) @rand()
%81 = and i32 %80, 1
%82 = icmp eq i32 %81, 0
%83 = select i1 %82, i32 0, i32 3
%84 = tail call i32 @setvoxel(i8 zeroext 3, i8 zeroext 3, i32 %83)
%85 = icmp sgt i32 %0, 0
br i1 %85, label %86, label %111
86: ; preds = %3, %105
%87 = phi i8 [ %108, %105 ], [ 0, %3 ]
%88 = phi i8 [ %107, %105 ], [ undef, %3 ]
%89 = phi i8 [ %106, %105 ], [ undef, %3 ]
%90 = tail call i32 (...) @rand()
%91 = srem i32 %90, 4
%92 = trunc i32 %91 to i8
%93 = tail call i32 (...) @rand()
%94 = srem i32 %93, 4
%95 = trunc i32 %94 to i8
%96 = icmp eq i8 %88, %95
%97 = icmp eq i8 %89, %92
%98 = select i1 %96, i1 true, i1 %97
br i1 %98, label %105, label %99
99: ; preds = %86
%100 = tail call i64 @getvoxel(i8 zeroext %92, i8 zeroext %95, i32 0)
%101 = icmp eq i64 %100, 0
%102 = select i1 %101, i32 3, i32 0
%103 = tail call i32 @sendvoxel_z(i8 zeroext %92, i8 zeroext %95, i32 %102, i32 %1)
%104 = tail call i32 @delay_ms(i32 %2)
br label %105
105: ; preds = %86, %99
%106 = phi i8 [ %92, %99 ], [ %89, %86 ]
%107 = phi i8 [ %95, %99 ], [ %88, %86 ]
%108 = add i8 %87, 1
%109 = zext i8 %108 to i32
%110 = icmp slt i32 %109, %0
br i1 %110, label %86, label %111
111: ; preds = %105, %3
ret void
}