// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/fglut/freeglut_state.c
// Function: glutGetModeValues
int * FGAPIENTRY glutGetModeValues(GLenum eWhat, int * size)
{
  int * array;

#if TARGET_HOST_POSIX_X11
  int attributes[9];
  GLXFBConfig * fbconfigArray;  /*  Array of FBConfigs  */
  int fbconfigArraySize;        /*  Number of FBConfigs in the array  */
  int attribute_name = 0;
#endif

  FREEGLUT_EXIT_IF_NOT_INITIALISED("glutGetModeValues");

  array = NULL;
  *size = 0;

  switch (eWhat)
    {
#if TARGET_HOST_POSIX_X11
    case GLUT_AUX:
    case GLUT_MULTISAMPLE:

      attributes[0] = GLX_BUFFER_SIZE;
      attributes[1] = GLX_DONT_CARE;

      switch (eWhat)
        {
        case GLUT_AUX:
          /*
            FBConfigs are now sorted by increasing number of auxiliary
            buffers.  We want at least one buffer.
          */
          attributes[2] = GLX_AUX_BUFFERS;
          attributes[3] = 1;
          attributes[4] = None;

          attribute_name = GLX_AUX_BUFFERS;

          break;


        case GLUT_MULTISAMPLE:
          attributes[2] = GLX_AUX_BUFFERS;
          attributes[3] = GLX_DONT_CARE;
          attributes[4] = GLX_SAMPLE_BUFFERS;
          attributes[5] = 1;
          /*
            FBConfigs are now sorted by increasing number of samples per
            pixel.  We want at least one sample.
          */
          attributes[6] = GLX_SAMPLES;
          attributes[7] = 1;
          attributes[8] = None;

          attribute_name = GLX_SAMPLES;

          break;
        }

      fbconfigArray = glXChooseFBConfig(fgDisplay.Display,
                                        fgDisplay.Screen,
                                        attributes,
                                        &fbconfigArraySize);

      if (fbconfigArray != NULL)
        {
          int * temp_array;
          int previous_value;
          int i;

          temp_array = malloc(sizeof(int) * fbconfigArraySize);
          previous_value = 0;

          for (i = 0; i < fbconfigArraySize; i++)
            {
              int value;

              glXGetFBConfigAttrib(fgDisplay.Display,
                                            fbconfigArray[i],
                                            attribute_name,
                                            &value);
              if (value > previous_value)
                {
                  temp_array[*size] = value;
                  previous_value = value;
                  (*size)++;
                }
            }

          array = malloc(sizeof(int) * (*size));
          for (i = 0; i < *size; i++)
            {
              array[i] = temp_array[i];
            }

          free(temp_array);
          XFree(fbconfigArray);
        }

      break;
#endif      

    default:
      break;
    }

  return array;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movl %edi, %ebp
leaq 0x75f0a(%rip), %rax     # 0x1331e0
cmpb $0x0, 0x1c(%rax)
jne 0xbd2f1
leaq 0x16f83(%rip), %rdi     # 0xd4266
leaq 0x283a5(%rip), %rsi     # 0xe568f
xorl %eax, %eax
callq 0xbad73
andl $0x0, (%r14)
xorl %ebx, %ebx
cmpl $0x1000, %ebp           # imm = 0x1000
je 0xbd30b
cmpl $0x80, %ebp
jne 0xbd43a
movabsq $-0xfffffffe, %rax      # imm = 0xFFFFFFFF00000002
movq %rax, 0x10(%rsp)
cmpl $0x1000, %ebp           # imm = 0x1000
je 0xbd34b
cmpl $0x80, %ebp
jne 0xbd368
leaq 0x30(%rsp), %rax
leaq 0x2c(%rsp), %rcx
leaq 0x28(%rsp), %rdx
movaps 0x28230(%rip), %xmm0    # 0xe5570
movups %xmm0, -0x10(%rdx)
movl $0x186a1, %ebx          # imm = 0x186A1
jmp 0xbd35d
leaq 0x20(%rsp), %rax
leaq 0x1c(%rsp), %rcx
leaq 0x18(%rsp), %rdx
pushq $0x7
popq %rbx
movl %ebx, (%rdx)
movl $0x1, (%rcx)
andl $0x0, (%rax)
leaq 0x7a481(%rip), %rax     # 0x1377f0
movq (%rax), %rdi
movl 0x8(%rax), %esi
leaq 0x10(%rsp), %rdx
movq %rsp, %rcx
callq 0x21cd0
xorl %ebp, %ebp
testq %rax, %rax
je 0xbd438
movq %rax, %r15
movq %r14, 0x8(%rsp)
movslq (%rsp), %r13
movq %r13, %rdi
shlq $0x2, %rdi
callq 0x21c70
movq %rax, %r12
xorl %r14d, %r14d
movslq %r13d, %rax
cmpq %rax, %r14
jge 0xbd3f0
leaq 0x7a436(%rip), %rax     # 0x1377f0
movq (%rax), %rdi
movq (%r15,%r14,8), %rsi
movl %ebx, %edx
leaq 0x4(%rsp), %rcx
callq 0x21290
movl 0x4(%rsp), %eax
cmpl %ebp, %eax
jle 0xbd3e7
movq 0x8(%rsp), %rdx
movslq (%rdx), %rcx
movl %eax, (%r12,%rcx,4)
incl %ecx
movl %ecx, (%rdx)
movl %eax, %ebp
incq %r14
movl (%rsp), %r13d
jmp 0xbd3ab
movq 0x8(%rsp), %rax
movslq (%rax), %r14
movq %r14, %rdi
shlq $0x2, %rdi
callq 0x21c70
movq %rax, %rbx
xorl %eax, %eax
testl %r14d, %r14d
movl $0x0, %ecx
cmovgl %r14d, %ecx
cmpq %rax, %rcx
je 0xbd426
movl (%r12,%rax,4), %edx
movl %edx, (%rbx,%rax,4)
incq %rax
jmp 0xbd415
movq %r12, %rdi
callq 0x21ad0
movq %r15, %rdi
callq 0x21bf0
jmp 0xbd43a
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq