#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*/ altervoxel(int, int, int, unsigned char);
int /*<<< orphan*/ delay_ms(int);
unsigned char getvoxel(int, int, int);
int rand();
void random_layer_filler(int delay, unsigned char set_state, int z,
                         int voxels) {
  int x, y;
  int loop = voxels;
  unsigned char state = 0x00;
  unsigned char new_state = 0x01;
  if (set_state == 0) {
    state = 0x01;
    new_state = 0x00;
  }
  while (loop) {
    x = rand() % 4;
    y = rand() % 4;
    if (getvoxel(x, y, z) == state) {
      altervoxel(x, y, z, new_state);
      delay_ms(delay);
      loop--;
    }
  }
}


x86 assembly (clang, -O0):
<random_layer_filler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movb   $0x0,-0x1d(%rbp)
movb   $0x1,-0x1e(%rbp)
movzbl -0x5(%rbp),%eax
cmp    $0x0,%eax
jne    117a <random_layer_filler+0x3a>
movb   $0x1,-0x1d(%rbp)
movb   $0x0,-0x1e(%rbp)
jmp    117f <random_layer_filler+0x3f>
cmpl   $0x0,-0x1c(%rbp)
je     11f2 <random_layer_filler+0xb2>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <getvoxel@plt>
movzbl %al,%eax
movzbl -0x1d(%rbp),%ecx
cmp    %ecx,%eax
jne    11ed <random_layer_filler+0xad>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%edx
movzbl -0x1e(%rbp),%ecx
call   1040 <altervoxel@plt>
mov    -0x4(%rbp),%edi
call   1050 <delay_ms@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    117f <random_layer_filler+0x3f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_layer_filler>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,0x4(%rsp)
xor    %r15d,%r15d
test   %esi,%esi
setne  %al
test   %ecx,%ecx
je     11d0 <random_layer_filler+0x90>
mov    %ecx,%r13d
mov    %edx,%r12d
test   %sil,%sil
sete   %r14b
mov    %al,%r15b
jmp    1175 <random_layer_filler+0x35>
nopl   (%rax)
test   %r13d,%r13d
je     11d0 <random_layer_filler+0x90>
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ebp
lea    0x3(%rbp),%eax
test   %ebp,%ebp
cmovns %ebp,%eax
and    $0xfffffffc,%eax
sub    %eax,%ebp
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ebx
lea    0x3(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xfffffffc,%eax
sub    %eax,%ebx
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r12d,%edx
call   1030 <getvoxel@plt>
cmp    %r14b,%al
jne    1170 <random_layer_filler+0x30>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1040 <altervoxel@plt>
mov    0x4(%rsp),%edi
call   1050 <delay_ms@plt>
add    $0xffffffff,%r13d
jmp    1170 <random_layer_filler+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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