#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*/ GL_LINE_STRIP;
int /*<<< orphan*/ glBegin(int /*<<< orphan*/);
int /*<<< orphan*/ glEnd();
int /*<<< orphan*/ glVertex3fv(float *);
void drawLines(int index, float array[511][3]) {
  int p;
  int i;
  p = (index + 1) & 511;
  i = 4 - (p % 4);
  if (i == 4)
    i = 0;
  glBegin(GL_LINE_STRIP);
  while (p != index) {
    if (i == 0) {
      glVertex3fv(array[p]);
      i = 4;
    }
    i--;
    p = (p + 1) & 511;
  }
  glVertex3fv(array[index]);
  glEnd();
}


x86 assembly (clang, -O0):
<drawLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
and    $0x1ff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    $0x4,%eax
sub    %edx,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jne    1173 <drawLines+0x43>
movl   $0x0,-0x18(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
call   1050 <glBegin@plt>
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
je     11ce <drawLines+0x9e>
cmpl   $0x0,-0x18(%rbp)
jne    11b2 <drawLines+0x82>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
imul   $0xc,%rax,%rax
add    %rax,%rdi
call   1040 <glVertex3fv@plt>
movl   $0x4,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
and    $0x1ff,%eax
mov    %eax,-0x14(%rbp)
jmp    1181 <drawLines+0x51>
mov    -0x10(%rbp),%rdi
movslq -0x4(%rbp),%rax
imul   $0xc,%rax,%rax
add    %rax,%rdi
call   1040 <glVertex3fv@plt>
mov    $0x0,%al
call   1030 <glEnd@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drawLines>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x1(%rbx),%r15d
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
call   1050 <glBegin@plt>
mov    %r15d,%ebp
and    $0x1ff,%ebp
cmp    %ebx,%ebp
jne    117c <drawLines+0x4c>
movslq %ebx,%rax
lea    (%rax,%rax,2),%rax
lea    (%r14,%rax,4),%rdi
call   1040 <glVertex3fv@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <glEnd@plt>
and    $0x3,%r15d
mov    $0x4,%eax
sub    %r15d,%eax
test   %r15d,%r15d
cmove  %r15d,%eax
jmp    11b0 <drawLines+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%eax
add    $0x1,%ebp
and    $0x1ff,%ebp
cmp    %ebx,%ebp
je     115b <drawLines+0x2b>
test   %eax,%eax
jne    11a0 <drawLines+0x70>
mov    %ebp,%eax
lea    (%rax,%rax,2),%rax
lea    (%r14,%rax,4),%rdi
call   1040 <glVertex3fv@plt>
mov    $0x4,%eax
jmp    11a0 <drawLines+0x70>

LLVM IR (-O0):
@GL_LINE_STRIP = global i32 0
define void @drawLines(i32 %0, [3 x float]* %1) {
%3 = alloca i32
%4 = alloca [3 x float]*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store [3 x float]* %1, [3 x float]** %4
%7 = load i32, i32* %3
%8 = add nsw i32 %7, 1
%9 = and i32 %8, 511
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = srem i32 %10, 4
%12 = sub nsw i32 4, %11
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 4
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 0, i32* %6
br label %16
16: ; preds = %15, %2
%17 = load i32, i32* @GL_LINE_STRIP
%18 = call i32 @glBegin(i32 %17)
br label %19
19: ; preds = %33, %16
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %39
23: ; preds = %19
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load [3 x float]*, [3 x float]** %4
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [3 x float], [3 x float]* %27, i64 %29
%31 = getelementptr inbounds [3 x float], [3 x float]* %30, i64 0, i64 0
%32 = call i32 @glVertex3fv(float* %31)
store i32 4, i32* %6
br label %33
33: ; preds = %26, %23
%34 = load i32, i32* %6
%35 = add nsw i32 %34, -1
store i32 %35, i32* %6
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
%38 = and i32 %37, 511
store i32 %38, i32* %5
br label %19
39: ; preds = %19
%40 = load [3 x float]*, [3 x float]** %4
%41 = load i32, i32* %3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [3 x float], [3 x float]* %40, i64 %42
%44 = getelementptr inbounds [3 x float], [3 x float]* %43, i64 0, i64 0
%45 = call i32 @glVertex3fv(float* %44)
%46 = call i32 (...) @glEnd()
ret void
}

LLVM IR (-O2):
@GL_LINE_STRIP = global i32 0
define void @drawLines(i32 %0, [3 x float]* %1) {
%3 = add nsw i32 %0, 1
%4 = and i32 %3, 3
%5 = load i32, i32* @GL_LINE_STRIP
%6 = tail call i32 @glBegin(i32 %5)
%7 = and i32 %3, 511
%8 = icmp eq i32 %7, %0
br i1 %8, label %27, label %9
9: ; preds = %2
%10 = icmp eq i32 %4, 0
%11 = sub nuw nsw i32 4, %4
%12 = select i1 %10, i32 0, i32 %11
br label %13
13: ; preds = %9, %21
%14 = phi i32 [ %25, %21 ], [ %7, %9 ]
%15 = phi i32 [ %23, %21 ], [ %12, %9 ]
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = zext i32 %14 to i64
%19 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 %18, i64 0
%20 = tail call i32 @glVertex3fv(float* %19)
br label %21
21: ; preds = %17, %13
%22 = phi i32 [ 4, %17 ], [ %15, %13 ]
%23 = add nsw i32 %22, -1
%24 = add nuw nsw i32 %14, 1
%25 = and i32 %24, 511
%26 = icmp eq i32 %25, %0
br i1 %26, label %27, label %13
27: ; preds = %21, %2
%28 = sext i32 %0 to i64
%29 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 %28, i64 0
%30 = tail call i32 @glVertex3fv(float* %29)
%31 = tail call i32 (...) @glEnd()
ret void
}