#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 size_t GLint;
typedef double GLfloat;

/* Variables and functions */
#define GL_LINE_RESET_TOKEN 132
#define GL_LINE_TOKEN 131
#define GL_PASS_THROUGH_TOKEN 130
#define GL_POINT_TOKEN 129
#define GL_POLYGON_TOKEN 128
int /*<<< orphan*/ print3DcolorVertex(size_t, size_t *, double *);
int /*<<< orphan*/ printf(char *, ...);
void printBuffer(GLint size, GLfloat *buffer) {
  GLint count;
  int token, nvertices;
  count = size;
  while (count) {
    token = buffer[size - count];
    count--;
    switch (token) {
    case GL_PASS_THROUGH_TOKEN:
      printf("GL_PASS_THROUGH_TOKEN\n");
      printf("  %4.2f\n", buffer[size - count]);
      count--;
      break;
    case GL_POINT_TOKEN:
      printf("GL_POINT_TOKEN\n");
      print3DcolorVertex(size, &count, buffer);
      break;
    case GL_LINE_TOKEN:
      printf("GL_LINE_TOKEN\n");
      print3DcolorVertex(size, &count, buffer);
      print3DcolorVertex(size, &count, buffer);
      break;
    case GL_LINE_RESET_TOKEN:
      printf("GL_LINE_RESET_TOKEN\n");
      print3DcolorVertex(size, &count, buffer);
      print3DcolorVertex(size, &count, buffer);
      break;
    case GL_POLYGON_TOKEN:
      printf("GL_POLYGON_TOKEN\n");
      nvertices = buffer[size - count];
      count--;
      for (; nvertices > 0; nvertices--) {
        print3DcolorVertex(size, &count, buffer);
      }
    }
  }
}


x86 assembly (clang, -O0):
<printBuffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12bc <printBuffer+0x19c>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
cvttsd2si (%rax,%rcx,8),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x4,%eax
ja     12b7 <printBuffer+0x197>
mov    -0x28(%rbp),%rax
lea    0xe7a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe76(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    12b7 <printBuffer+0x197>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rsi
call   1040 <print3DcolorVertex@plt>
jmp    12b7 <printBuffer+0x197>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rsi
call   1040 <print3DcolorVertex@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rsi
call   1040 <print3DcolorVertex@plt>
jmp    12b7 <printBuffer+0x197>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rsi
call   1040 <print3DcolorVertex@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rsi
call   1040 <print3DcolorVertex@plt>
jmp    12b7 <printBuffer+0x197>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    -0x18(%rbp),%rcx
cvttsd2si (%rax,%rcx,8),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    12b2 <printBuffer+0x192>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rsi
call   1040 <print3DcolorVertex@plt>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1289 <printBuffer+0x169>
jmp    12b7 <printBuffer+0x197>
jmp    1138 <printBuffer+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printBuffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     125e <printBuffer+0x12e>
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeaf(%rip),%r15
mov    %rsp,%r12
lea    0xed3(%rip),%rbp
mov    %rdi,%rax
jmp    11a9 <printBuffer+0x79>
lea    0xef8(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rax
sub    (%rsp),%rax
movsd  (%r14,%rax,8),%xmm0
lea    0xe94(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    (%rsp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %rax,%rax
je     125e <printBuffer+0x12e>
mov    %rbx,%rcx
sub    %rax,%rcx
cvttsd2si (%r14,%rcx,8),%ecx
add    $0xffffffffffffffff,%rax
mov    %rax,(%rsp)
add    $0xffffff80,%ecx
cmp    $0x4,%ecx
ja     11a0 <printBuffer+0x70>
movslq (%r15,%rcx,4),%rax
add    %r15,%rax
jmp    *%rax
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%rax
mov    %rbx,%rcx
sub    %rax,%rcx
cvttsd2si (%r14,%rcx,8),%r13d
add    $0xffffffffffffffff,%rax
mov    %rax,(%rsp)
test   %r13d,%r13d
jle    11a0 <printBuffer+0x70>
add    $0x1,%r13d
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1050 <print3DcolorVertex@plt>
add    $0xffffffff,%r13d
cmp    $0x1,%r13d
ja     1200 <printBuffer+0xd0>
jmp    1255 <printBuffer+0x125>
lea    0xe2f(%rip),%rdi
call   1030 <puts@plt>
jmp    1247 <printBuffer+0x117>
lea    0xe13(%rip),%rdi
jmp    1234 <printBuffer+0x104>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1050 <print3DcolorVertex@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1050 <print3DcolorVertex@plt>
mov    (%rsp),%rax
jmp    11a0 <printBuffer+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"GL_PASS_THROUGH_TOKEN\0A\00"
@.str.1 = [9 x i8] c" %4.2f\0A\00"
@.str.2 = [16 x i8] c"GL_POINT_TOKEN\0A\00"
@.str.3 = [15 x i8] c"GL_LINE_TOKEN\0A\00"
@.str.4 = [21 x i8] c"GL_LINE_RESET_TOKEN\0A\00"
@.str.5 = [18 x i8] c"GL_POLYGON_TOKEN\0A\00"
define void @printBuffer(i64 %0, double* %1) {
%3 = alloca i64
%4 = alloca double*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i64 %0, i64* %3
store double* %1, double** %4
%8 = load i64, i64* %3
store i64 %8, i64* %5
br label %9
9: ; preds = %77, %2
%10 = load i64, i64* %5
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %78
12: ; preds = %9
%13 = load double*, double** %4
%14 = load i64, i64* %3
%15 = load i64, i64* %5
%16 = sub i64 %14, %15
%17 = getelementptr inbounds double, double* %13, i64 %16
%18 = load double, double* %17
%19 = fptosi double %18 to i32
store i32 %19, i32* %6
%20 = load i64, i64* %5
%21 = add i64 %20, -1
store i64 %21, i64* %5
%22 = load i32, i32* %6
switch i32 %22, label %77 [
i32 130, label %23
i32 129, label %34
i32 131, label %39
i32 132, label %47
i32 128, label %55
]
23: ; preds = %12
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%25 = load double*, double** %4
%26 = load i64, i64* %3
%27 = load i64, i64* %5
%28 = sub i64 %26, %27
%29 = getelementptr inbounds double, double* %25, i64 %28
%30 = load double, double* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %30)
%32 = load i64, i64* %5
%33 = add i64 %32, -1
store i64 %33, i64* %5
br label %77
34: ; preds = %12
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%36 = load i64, i64* %3
%37 = load double*, double** %4
%38 = call i32 @print3DcolorVertex(i64 %36, i64* %5, double* %37)
br label %77
39: ; preds = %12
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%41 = load i64, i64* %3
%42 = load double*, double** %4
%43 = call i32 @print3DcolorVertex(i64 %41, i64* %5, double* %42)
%44 = load i64, i64* %3
%45 = load double*, double** %4
%46 = call i32 @print3DcolorVertex(i64 %44, i64* %5, double* %45)
br label %77
47: ; preds = %12
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%49 = load i64, i64* %3
%50 = load double*, double** %4
%51 = call i32 @print3DcolorVertex(i64 %49, i64* %5, double* %50)
%52 = load i64, i64* %3
%53 = load double*, double** %4
%54 = call i32 @print3DcolorVertex(i64 %52, i64* %5, double* %53)
br label %77
55: ; preds = %12
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%57 = load double*, double** %4
%58 = load i64, i64* %3
%59 = load i64, i64* %5
%60 = sub i64 %58, %59
%61 = getelementptr inbounds double, double* %57, i64 %60
%62 = load double, double* %61
%63 = fptosi double %62 to i32
store i32 %63, i32* %7
%64 = load i64, i64* %5
%65 = add i64 %64, -1
store i64 %65, i64* %5
br label %66
66: ; preds = %73, %55
%67 = load i32, i32* %7
%68 = icmp sgt i32 %67, 0
br i1 %68, label %69, label %76
69: ; preds = %66
%70 = load i64, i64* %3
%71 = load double*, double** %4
%72 = call i32 @print3DcolorVertex(i64 %70, i64* %5, double* %71)
br label %73
73: ; preds = %69
%74 = load i32, i32* %7
%75 = add nsw i32 %74, -1
store i32 %75, i32* %7
br label %66
76: ; preds = %66
br label %77
77: ; preds = %76, %12, %47, %39, %34, %23
br label %9
78: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c" %4.2f\0A\00"
@str = [17 x i8] c"GL_POLYGON_TOKEN\00"
@str.6 = [20 x i8] c"GL_LINE_RESET_TOKEN\00"
@str.7 = [14 x i8] c"GL_LINE_TOKEN\00"
@str.8 = [15 x i8] c"GL_POINT_TOKEN\00"
@str.9 = [22 x i8] c"GL_PASS_THROUGH_TOKEN\00"
define void @printBuffer(i64 %0, double* %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = icmp eq i64 %0, 0
br i1 %5, label %51, label %6
6: ; preds = %2, %48
%7 = phi i64 [ %49, %48 ], [ %0, %2 ]
%8 = sub i64 %0, %7
%9 = getelementptr inbounds double, double* %1, i64 %8
%10 = load double, double* %9
%11 = fptosi double %10 to i32
%12 = add i64 %7, -1
store i64 %12, i64* %3
switch i32 %11, label %48 [
i32 130, label %13
i32 129, label %22
i32 131, label %24
i32 132, label %27
i32 128, label %30
]
13: ; preds = %6
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0))
%15 = load i64, i64* %3
%16 = sub i64 %0, %15
%17 = getelementptr inbounds double, double* %1, i64 %16
%18 = load double, double* %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %18)
%20 = load i64, i64* %3
%21 = add i64 %20, -1
store i64 %21, i64* %3
br label %48
22: ; preds = %6
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0))
br label %44
24: ; preds = %6
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.7, i64 0, i64 0))
%26 = call i32 @print3DcolorVertex(i64 %0, i64* %3, double* %1)
br label %44
27: ; preds = %6
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.6, i64 0, i64 0))
%29 = call i32 @print3DcolorVertex(i64 %0, i64* %3, double* %1)
br label %44
30: ; preds = %6
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%32 = load i64, i64* %3
%33 = sub i64 %0, %32
%34 = getelementptr inbounds double, double* %1, i64 %33
%35 = load double, double* %34
%36 = fptosi double %35 to i32
%37 = add i64 %32, -1
store i64 %37, i64* %3
%38 = icmp sgt i32 %36, 0
br i1 %38, label %39, label %48
39: ; preds = %30, %39
%40 = phi i32 [ %42, %39 ], [ %36, %30 ]
%41 = call i32 @print3DcolorVertex(i64 %0, i64* %3, double* %1)
%42 = add nsw i32 %40, -1
%43 = icmp ugt i32 %40, 1
br i1 %43, label %39, label %46
44: ; preds = %27, %24, %22
%45 = call i32 @print3DcolorVertex(i64 %0, i64* %3, double* %1)
br label %46
46: ; preds = %39, %44
%47 = load i64, i64* %3
br label %48
48: ; preds = %46, %30, %6, %13
%49 = phi i64 [ %47, %46 ], [ %37, %30 ], [ %12, %6 ], [ %21, %13 ]
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %6
51: ; preds = %48, %2
ret void
}