// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpb $0x0, 0x170(%rdi)
sete %al
leaq 0x79655(%rip), %rcx     # 0x137890
cmpq $0x0, 0x40(%rcx)
setne %cl
orb %al, %cl
leaq 0x74f94(%rip), %r12     # 0x1331e0
movl 0x18(%r12), %eax
leaq 0x79598(%rip), %rdx     # 0x1377f0
movq (%rdx), %r14
movq 0x28(%rdi), %rdx
movq (%rdx), %r15
andb %cl, %al
xorl %ebx, %ebx
cmpl $0x0, 0x20(%r12)
setne %bl
movdqu 0xbc(%r12), %xmm0
movd 0x2671f(%rip), %xmm1    # 0xe49a0
pcmpeqd %xmm0, %xmm1
movmskps %xmm1, %ecx
xorl $0xf, %ecx
je 0xbe2b1
testb %al, %al
je 0xbe2cf
leaq 0x27739(%rip), %rdi     # 0xe59d1
xorl %eax, %eax
callq 0xbae63
movl 0xbc(%r12), %ecx
movl 0xc0(%r12), %edx
jmp 0xbe2dc
movzbl %al, %edx
orl $0x8014, %edx           # imm = 0x8014
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
movl %ebx, %r8d
callq 0x21c40
jmp 0xbe373
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 0xbe301
movl $0x2091, (%rsp)         # imm = 0x2091
movl %ecx, 0x4(%rsp)
movl $0x2092, 0x8(%rsp)      # imm = 0x2092
movl %edx, 0xc(%rsp)
pushq $0x4
popq %rax
movl 0xc4(%r12), %ecx
andl $0x3, %ecx
je 0xbe31e
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 0xbe33b
movl %eax, %edx
movl $0x9126, (%rsp,%rdx,4)  # imm = 0x9126
addl $0x2, %eax
movl %ecx, 0x4(%rsp,%rdx,4)
movl %eax, %eax
andl $0x0, (%rsp,%rax,4)
leaq 0x276b9(%rip), %rdi     # 0xe5a01
callq 0xbed58
movq %rax, %r12
testq %rax, %rax
jne 0xbe363
leaq 0x276c0(%rip), %rdi     # 0xe5a1c
xorl %eax, %eax
callq 0xbad73
movq %rsp, %r8
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
movl %ebx, %ecx
callq *%r12
testq %rax, %rax
jne 0xbe37f
callq 0xbed28
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq