#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*/ render_grid(int);
int sand_rand();
void generate_piece(int player, int *pos_x, int *pos_y, unsigned char *color,
                    int x[4], int y[4]) {
  unsigned int piece = sand_rand() % 7;
  *pos_x = 4;
  *pos_y = 0;
  switch (piece) {
  case 0:
    x[0] = -1;
    y[0] = 0;
    x[1] = 0;
    y[1] = 0;
    x[2] = 1;
    y[2] = 0;
    x[3] = 2;
    y[3] = 0;
    *color = 33;
    break;
  case 1:
    x[0] = -1;
    y[0] = 0;
    x[1] = 0;
    y[1] = 0;
    x[2] = 1;
    y[2] = 0;
    x[3] = 1;
    y[3] = 1;
    *color = 38;
    break;
  case 2:
    x[0] = -1;
    y[0] = 0;
    x[1] = 0;
    y[1] = 0;
    x[2] = 1;
    y[2] = 0;
    x[3] = -1;
    y[3] = 1;
    *color = 18;
    break;
  case 3:
    x[0] = 0;
    y[0] = 0;
    x[1] = 1;
    y[1] = 0;
    x[2] = -1;
    y[2] = 1;
    x[3] = 0;
    y[3] = 1;
    *color = 13;
    break;
  case 4:
    x[0] = -1;
    y[0] = 0;
    x[1] = 0;
    y[1] = 0;
    x[2] = 0;
    y[2] = 1;
    x[3] = 1;
    y[3] = 1;
    *color = 8;
    break;
  case 5:
    x[0] = -1;
    y[0] = 0;
    x[1] = 0;
    y[1] = 0;
    x[2] = 1;
    y[2] = 0;
    x[3] = 0;
    y[3] = 1;
    *color = 28;
    break;
  case 6:
    x[0] = 0;
    y[0] = 0;
    x[1] = 1;
    y[1] = 0;
    x[2] = 0;
    y[2] = 1;
    x[3] = 1;
    y[3] = 1;
    *color = 23;
    break;
  }
  render_grid(player);
}


x86 assembly (clang, -O0):
<generate_piece>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
xor    %eax,%eax
call   1030 <sand_rand@plt>
movslq %eax,%rcx
imul   $0xffffffff92492493,%rcx,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x2,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x3,%edx
sub    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x34(%rbp),%eax
mov    %rax,-0x40(%rbp)
sub    $0x6,%rax
ja     144e <generate_piece+0x32e>
mov    -0x40(%rbp),%rax
lea    0xe64(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x28(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,0x8(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x28(%rbp),%rax
movl   $0x2,0xc(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,0xc(%rax)
mov    -0x20(%rbp),%rax
movb   $0x21,(%rax)
jmp    144e <generate_piece+0x32e>
mov    -0x28(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,0x8(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    -0x30(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    -0x20(%rbp),%rax
movb   $0x26,(%rax)
jmp    144e <generate_piece+0x32e>
mov    -0x28(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,0x8(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x28(%rbp),%rax
movl   $0xffffffff,0xc(%rax)
mov    -0x30(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    -0x20(%rbp),%rax
movb   $0x12,(%rax)
jmp    144e <generate_piece+0x32e>
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,0x4(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x28(%rbp),%rax
movl   $0xffffffff,0x8(%rax)
mov    -0x30(%rbp),%rax
movl   $0x1,0x8(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,0xc(%rax)
mov    -0x30(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    -0x20(%rbp),%rax
movb   $0xd,(%rax)
jmp    144e <generate_piece+0x32e>
mov    -0x28(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x30(%rbp),%rax
movl   $0x1,0x8(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    -0x30(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    -0x20(%rbp),%rax
movb   $0x8,(%rax)
jmp    144e <generate_piece+0x32e>
mov    -0x28(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,0x8(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,0xc(%rax)
mov    -0x30(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    -0x20(%rbp),%rax
movb   $0x1c,(%rax)
jmp    144e <generate_piece+0x32e>
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,0x4(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x30(%rbp),%rax
movl   $0x1,0x8(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    -0x30(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    -0x20(%rbp),%rax
movb   $0x17,(%rax)
mov    -0x4(%rbp),%edi
call   1040 <render_grid@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_piece>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r12
mov    %r8,%r13
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r15d
xor    %eax,%eax
call   1030 <sand_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
movl   $0x4,0x0(%rbp)
movl   $0x0,(%rbx)
cmp    $0x6,%ecx
ja     11f9 <generate_piece+0xd9>
movslq %ecx,%rax
lea    0xe7c(%rip),%rdx
mov    (%rdx,%rax,4),%r8d
lea    0xe8d(%rip),%rsi
mov    (%rsi,%rax,4),%esi
lea    0xe9f(%rip),%rdi
mov    (%rdi,%rax,4),%edi
lea    0xeb1(%rip),%rbp
mov    0x0(%rbp,%rax,4),%ebp
lea    0xec2(%rip),%rbx
mov    (%rbx,%rax,4),%ebx
lea    0xed4(%rip),%rdx
mov    (%rdx,%rax,4),%eax
shl    $0x3,%ecx
movabs $0x171c080d122621,%rdx
shr    %cl,%rdx
mov    %r8d,0x0(%r13)
movl   $0x0,(%r12)
mov    %esi,0x4(%r13)
movl   $0x0,0x4(%r12)
mov    %edi,0x8(%r13)
mov    %ebp,0x8(%r12)
mov    %ebx,0xc(%r13)
mov    %eax,0xc(%r12)
mov    %dl,(%r14)
mov    %r15d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <render_grid@plt>

LLVM IR (-O0):
define void @generate_piece(i32 %0, i32* %1, i32* %2, i8* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
store i32 %0, i32* %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i8* %3, i8** %10
store i32* %4, i32** %11
store i32* %5, i32** %12
%14 = call i32 (...) @sand_rand()
%15 = srem i32 %14, 7
store i32 %15, i32* %13
%16 = load i32*, i32** %8
store i32 4, i32* %16
%17 = load i32*, i32** %9
store i32 0, i32* %17
%18 = load i32, i32* %13
switch i32 %18, label %145 [
i32 0, label %19
i32 1, label %37
i32 2, label %55
i32 3, label %73
i32 4, label %91
i32 5, label %109
i32 6, label %127
]
19: ; preds = %6
%20 = load i32*, i32** %11
%21 = getelementptr inbounds i32, i32* %20, i64 0
store i32 -1, i32* %21
%22 = load i32*, i32** %12
%23 = getelementptr inbounds i32, i32* %22, i64 0
store i32 0, i32* %23
%24 = load i32*, i32** %11
%25 = getelementptr inbounds i32, i32* %24, i64 1
store i32 0, i32* %25
%26 = load i32*, i32** %12
%27 = getelementptr inbounds i32, i32* %26, i64 1
store i32 0, i32* %27
%28 = load i32*, i32** %11
%29 = getelementptr inbounds i32, i32* %28, i64 2
store i32 1, i32* %29
%30 = load i32*, i32** %12
%31 = getelementptr inbounds i32, i32* %30, i64 2
store i32 0, i32* %31
%32 = load i32*, i32** %11
%33 = getelementptr inbounds i32, i32* %32, i64 3
store i32 2, i32* %33
%34 = load i32*, i32** %12
%35 = getelementptr inbounds i32, i32* %34, i64 3
store i32 0, i32* %35
%36 = load i8*, i8** %10
store i8 33, i8* %36
br label %145
37: ; preds = %6
%38 = load i32*, i32** %11
%39 = getelementptr inbounds i32, i32* %38, i64 0
store i32 -1, i32* %39
%40 = load i32*, i32** %12
%41 = getelementptr inbounds i32, i32* %40, i64 0
store i32 0, i32* %41
%42 = load i32*, i32** %11
%43 = getelementptr inbounds i32, i32* %42, i64 1
store i32 0, i32* %43
%44 = load i32*, i32** %12
%45 = getelementptr inbounds i32, i32* %44, i64 1
store i32 0, i32* %45
%46 = load i32*, i32** %11
%47 = getelementptr inbounds i32, i32* %46, i64 2
store i32 1, i32* %47
%48 = load i32*, i32** %12
%49 = getelementptr inbounds i32, i32* %48, i64 2
store i32 0, i32* %49
%50 = load i32*, i32** %11
%51 = getelementptr inbounds i32, i32* %50, i64 3
store i32 1, i32* %51
%52 = load i32*, i32** %12
%53 = getelementptr inbounds i32, i32* %52, i64 3
store i32 1, i32* %53
%54 = load i8*, i8** %10
store i8 38, i8* %54
br label %145
55: ; preds = %6
%56 = load i32*, i32** %11
%57 = getelementptr inbounds i32, i32* %56, i64 0
store i32 -1, i32* %57
%58 = load i32*, i32** %12
%59 = getelementptr inbounds i32, i32* %58, i64 0
store i32 0, i32* %59
%60 = load i32*, i32** %11
%61 = getelementptr inbounds i32, i32* %60, i64 1
store i32 0, i32* %61
%62 = load i32*, i32** %12
%63 = getelementptr inbounds i32, i32* %62, i64 1
store i32 0, i32* %63
%64 = load i32*, i32** %11
%65 = getelementptr inbounds i32, i32* %64, i64 2
store i32 1, i32* %65
%66 = load i32*, i32** %12
%67 = getelementptr inbounds i32, i32* %66, i64 2
store i32 0, i32* %67
%68 = load i32*, i32** %11
%69 = getelementptr inbounds i32, i32* %68, i64 3
store i32 -1, i32* %69
%70 = load i32*, i32** %12
%71 = getelementptr inbounds i32, i32* %70, i64 3
store i32 1, i32* %71
%72 = load i8*, i8** %10
store i8 18, i8* %72
br label %145
73: ; preds = %6
%74 = load i32*, i32** %11
%75 = getelementptr inbounds i32, i32* %74, i64 0
store i32 0, i32* %75
%76 = load i32*, i32** %12
%77 = getelementptr inbounds i32, i32* %76, i64 0
store i32 0, i32* %77
%78 = load i32*, i32** %11
%79 = getelementptr inbounds i32, i32* %78, i64 1
store i32 1, i32* %79
%80 = load i32*, i32** %12
%81 = getelementptr inbounds i32, i32* %80, i64 1
store i32 0, i32* %81
%82 = load i32*, i32** %11
%83 = getelementptr inbounds i32, i32* %82, i64 2
store i32 -1, i32* %83
%84 = load i32*, i32** %12
%85 = getelementptr inbounds i32, i32* %84, i64 2
store i32 1, i32* %85
%86 = load i32*, i32** %11
%87 = getelementptr inbounds i32, i32* %86, i64 3
store i32 0, i32* %87
%88 = load i32*, i32** %12
%89 = getelementptr inbounds i32, i32* %88, i64 3
store i32 1, i32* %89
%90 = load i8*, i8** %10
store i8 13, i8* %90
br label %145
91: ; preds = %6
%92 = load i32*, i32** %11
%93 = getelementptr inbounds i32, i32* %92, i64 0
store i32 -1, i32* %93
%94 = load i32*, i32** %12
%95 = getelementptr inbounds i32, i32* %94, i64 0
store i32 0, i32* %95
%96 = load i32*, i32** %11
%97 = getelementptr inbounds i32, i32* %96, i64 1
store i32 0, i32* %97
%98 = load i32*, i32** %12
%99 = getelementptr inbounds i32, i32* %98, i64 1
store i32 0, i32* %99
%100 = load i32*, i32** %11
%101 = getelementptr inbounds i32, i32* %100, i64 2
store i32 0, i32* %101
%102 = load i32*, i32** %12
%103 = getelementptr inbounds i32, i32* %102, i64 2
store i32 1, i32* %103
%104 = load i32*, i32** %11
%105 = getelementptr inbounds i32, i32* %104, i64 3
store i32 1, i32* %105
%106 = load i32*, i32** %12
%107 = getelementptr inbounds i32, i32* %106, i64 3
store i32 1, i32* %107
%108 = load i8*, i8** %10
store i8 8, i8* %108
br label %145
109: ; preds = %6
%110 = load i32*, i32** %11
%111 = getelementptr inbounds i32, i32* %110, i64 0
store i32 -1, i32* %111
%112 = load i32*, i32** %12
%113 = getelementptr inbounds i32, i32* %112, i64 0
store i32 0, i32* %113
%114 = load i32*, i32** %11
%115 = getelementptr inbounds i32, i32* %114, i64 1
store i32 0, i32* %115
%116 = load i32*, i32** %12
%117 = getelementptr inbounds i32, i32* %116, i64 1
store i32 0, i32* %117
%118 = load i32*, i32** %11
%119 = getelementptr inbounds i32, i32* %118, i64 2
store i32 1, i32* %119
%120 = load i32*, i32** %12
%121 = getelementptr inbounds i32, i32* %120, i64 2
store i32 0, i32* %121
%122 = load i32*, i32** %11
%123 = getelementptr inbounds i32, i32* %122, i64 3
store i32 0, i32* %123
%124 = load i32*, i32** %12
%125 = getelementptr inbounds i32, i32* %124, i64 3
store i32 1, i32* %125
%126 = load i8*, i8** %10
store i8 28, i8* %126
br label %145
127: ; preds = %6
%128 = load i32*, i32** %11
%129 = getelementptr inbounds i32, i32* %128, i64 0
store i32 0, i32* %129
%130 = load i32*, i32** %12
%131 = getelementptr inbounds i32, i32* %130, i64 0
store i32 0, i32* %131
%132 = load i32*, i32** %11
%133 = getelementptr inbounds i32, i32* %132, i64 1
store i32 1, i32* %133
%134 = load i32*, i32** %12
%135 = getelementptr inbounds i32, i32* %134, i64 1
store i32 0, i32* %135
%136 = load i32*, i32** %11
%137 = getelementptr inbounds i32, i32* %136, i64 2
store i32 0, i32* %137
%138 = load i32*, i32** %12
%139 = getelementptr inbounds i32, i32* %138, i64 2
store i32 1, i32* %139
%140 = load i32*, i32** %11
%141 = getelementptr inbounds i32, i32* %140, i64 3
store i32 1, i32* %141
%142 = load i32*, i32** %12
%143 = getelementptr inbounds i32, i32* %142, i64 3
store i32 1, i32* %143
%144 = load i8*, i8** %10
store i8 23, i8* %144
br label %145
145: ; preds = %6, %127, %109, %91, %73, %55, %37, %19
%146 = load i32, i32* %7
%147 = call i32 @render_grid(i32 %146)
ret void
}

LLVM IR (-O2):
@switch.table.generate_piece = [7 x i32] [i32 -1, i32 -1, i32 -1, i32 0, i32 -1, i32 -1, i32 0]
@switch.table.generate_piece.1 = [7 x i32] [i32 0, i32 0, i32 0, i32 1, i32 0, i32 0, i32 1]
@switch.table.generate_piece.2 = [7 x i32] [i32 1, i32 1, i32 1, i32 -1, i32 0, i32 1, i32 0]
@switch.table.generate_piece.3 = [7 x i32] [i32 0, i32 0, i32 0, i32 1, i32 1, i32 0, i32 1]
@switch.table.generate_piece.4 = [7 x i32] [i32 2, i32 1, i32 -1, i32 0, i32 1, i32 0, i32 1]
@switch.table.generate_piece.5 = [7 x i32] [i32 0, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1]
define void @generate_piece(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i8* nocapture writeonly %3, i32* writeonly %4, i32* writeonly %5) {
%7 = tail call i32 (...) @sand_rand()
%8 = srem i32 %7, 7
store i32 4, i32* %1
store i32 0, i32* %2
%9 = icmp ult i32 %8, 7
br i1 %9, label %10, label %39
10: ; preds = %6
%11 = sext i32 %8 to i64
%12 = getelementptr inbounds [7 x i32], [7 x i32]* @switch.table.generate_piece, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = sext i32 %8 to i64
%15 = getelementptr inbounds [7 x i32], [7 x i32]* @switch.table.generate_piece.1, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = sext i32 %8 to i64
%18 = getelementptr inbounds [7 x i32], [7 x i32]* @switch.table.generate_piece.2, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = sext i32 %8 to i64
%21 = getelementptr inbounds [7 x i32], [7 x i32]* @switch.table.generate_piece.3, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = sext i32 %8 to i64
%24 = getelementptr inbounds [7 x i32], [7 x i32]* @switch.table.generate_piece.4, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = sext i32 %8 to i64
%27 = getelementptr inbounds [7 x i32], [7 x i32]* @switch.table.generate_piece.5, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = zext i32 %8 to i56
%30 = shl nuw nsw i56 %29, 3
%31 = lshr i56 6504745368954401, %30
%32 = trunc i56 %31 to i8
store i32 %13, i32* %4
store i32 0, i32* %5
%33 = getelementptr inbounds i32, i32* %4, i64 1
store i32 %16, i32* %33
%34 = getelementptr inbounds i32, i32* %5, i64 1
store i32 0, i32* %34
%35 = getelementptr inbounds i32, i32* %4, i64 2
store i32 %19, i32* %35
%36 = getelementptr inbounds i32, i32* %5, i64 2
store i32 %22, i32* %36
%37 = getelementptr inbounds i32, i32* %4, i64 3
store i32 %25, i32* %37
%38 = getelementptr inbounds i32, i32* %5, i64 3
store i32 %28, i32* %38
store i8 %32, i8* %3
br label %39
39: ; preds = %6, %10
%40 = tail call i32 @render_grid(i32 %0)
ret void
}