// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/fglut/freeglut_window.c
// Function: fghCreateNewContext
static GLXContext fghCreateNewContext( SFG_Window* window )
{
  /* for color model calculation */
  int menu = ( window->IsMenu && !fgStructure.MenuContext );
  int index_mode = ( fgState.DisplayMode & GLUT_INDEX );

  /* "classic" context creation */
  Display *dpy = fgDisplay.Display;
  GLXFBConfig config = *(window->Window.FBConfig);
  int render_type = ( !menu && index_mode ) ? GLX_COLOR_INDEX_TYPE : GLX_RGBA_TYPE;
  GLXContext share_list = NULL;
  Bool direct = ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT );
  GLXContext context;

  /* new context creation */
  int attributes[9];
  CreateContextAttribsProc createContextAttribs;

  /* If nothing fancy has been required, simply use the old context creation GLX API entry */
  if ( fghIsLegacyContextRequested() )
  {
    context = glXCreateNewContext( dpy, config, render_type, share_list, direct );
    if ( context == NULL ) {
      fghContextCreationError();
    }
    return context;
  }

  /* color index mode is not available anymore with OpenGL 3.0 */
  if ( render_type == GLX_COLOR_INDEX_TYPE ) {
    fgWarning( "color index mode is deprecated, using RGBA mode" );
  }

  fghFillContextAttributes( attributes );

  createContextAttribs = (CreateContextAttribsProc) fghGetProcAddress( "glXCreateContextAttribsARB" );
  if ( createContextAttribs == NULL ) {
    fgError( "glXCreateContextAttribsARB not found" );
  }

  context = createContextAttribs( dpy, config, share_list, direct, attributes );
  if ( context == NULL ) {
    fghContextCreationError();
  }
  return context;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
testb %sil, %sil
sete %al
leaq 0x732f0(%rip), %rcx     # 0x146870
cmpq $0x0, 0x40(%rcx)
setne %cl
orb %al, %cl
leaq 0x6ec2f(%rip), %r12     # 0x1421c0
movl 0x18(%r12), %eax
leaq 0x73233(%rip), %rdx     # 0x1467d0
movq (%rdx), %r14
andb %cl, %al
xorl %ebp, %ebp
cmpl $0x0, 0x20(%r12)
setne %bpl
movdqu 0xbc(%r12), %xmm0
movd 0x26730(%rip), %xmm1    # 0xf9cf0
pcmpeqd %xmm0, %xmm1
movmskps %xmm1, %ecx
xorl $0xf, %ecx
je 0xd35f0
testb %al, %al
je 0xd360e
leaq 0x2778a(%rip), %rdi     # 0xfad61
xorl %eax, %eax
callq 0x22a74
movl 0xbc(%r12), %ecx
movl 0xc0(%r12), %edx
jmp 0xd361b
movzbl %al, %edx
orl $0x8014, %edx           # imm = 0x8014
movq %r14, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
movl %ebp, %r8d
callq 0x21c30
jmp 0xd36b7
movd %xmm0, %ecx
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %edx
movl %ecx, %esi
xorl $0x1, %esi
xorl %eax, %eax
orl %edx, %esi
je 0xd3642
movl $0x2091, (%rsp)         # imm = 0x2091
movl %ecx, 0x4(%rsp)
movl $0x2092, 0x8(%rsp)      # imm = 0x2092
movl %edx, 0xc(%rsp)
movl $0x4, %eax
movl 0xc4(%r12), %ecx
andl $0x3, %ecx
je 0xd365f
movl %eax, %edx
movl $0x2094, (%rsp,%rdx,4)  # imm = 0x2094
orl $0x2, %eax
movl %ecx, 0x4(%rsp,%rdx,4)
movl 0xc8(%r12), %ecx
andl $0x3, %ecx
je 0xd367c
movl %eax, %edx
movl $0x9126, (%rsp,%rdx,4)  # imm = 0x9126
addl $0x2, %eax
movl %ecx, 0x4(%rsp,%rdx,4)
movl %eax, %eax
movl $0x0, (%rsp,%rax,4)
leaq 0x27705(%rip), %rdi     # 0xfad91
callq 0xd40d4
movq %rax, %r15
testq %rax, %rax
jne 0xd36a7
leaq 0x2770c(%rip), %rdi     # 0xfadac
xorl %eax, %eax
callq 0xcfe73
movq %rsp, %r8
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movl %ebp, %ecx
callq *%r15
testq %rax, %rax
je 0xd36c1
movq %rax, %rbx
jmp 0xd36f1
movl 0xbc(%r12), %esi
movl 0xc0(%r12), %edx
movl 0xc4(%r12), %ecx
movl 0xc8(%r12), %r8d
leaq 0x276e9(%rip), %rdi     # 0xfadd1
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xcfe73
movq %rbx, %rax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq