// File: 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:
subq $0x78, %rsp
movl %edi, 0x74(%rsp)
movq %rsi, 0x68(%rsp)
movl $0x0, 0x20(%rsp)
leaq 0x780a4(%rip), %rax     # 0x1fa390
cmpb $0x0, 0x1c(%rax)
jne 0x182307
leaq 0x1b5d9(%rip), %rdi     # 0x19d8d2
leaq 0x2c96f(%rip), %rsi     # 0x1aec6f
movb $0x0, %al
callq 0x17de70
movq $0x0, 0x60(%rsp)
movq 0x68(%rsp), %rax
movl $0x0, (%rax)
movl 0x74(%rsp), %eax
movl %eax, 0x8(%rsp)
subl $0x80, %eax
je 0x18233d
jmp 0x18232c
movl 0x8(%rsp), %eax
subl $0x1000, %eax           # imm = 0x1000
jne 0x1824fd
jmp 0x18233d
movl $0x2, 0x30(%rsp)
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
movl 0x74(%rsp), %eax
movl %eax, 0x4(%rsp)
subl $0x80, %eax
je 0x18238d
jmp 0x18235e
movl 0x4(%rsp), %eax
subl $0x1000, %eax           # imm = 0x1000
jne 0x1823cd
jmp 0x18236b
movl $0x7, 0x38(%rsp)
movl $0x1, 0x3c(%rsp)
movl $0x0, 0x40(%rsp)
movl $0x7, 0x20(%rsp)
jmp 0x1823cd
movl $0x7, 0x38(%rsp)
movl $0xffffffff, 0x3c(%rsp) # imm = 0xFFFFFFFF
movl $0x186a0, 0x40(%rsp)    # imm = 0x186A0
movl $0x1, 0x44(%rsp)
movl $0x186a1, 0x48(%rsp)    # imm = 0x186A1
movl $0x1, 0x4c(%rsp)
movl $0x0, 0x50(%rsp)
movl $0x186a1, 0x20(%rsp)    # imm = 0x186A1
leaq 0x7da5c(%rip), %rax     # 0x1ffe30
movq (%rax), %rdi
leaq 0x7da52(%rip), %rax     # 0x1ffe30
movl 0x8(%rax), %esi
leaq 0x30(%rsp), %rdx
leaq 0x24(%rsp), %rcx
callq 0x22e60
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
je 0x1824fb
movslq 0x24(%rsp), %rdi
shlq $0x2, %rdi
callq 0x22df0
movq %rax, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
movl 0x10(%rsp), %eax
cmpl 0x24(%rsp), %eax
jge 0x182495
leaq 0x7d9fb(%rip), %rax     # 0x1ffe30
movq (%rax), %rdi
movq 0x28(%rsp), %rax
movslq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
movl 0x20(%rsp), %edx
leaq 0xc(%rsp), %rcx
callq 0x222b0
movl 0xc(%rsp), %eax
cmpl 0x14(%rsp), %eax
jle 0x182486
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rax
movq 0x68(%rsp), %rcx
movslq (%rcx), %rcx
movl %edx, (%rax,%rcx,4)
movl 0xc(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x68(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x182488
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x182424
movq 0x68(%rsp), %rax
movslq (%rax), %rdi
shlq $0x2, %rdi
callq 0x22df0
movq %rax, 0x60(%rsp)
movl $0x0, 0x10(%rsp)
movl 0x10(%rsp), %eax
movq 0x68(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x1824e7
movq 0x18(%rsp), %rax
movslq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x60(%rsp), %rax
movslq 0x10(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x1824b3
movq 0x18(%rsp), %rdi
callq 0x22c30
movq 0x28(%rsp), %rdi
callq 0x22d60
jmp 0x1824ff
jmp 0x1824ff
movq 0x60(%rsp), %rax
addq $0x78, %rsp
retq
nopl (%rax)