#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*/ drawSquares(int /*<<< orphan*/);
int /*<<< orphan*/ glFlush();
int /*<<< orphan*/ glGetIntegerv(int /*<<< orphan*/, int *);
int /*<<< orphan*/ glInitNames();
int /*<<< orphan*/ glLoadIdentity();
int /*<<< orphan*/ glMatrixMode(int /*<<< orphan*/);
int /*<<< orphan*/ glPopMatrix();
int /*<<< orphan*/ glPushMatrix();
int /*<<< orphan*/ glPushName(int /*<<< orphan*/);
int glRenderMode(int /*<<< orphan*/);
int /*<<< orphan*/ glSelectBuffer(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ gluOrtho2D(double, double, double, double);
int /*<<< orphan*/ gluPickMatrix(int /*<<< orphan*/, int /*<<< orphan*/, double,
                                 double, int *);
int /*<<< orphan*/ glutPostRedisplay();
int /*<<< orphan*/ processHits(int, int /*<<< orphan*/ *);
void pickSquares(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(0);
  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  gluPickMatrix((GLdouble)x, (GLdouble)(viewport[3] - y), 5.0, 5.0, viewport);
  gluOrtho2D(0.0, 3.0, 0.0, 3.0);
  drawSquares(GL_SELECT);
  glMatrixMode(GL_PROJECTION);
  glPopMatrix();
  glFlush();
  hits = glRenderMode(GL_RENDER);
  processHits(hits, selectBuf);
  glutPostRedisplay();
}


x86 assembly (clang, -O0):
<pickSquares>:
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    0x2daf(%rip),%rcx
cmp    (%rcx),%eax
jne    122b <pickSquares+0x3b>
mov    -0x8(%rbp),%eax
mov    0x2dbd(%rip),%rcx
cmp    (%rcx),%eax
je     1230 <pickSquares+0x40>
jmp    131e <pickSquares+0x12e>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    -0x830(%rbp),%rsi
call   1100 <glGetIntegerv@plt>
lea    -0x810(%rbp),%rsi
mov    $0x200,%edi
call   1040 <glSelectBuffer@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   10c0 <glRenderMode@plt>
mov    $0x0,%al
call   10b0 <glInitNames@plt>
xor    %edi,%edi
call   1110 <glPushName@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   1050 <glMatrixMode@plt>
mov    $0x0,%al
call   10d0 <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  0xd5f(%rip),%xmm1
movaps %xmm1,%xmm0
call   10f0 <gluPickMatrix@plt>
xorps  %xmm2,%xmm2
movsd  0xd44(%rip),%xmm3
movaps %xmm2,%xmm0
movaps %xmm3,%xmm1
call   10e0 <gluOrtho2D@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
call   1030 <drawSquares@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
call   1050 <glMatrixMode@plt>
mov    $0x0,%al
call   1070 <glPopMatrix@plt>
mov    $0x0,%al
call   10a0 <glFlush@plt>
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
call   10c0 <glRenderMode@plt>
mov    %eax,-0x814(%rbp)
mov    -0x814(%rbp),%edi
lea    -0x810(%rbp),%rsi
call   1060 <processHits@plt>
mov    $0x0,%al
call   1090 <glutPostRedisplay@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pickSquares>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    0x2db8(%rip),%rax
cmp    %edi,(%rax)
jne    12f5 <pickSquares+0x105>
mov    0x2dc9(%rip),%rax
cmp    %esi,(%rax)
jne    12f5 <pickSquares+0x105>
mov    %ecx,%ebx
mov    %edx,%ebp
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%r15
mov    %r15,%rsi
call   1100 <glGetIntegerv@plt>
lea    0x10(%rsp),%r14
mov    $0x200,%edi
mov    %r14,%rsi
call   1040 <glSelectBuffer@plt>
mov    0x2d98(%rip),%r12
mov    (%r12),%edi
call   10c0 <glRenderMode@plt>
xor    %eax,%eax
call   10b0 <glInitNames@plt>
xor    %edi,%edi
call   1110 <glPushName@plt>
mov    0x2d5a(%rip),%r13
mov    0x0(%r13),%edi
call   1050 <glMatrixMode@plt>
xor    %eax,%eax
call   10d0 <glPushMatrix@plt>
xor    %eax,%eax
call   1080 <glLoadIdentity@plt>
mov    0xc(%rsp),%esi
sub    %ebx,%esi
movsd  0xd6d(%rip),%xmm0
mov    %ebp,%edi
movaps %xmm0,%xmm1
mov    %r15,%rdx
call   10f0 <gluPickMatrix@plt>
movsd  0xd60(%rip),%xmm1
xorps  %xmm0,%xmm0
xorps  %xmm2,%xmm2
movaps %xmm1,%xmm3
call   10e0 <gluOrtho2D@plt>
mov    (%r12),%edi
call   1030 <drawSquares@plt>
mov    0x0(%r13),%edi
call   1050 <glMatrixMode@plt>
xor    %eax,%eax
call   1070 <glPopMatrix@plt>
xor    %eax,%eax
call   10a0 <glFlush@plt>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
call   10c0 <glRenderMode@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1060 <processHits@plt>
xor    %eax,%eax
call   1090 <glutPostRedisplay@plt>
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 @pickSquares(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 %54
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 0)
%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 @gluOrtho2D(double 0.000000e+00, double 3.000000e+00, double 0.000000e+00, double 3.000000e+00)
%42 = load i32, i32* @GL_SELECT
%43 = call i32 @drawSquares(i32 %42)
%44 = load i32, i32* @GL_PROJECTION
%45 = call i32 @glMatrixMode(i32 %44)
%46 = call i32 (...) @glPopMatrix()
%47 = call i32 (...) @glFlush()
%48 = load i32, i32* @GL_RENDER
%49 = call i32 @glRenderMode(i32 %48)
store i32 %49, i32* %10
%50 = load i32, i32* %10
%51 = getelementptr inbounds [512 x i32], [512 x i32]* %9, i64 0, i64 0
%52 = call i32 @processHits(i32 %50, i32* %51)
%53 = call i32 (...) @glutPostRedisplay()
br label %54
54: ; 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 @pickSquares(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 %43
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 0)
%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 @gluOrtho2D(double 0.000000e+00, double 3.000000e+00, double 0.000000e+00, double 3.000000e+00)
%33 = load i32, i32* @GL_SELECT
%34 = call i32 @drawSquares(i32 %33)
%35 = load i32, i32* @GL_PROJECTION
%36 = call i32 @glMatrixMode(i32 %35)
%37 = call i32 (...) @glPopMatrix()
%38 = call i32 (...) @glFlush()
%39 = load i32, i32* @GL_RENDER
%40 = call i32 @glRenderMode(i32 %39)
%41 = call i32 @processHits(i32 %40, i32* %18)
%42 = call i32 (...) @glutPostRedisplay()
br label %43
43: ; preds = %4, %14
ret void
}