#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 */
typedef int /*<<< orphan*/ GLuint;
typedef int GLint;
typedef int /*<<< orphan*/ GLdouble;

/* Variables and functions */
int GLUT_DOWN;
int GLUT_LEFT_BUTTON;
int /*<<< orphan*/ GL_PROJECTION;
int /*<<< orphan*/ GL_RENDER;
int /*<<< orphan*/ GL_SELECT;
int /*<<< orphan*/ GL_VIEWPORT;
int /*<<< orphan*/ drawRects(int /*<<< orphan*/);
int /*<<< orphan*/ glFlush();
int /*<<< orphan*/ glGetIntegerv(int /*<<< orphan*/, int *);
int /*<<< orphan*/ glInitNames();
int /*<<< orphan*/ glLoadIdentity();
int /*<<< orphan*/ glMatrixMode(int /*<<< orphan*/);
int /*<<< orphan*/ glOrtho(double, double, double, double, double, double);
int /*<<< orphan*/ glPopMatrix();
int /*<<< orphan*/ glPushMatrix();
int /*<<< orphan*/ glPushName(int /*<<< orphan*/);
int glRenderMode(int /*<<< orphan*/);
int /*<<< orphan*/ glSelectBuffer(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ gluPickMatrix(int /*<<< orphan*/, int /*<<< orphan*/, double,
                                 double, int *);
int /*<<< orphan*/ processHits(int, int /*<<< orphan*/ *);
void pickRects(int button, int state, int x, int y) {
  GLuint selectBuf[512];
  GLint hits;
  GLint viewport[4];
  if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN)
    return;
  glGetIntegerv(GL_VIEWPORT, viewport);
  glSelectBuffer(512, selectBuf);
  (void)glRenderMode(GL_SELECT);
  glInitNames();
  glPushName((GLuint)~0);
  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  gluPickMatrix((GLdouble)x, (GLdouble)(viewport[3] - y), 5.0, 5.0, viewport);
  glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5);
  drawRects(GL_SELECT);
  glPopMatrix();
  glFlush();
  hits = glRenderMode(GL_RENDER);
  processHits(hits, selectBuf);
}


x86 assembly (clang, -O0):
<pickRects>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2dbf(%rip),%rcx
cmp    (%rcx),%eax
jne    121b <pickRects+0x3b>
mov    -0x8(%rbp),%eax
mov    0x2dcd(%rip),%rcx
cmp    (%rcx),%eax
je     1220 <pickRects+0x40>
jmp    130c <pickRects+0x12c>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
lea    -0x830(%rbp),%rsi
call   10f0 <glGetIntegerv@plt>
lea    -0x810(%rbp),%rsi
mov    $0x200,%edi
call   1030 <glSelectBuffer@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   10b0 <glRenderMode@plt>
mov    $0x0,%al
call   10a0 <glInitNames@plt>
mov    $0xffffffff,%edi
call   1100 <glPushName@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
call   1040 <glMatrixMode@plt>
mov    $0x0,%al
call   10c0 <glPushMatrix@plt>
mov    $0x0,%al
call   1080 <glLoadIdentity@plt>
mov    -0xc(%rbp),%edi
mov    -0x824(%rbp),%esi
sub    -0x10(%rbp),%esi
lea    -0x830(%rbp),%rdx
movsd  0xd7c(%rip),%xmm1
movaps %xmm1,%xmm0
call   10d0 <gluPickMatrix@plt>
xorps  %xmm2,%xmm2
movsd  0xd51(%rip),%xmm3
movsd  0xd51(%rip),%xmm4
movsd  0xd51(%rip),%xmm5
movaps %xmm2,%xmm0
movaps %xmm3,%xmm1
call   1050 <glOrtho@plt>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
call   10e0 <drawRects@plt>
mov    $0x0,%al
call   1070 <glPopMatrix@plt>
mov    $0x0,%al
call   1090 <glFlush@plt>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
call   10b0 <glRenderMode@plt>
mov    %eax,-0x814(%rbp)
mov    -0x814(%rbp),%edi
lea    -0x810(%rbp),%rsi
call   1060 <processHits@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pickRects>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x810,%rsp
mov    0x2dca(%rip),%rax
cmp    %edi,(%rax)
jne    12e4 <pickRects+0x104>
mov    0x2ddb(%rip),%rax
cmp    %esi,(%rax)
jne    12e4 <pickRects+0x104>
mov    %ecx,%ebx
mov    %edx,%ebp
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%r15
mov    %r15,%rsi
call   10f0 <glGetIntegerv@plt>
lea    0x10(%rsp),%r14
mov    $0x200,%edi
mov    %r14,%rsi
call   1030 <glSelectBuffer@plt>
mov    0x2daa(%rip),%r12
mov    (%r12),%edi
call   10b0 <glRenderMode@plt>
xor    %eax,%eax
call   10a0 <glInitNames@plt>
mov    $0xffffffff,%edi
call   1100 <glPushName@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   1040 <glMatrixMode@plt>
xor    %eax,%eax
call   10c0 <glPushMatrix@plt>
xor    %eax,%eax
call   1080 <glLoadIdentity@plt>
mov    0xc(%rsp),%esi
sub    %ebx,%esi
movsd  0xd7e(%rip),%xmm0
mov    %ebp,%edi
movaps %xmm0,%xmm1
mov    %r15,%rdx
call   10d0 <gluPickMatrix@plt>
movsd  0xd71(%rip),%xmm1
movsd  0xd71(%rip),%xmm4
movsd  0xd71(%rip),%xmm5
xorps  %xmm0,%xmm0
xorps  %xmm2,%xmm2
movaps %xmm1,%xmm3
call   1050 <glOrtho@plt>
mov    (%r12),%edi
call   10e0 <drawRects@plt>
xor    %eax,%eax
call   1070 <glPopMatrix@plt>
xor    %eax,%eax
call   1090 <glFlush@plt>
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
call   10b0 <glRenderMode@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1060 <processHits@plt>
add    $0x810,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@GLUT_LEFT_BUTTON = global i32 0
@GLUT_DOWN = global i32 0
@GL_VIEWPORT = global i32 0
@GL_SELECT = global i32 0
@GL_PROJECTION = global i32 0
@GL_RENDER = global i32 0
define void @pickRects(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [512 x i32]
%10 = alloca i32
%11 = alloca [4 x i32]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %5
%13 = load i32, i32* @GLUT_LEFT_BUTTON
%14 = icmp ne i32 %12, %13
br i1 %14, label %19, label %15
15: ; preds = %4
%16 = load i32, i32* %6
%17 = load i32, i32* @GLUT_DOWN
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15, %4
br label %51
20: ; preds = %15
%21 = load i32, i32* @GL_VIEWPORT
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%23 = call i32 @glGetIntegerv(i32 %21, i32* %22)
%24 = getelementptr inbounds [512 x i32], [512 x i32]* %9, i64 0, i64 0
%25 = call i32 @glSelectBuffer(i32 512, i32* %24)
%26 = load i32, i32* @GL_SELECT
%27 = call i32 @glRenderMode(i32 %26)
%28 = call i32 (...) @glInitNames()
%29 = call i32 @glPushName(i32 -1)
%30 = load i32, i32* @GL_PROJECTION
%31 = call i32 @glMatrixMode(i32 %30)
%32 = call i32 (...) @glPushMatrix()
%33 = call i32 (...) @glLoadIdentity()
%34 = load i32, i32* %7
%35 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 3
%36 = load i32, i32* %35
%37 = load i32, i32* %8
%38 = sub nsw i32 %36, %37
%39 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%40 = call i32 @gluPickMatrix(i32 %34, i32 %38, double 5.000000e+00, double 5.000000e+00, i32* %39)
%41 = call i32 @glOrtho(double 0.000000e+00, double 8.000000e+00, double 0.000000e+00, double 8.000000e+00, double -5.000000e-01, double 2.500000e+00)
%42 = load i32, i32* @GL_SELECT
%43 = call i32 @drawRects(i32 %42)
%44 = call i32 (...) @glPopMatrix()
%45 = call i32 (...) @glFlush()
%46 = load i32, i32* @GL_RENDER
%47 = call i32 @glRenderMode(i32 %46)
store i32 %47, i32* %10
%48 = load i32, i32* %10
%49 = getelementptr inbounds [512 x i32], [512 x i32]* %9, i64 0, i64 0
%50 = call i32 @processHits(i32 %48, i32* %49)
br label %51
51: ; preds = %20, %19
ret void
}

LLVM IR (-O2):
@GLUT_LEFT_BUTTON = global i32 0
@GLUT_DOWN = global i32 0
@GL_VIEWPORT = global i32 0
@GL_SELECT = global i32 0
@GL_PROJECTION = global i32 0
@GL_RENDER = global i32 0
define void @pickRects(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [512 x i32]
%6 = alloca [4 x i32]
%7 = bitcast [512 x i32]* %5 to i8*
%8 = bitcast [4 x i32]* %6 to i8*
%9 = load i32, i32* @GLUT_LEFT_BUTTON
%10 = icmp eq i32 %9, %0
%11 = load i32, i32* @GLUT_DOWN
%12 = icmp eq i32 %11, %1
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %14, label %40
14: ; preds = %4
%15 = load i32, i32* @GL_VIEWPORT
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%17 = call i32 @glGetIntegerv(i32 %15, i32* %16)
%18 = getelementptr inbounds [512 x i32], [512 x i32]* %5, i64 0, i64 0
%19 = call i32 @glSelectBuffer(i32 512, i32* %18)
%20 = load i32, i32* @GL_SELECT
%21 = call i32 @glRenderMode(i32 %20)
%22 = call i32 (...) @glInitNames()
%23 = call i32 @glPushName(i32 -1)
%24 = load i32, i32* @GL_PROJECTION
%25 = call i32 @glMatrixMode(i32 %24)
%26 = call i32 (...) @glPushMatrix()
%27 = call i32 (...) @glLoadIdentity()
%28 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 3
%29 = load i32, i32* %28
%30 = sub nsw i32 %29, %3
%31 = call i32 @gluPickMatrix(i32 %2, i32 %30, double 5.000000e+00, double 5.000000e+00, i32* %16)
%32 = call i32 @glOrtho(double 0.000000e+00, double 8.000000e+00, double 0.000000e+00, double 8.000000e+00, double -5.000000e-01, double 2.500000e+00)
%33 = load i32, i32* @GL_SELECT
%34 = call i32 @drawRects(i32 %33)
%35 = call i32 (...) @glPopMatrix()
%36 = call i32 (...) @glFlush()
%37 = load i32, i32* @GL_RENDER
%38 = call i32 @glRenderMode(i32 %37)
%39 = call i32 @processHits(i32 %38, i32* %18)
br label %40
40: ; preds = %4, %14
ret void
}