#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 /*<<< orphan*/ GLint;

/* Variables and functions */
int /*<<< orphan*/ GL_MODELVIEW;
int /*<<< orphan*/ GL_PROJECTION;
int /*<<< orphan*/ GL_RENDER;
int /*<<< orphan*/ GL_SELECT;
int /*<<< orphan*/ drawTriangle(double, double, double, double, double, double,
                                double);
int /*<<< orphan*/ glFlush();
int /*<<< orphan*/ glInitNames();
int /*<<< orphan*/ glLoadIdentity();
int /*<<< orphan*/ glLoadName(int);
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 /*<<< orphan*/ glRenderMode(int /*<<< orphan*/);
int /*<<< orphan*/ glSelectBuffer(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ processHits(int /*<<< orphan*/, int /*<<< orphan*/ *);
void selectObjects(void) {
  GLuint selectBuf[512];
  GLint hits;
  glSelectBuffer(512, selectBuf);
  (void)glRenderMode(GL_SELECT);
  glInitNames();
  glPushName(0);
  glPushMatrix();
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0.0, 5.0, 0.0, 5.0, 0.0, 10.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glLoadName(1);
  drawTriangle(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -5.0);
  glLoadName(2);
  drawTriangle(2.0, 7.0, 3.0, 7.0, 2.5, 8.0, -5.0);
  glLoadName(3);
  drawTriangle(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, 0.0);
  drawTriangle(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -10.0);
  glPopMatrix();
  glFlush();
  hits = glRenderMode(GL_RENDER);
  processHits(hits, selectBuf);
}


x86 assembly (clang, -O0):
<selectObjects>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
lea    -0x800(%rbp),%rsi
mov    $0x200,%edi
call   1040 <glSelectBuffer@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   10d0 <glRenderMode@plt>
mov    $0x0,%al
call   10b0 <glInitNames@plt>
xor    %edi,%edi
call   10f0 <glPushName@plt>
mov    $0x0,%al
call   10e0 <glPushMatrix@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1050 <glMatrixMode@plt>
mov    $0x0,%al
call   1090 <glLoadIdentity@plt>
xorps  %xmm4,%xmm4
movsd  0xe09(%rip),%xmm3
movsd  0xe09(%rip),%xmm5
movaps %xmm4,%xmm0
movaps %xmm3,%xmm1
movaps %xmm4,%xmm2
call   1060 <glOrtho@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1050 <glMatrixMode@plt>
mov    $0x0,%al
call   1090 <glLoadIdentity@plt>
mov    $0x1,%edi
call   10c0 <glLoadName@plt>
movsd  0xd94(%rip),%xmm3
movsd  0xd94(%rip),%xmm5
movsd  0xd94(%rip),%xmm4
movsd  0xdac(%rip),%xmm6
movaps %xmm3,%xmm0
movaps %xmm3,%xmm1
movaps %xmm5,%xmm2
call   1030 <drawTriangle@plt>
mov    $0x2,%edi
call   10c0 <glLoadName@plt>
movsd  0xd5c(%rip),%xmm0
movsd  0xd74(%rip),%xmm3
movsd  0xd54(%rip),%xmm2
movsd  0xd54(%rip),%xmm4
movsd  0xd64(%rip),%xmm5
movsd  0xd64(%rip),%xmm6
movaps %xmm3,%xmm1
call   1030 <drawTriangle@plt>
mov    $0x3,%edi
call   10c0 <glLoadName@plt>
movsd  0xd1a(%rip),%xmm3
movsd  0xd1a(%rip),%xmm5
movsd  0xd1a(%rip),%xmm4
xorps  %xmm6,%xmm6
movaps %xmm3,%xmm0
movaps %xmm3,%xmm1
movaps %xmm5,%xmm2
call   1030 <drawTriangle@plt>
movsd  0xcf1(%rip),%xmm3
movsd  0xcf1(%rip),%xmm5
movsd  0xcf1(%rip),%xmm4
movsd  0xcf1(%rip),%xmm6
movaps %xmm3,%xmm0
movaps %xmm3,%xmm1
movaps %xmm5,%xmm2
call   1030 <drawTriangle@plt>
mov    $0x0,%al
call   1080 <glPopMatrix@plt>
mov    $0x0,%al
call   10a0 <glFlush@plt>
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
call   10d0 <glRenderMode@plt>
mov    %eax,-0x804(%rbp)
mov    -0x804(%rbp),%edi
lea    -0x800(%rbp),%rsi
call   1070 <processHits@plt>
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<selectObjects>:
push   %rbx
sub    $0x800,%rsp
mov    %rsp,%rbx
mov    $0x200,%edi
mov    %rbx,%rsi
call   1040 <glSelectBuffer@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   10d0 <glRenderMode@plt>
xor    %eax,%eax
call   10b0 <glInitNames@plt>
xor    %edi,%edi
call   10f0 <glPushName@plt>
xor    %eax,%eax
call   10e0 <glPushMatrix@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1050 <glMatrixMode@plt>
xor    %eax,%eax
call   1090 <glLoadIdentity@plt>
movsd  0xdd8(%rip),%xmm1
movsd  0xdd8(%rip),%xmm5
xorps  %xmm0,%xmm0
xorps  %xmm2,%xmm2
xorps  %xmm4,%xmm4
movaps %xmm1,%xmm3
call   1060 <glOrtho@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   1050 <glMatrixMode@plt>
xor    %eax,%eax
call   1090 <glLoadIdentity@plt>
mov    $0x1,%edi
call   10c0 <glLoadName@plt>
movsd  0xda8(%rip),%xmm0
movsd  0xda8(%rip),%xmm4
movsd  0xda8(%rip),%xmm2
movsd  0xda8(%rip),%xmm6
movaps %xmm0,%xmm1
movaps %xmm0,%xmm3
movaps %xmm2,%xmm5
call   1030 <drawTriangle@plt>
mov    $0x2,%edi
call   10c0 <glLoadName@plt>
movsd  0xd90(%rip),%xmm1
movsd  0xd90(%rip),%xmm5
movsd  0xd60(%rip),%xmm0
movsd  0xd68(%rip),%xmm2
movaps %xmm1,%xmm3
movsd  0xd55(%rip),%xmm4
movsd  0xd5d(%rip),%xmm6
call   1030 <drawTriangle@plt>
mov    $0x3,%edi
call   10c0 <glLoadName@plt>
xorps  %xmm6,%xmm6
movsd  0xd2b(%rip),%xmm0
movaps %xmm0,%xmm1
movsd  0xd30(%rip),%xmm2
movaps %xmm0,%xmm3
movsd  0xd1d(%rip),%xmm4
movaps %xmm2,%xmm5
call   1030 <drawTriangle@plt>
movsd  0xd35(%rip),%xmm6
movsd  0xcfd(%rip),%xmm0
movaps %xmm0,%xmm1
movsd  0xd02(%rip),%xmm2
movaps %xmm0,%xmm3
movsd  0xcef(%rip),%xmm4
movaps %xmm2,%xmm5
call   1030 <drawTriangle@plt>
xor    %eax,%eax
call   1080 <glPopMatrix@plt>
xor    %eax,%eax
call   10a0 <glFlush@plt>
mov    0x2c8a(%rip),%rax
mov    (%rax),%edi
call   10d0 <glRenderMode@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1070 <processHits@plt>
add    $0x800,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@GL_SELECT = global i32 0
@GL_PROJECTION = global i32 0
@GL_MODELVIEW = global i32 0
@GL_RENDER = global i32 0
define void @selectObjects() {
%1 = alloca [512 x i32]
%2 = alloca i32
%3 = getelementptr inbounds [512 x i32], [512 x i32]* %1, i64 0, i64 0
%4 = call i32 @glSelectBuffer(i32 512, i32* %3)
%5 = load i32, i32* @GL_SELECT
%6 = call i32 @glRenderMode(i32 %5)
%7 = call i32 (...) @glInitNames()
%8 = call i32 @glPushName(i32 0)
%9 = call i32 (...) @glPushMatrix()
%10 = load i32, i32* @GL_PROJECTION
%11 = call i32 @glMatrixMode(i32 %10)
%12 = call i32 (...) @glLoadIdentity()
%13 = call i32 @glOrtho(double 0.000000e+00, double 5.000000e+00, double 0.000000e+00, double 5.000000e+00, double 0.000000e+00, double 1.000000e+01)
%14 = load i32, i32* @GL_MODELVIEW
%15 = call i32 @glMatrixMode(i32 %14)
%16 = call i32 (...) @glLoadIdentity()
%17 = call i32 @glLoadName(i32 1)
%18 = call i32 @drawTriangle(double 2.000000e+00, double 2.000000e+00, double 3.000000e+00, double 2.000000e+00, double 2.500000e+00, double 3.000000e+00, double -5.000000e+00)
%19 = call i32 @glLoadName(i32 2)
%20 = call i32 @drawTriangle(double 2.000000e+00, double 7.000000e+00, double 3.000000e+00, double 7.000000e+00, double 2.500000e+00, double 8.000000e+00, double -5.000000e+00)
%21 = call i32 @glLoadName(i32 3)
%22 = call i32 @drawTriangle(double 2.000000e+00, double 2.000000e+00, double 3.000000e+00, double 2.000000e+00, double 2.500000e+00, double 3.000000e+00, double 0.000000e+00)
%23 = call i32 @drawTriangle(double 2.000000e+00, double 2.000000e+00, double 3.000000e+00, double 2.000000e+00, double 2.500000e+00, double 3.000000e+00, double -1.000000e+01)
%24 = call i32 (...) @glPopMatrix()
%25 = call i32 (...) @glFlush()
%26 = load i32, i32* @GL_RENDER
%27 = call i32 @glRenderMode(i32 %26)
store i32 %27, i32* %2
%28 = load i32, i32* %2
%29 = getelementptr inbounds [512 x i32], [512 x i32]* %1, i64 0, i64 0
%30 = call i32 @processHits(i32 %28, i32* %29)
ret void
}

LLVM IR (-O2):
@GL_SELECT = global i32 0
@GL_PROJECTION = global i32 0
@GL_MODELVIEW = global i32 0
@GL_RENDER = global i32 0
define void @selectObjects() {
%1 = alloca [512 x i32]
%2 = bitcast [512 x i32]* %1 to i8*
%3 = getelementptr inbounds [512 x i32], [512 x i32]* %1, i64 0, i64 0
%4 = call i32 @glSelectBuffer(i32 512, i32* %3)
%5 = load i32, i32* @GL_SELECT
%6 = call i32 @glRenderMode(i32 %5)
%7 = call i32 (...) @glInitNames()
%8 = call i32 @glPushName(i32 0)
%9 = call i32 (...) @glPushMatrix()
%10 = load i32, i32* @GL_PROJECTION
%11 = call i32 @glMatrixMode(i32 %10)
%12 = call i32 (...) @glLoadIdentity()
%13 = call i32 @glOrtho(double 0.000000e+00, double 5.000000e+00, double 0.000000e+00, double 5.000000e+00, double 0.000000e+00, double 1.000000e+01)
%14 = load i32, i32* @GL_MODELVIEW
%15 = call i32 @glMatrixMode(i32 %14)
%16 = call i32 (...) @glLoadIdentity()
%17 = call i32 @glLoadName(i32 1)
%18 = call i32 @drawTriangle(double 2.000000e+00, double 2.000000e+00, double 3.000000e+00, double 2.000000e+00, double 2.500000e+00, double 3.000000e+00, double -5.000000e+00)
%19 = call i32 @glLoadName(i32 2)
%20 = call i32 @drawTriangle(double 2.000000e+00, double 7.000000e+00, double 3.000000e+00, double 7.000000e+00, double 2.500000e+00, double 8.000000e+00, double -5.000000e+00)
%21 = call i32 @glLoadName(i32 3)
%22 = call i32 @drawTriangle(double 2.000000e+00, double 2.000000e+00, double 3.000000e+00, double 2.000000e+00, double 2.500000e+00, double 3.000000e+00, double 0.000000e+00)
%23 = call i32 @drawTriangle(double 2.000000e+00, double 2.000000e+00, double 3.000000e+00, double 2.000000e+00, double 2.500000e+00, double 3.000000e+00, double -1.000000e+01)
%24 = call i32 (...) @glPopMatrix()
%25 = call i32 (...) @glFlush()
%26 = load i32, i32* @GL_RENDER
%27 = call i32 @glRenderMode(i32 %26)
%28 = call i32 @processHits(i32 %27, i32* %3)
ret void
}