#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, unsigned char);
int rand();
int /*<<< orphan*/ sendvoxel_z(unsigned char, unsigned char, unsigned char,
                               int);
int /*<<< orphan*/ setplane_z(unsigned char);
void sendplane_rand_z(unsigned char z, int delay, int wait) {
  unsigned char loop = 16;
  unsigned char x, y;
  fill(0x00);
  setplane_z(z);
  while (loop) {
    x = rand() % 4;
    y = rand() % 4;
    if (getvoxel(x, y, z)) {
      sendvoxel_z(x, y, z, delay);
      delay_ms(wait);
      loop--;
    }
  }
}


x86 assembly (clang, -O0):
<sendplane_rand_z>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movb   $0x10,-0xd(%rbp)
xor    %edi,%edi
call   1040 <fill@plt>
movzbl -0x1(%rbp),%edi
call   1050 <setplane_z@plt>
cmpb   $0x0,-0xd(%rbp)
je     120a <sendplane_rand_z+0xaa>
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)
mov    -0xe(%rbp),%cl
mov    -0xf(%rbp),%al
movzbl %cl,%edi
movzbl %al,%esi
movzbl -0x1(%rbp),%edx
call   1030 <getvoxel@plt>
cmp    $0x0,%rax
je     1205 <sendplane_rand_z+0xa5>
mov    -0xe(%rbp),%sil
mov    -0xf(%rbp),%dl
mov    -0x1(%rbp),%al
mov    -0x8(%rbp),%ecx
movzbl %sil,%edi
movzbl %dl,%esi
movzbl %al,%edx
call   1070 <sendvoxel_z@plt>
mov    -0xc(%rbp),%edi
call   1060 <delay_ms@plt>
mov    -0xd(%rbp),%al
add    $0xff,%al
mov    %al,-0xd(%rbp)
jmp    1188 <sendplane_rand_z+0x28>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendplane_rand_z>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebx
xor    %edi,%edi
call   1040 <fill@plt>
mov    %ebx,%edi
call   1050 <setplane_z@plt>
mov    $0x10,%r13b
movzbl %bl,%r12d
jmp    1195 <sendplane_rand_z+0x35>
nopw   0x0(%rax,%rax,1)
test   %r13b,%r13b
je     11f3 <sendplane_rand_z+0x93>
xor    %eax,%eax
call   1080 <rand@plt>
mov    %eax,%ebx
lea    0x3(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xfffffffc,%eax
sub    %eax,%ebx
xor    %eax,%eax
call   1080 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
movzbl %bl,%ebp
movzbl %al,%ebx
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r12d,%edx
call   1030 <getvoxel@plt>
test   %rax,%rax
je     1190 <sendplane_rand_z+0x30>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1070 <sendvoxel_z@plt>
mov    %r14d,%edi
call   1060 <delay_ms@plt>
add    $0xff,%r13b
jmp    1190 <sendplane_rand_z+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @sendplane_rand_z(i8 zeroext %0, i32 %1, i32 %2) {
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
store i8 %0, i8* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i8 16, i8* %7
%10 = call i32 @fill(i32 0)
%11 = load i8, i8* %4
%12 = call i32 @setplane_z(i8 zeroext %11)
br label %13
13: ; preds = %38, %3
%14 = load i8, i8* %7
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %39
16: ; preds = %13
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 4
%19 = trunc i32 %18 to i8
store i8 %19, i8* %8
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 4
%22 = trunc i32 %21 to i8
store i8 %22, i8* %9
%23 = load i8, i8* %8
%24 = load i8, i8* %9
%25 = load i8, i8* %4
%26 = call i64 @getvoxel(i8 zeroext %23, i8 zeroext %24, i8 zeroext %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %16
%29 = load i8, i8* %8
%30 = load i8, i8* %9
%31 = load i8, i8* %4
%32 = load i32, i32* %5
%33 = call i32 @sendvoxel_z(i8 zeroext %29, i8 zeroext %30, i8 zeroext %31, i32 %32)
%34 = load i32, i32* %6
%35 = call i32 @delay_ms(i32 %34)
%36 = load i8, i8* %7
%37 = add i8 %36, -1
store i8 %37, i8* %7
br label %38
38: ; preds = %28, %16
br label %13
39: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @sendplane_rand_z(i8 zeroext %0, i32 %1, i32 %2) {
%4 = tail call i32 @fill(i32 0)
%5 = tail call i32 @setplane_z(i8 zeroext %0)
br label %6
6: ; preds = %3, %20
%7 = phi i8 [ 16, %3 ], [ %21, %20 ]
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 4
%10 = trunc i32 %9 to i8
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 4
%13 = trunc i32 %12 to i8
%14 = tail call i64 @getvoxel(i8 zeroext %10, i8 zeroext %13, i8 zeroext %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %6
%17 = tail call i32 @sendvoxel_z(i8 zeroext %10, i8 zeroext %13, i8 zeroext %0, i32 %1)
%18 = tail call i32 @delay_ms(i32 %2)
%19 = add i8 %7, -1
br label %20
20: ; preds = %16, %6
%21 = phi i8 [ %19, %16 ], [ %7, %6 ]
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %6
23: ; preds = %20
ret void
}