// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x30, %rsp
cmpb $0x0, 0x170(%rdi)
sete %al
leaq 0x73408(%rip), %rcx     # 0x148870
cmpq $0x0, 0x40(%rcx)
setne %cl
orb %al, %cl
leaq 0x6ed47(%rip), %r13     # 0x1441c0
movl 0x18(%r13), %eax
leaq 0x7334c(%rip), %rdx     # 0x1487d0
movq (%rdx), %r14
movq 0x28(%rdi), %rdx
movq (%rdx), %r15
andb %cl, %al
xorl %ebx, %ebx
cmpl $0x0, 0x20(%r13)
setne %bl
movdqu 0xbc(%r13), %xmm0
pcmpeqd 0x267c5(%rip), %xmm0    # 0xfbc70
movmskps %xmm0, %ecx
xorl $0xf, %ecx
je 0xd5573
testb %al, %al
je 0xd54c9
leaq 0x2784f(%rip), %rdi     # 0xfcd11
xorl %eax, %eax
callq 0x22aab
movl 0xbc(%r13), %edx
movl 0xc0(%r13), %ecx
movl %edx, %esi
xorl $0x1, %esi
xorl %eax, %eax
orl %ecx, %esi
je 0xd54fe
movl $0x2091, (%rsp)         # imm = 0x2091
movl %edx, 0x4(%rsp)
movl $0x2092, 0x8(%rsp)      # imm = 0x2092
movl %ecx, 0xc(%rsp)
movl $0x4, %eax
movl 0xc4(%r13), %ecx
andl $0x3, %ecx
je 0xd551a
movl %eax, %edx
movl $0x2094, (%rsp,%rdx,4)  # imm = 0x2094
orl $0x2, %eax
movl %ecx, 0x4(%rsp,%rdx,4)
movl 0xc8(%r13), %ecx
andl $0x3, %ecx
je 0xd5536
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 0x277fb(%rip), %rdi     # 0xfcd41
callq 0xd5f7c
movq %rax, %r12
testq %rax, %rax
jne 0xd5561
leaq 0x27802(%rip), %rdi     # 0xfcd5c
xorl %eax, %eax
callq 0xd1cf7
movq %rsp, %r8
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
movl %ebx, %ecx
callq *%r12
jmp 0xd558c
movzbl %al, %edx
orl $0x8014, %edx           # imm = 0x8014
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
movl %ebx, %r8d
callq 0x21c40
movq %rax, %rbx
testq %rax, %rax
jne 0xd55be
movl 0xbc(%r13), %esi
movl 0xc0(%r13), %edx
movl 0xc4(%r13), %ecx
movl 0xc8(%r13), %r8d
leaq 0x277ca(%rip), %rdi     # 0xfcd81
xorl %eax, %eax
callq 0xd1cf7
movq %rbx, %rax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq