// File: Ciaxur[P]yagb-emu/include/imgui/backends/imgui_impl_opengl3.cpp
// Function: ImGui_ImplOpenGL3_SetupRenderState(ImDrawData*, int, int, unsigned int)
static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height, GLuint vertex_array_object)
{
    // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill
    glEnable(GL_BLEND);
    glBlendEquation(GL_FUNC_ADD);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDisable(GL_CULL_FACE);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_STENCIL_TEST);
    glEnable(GL_SCISSOR_TEST);
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
    if (g_GlVersion >= 310)
        glDisable(GL_PRIMITIVE_RESTART);
#endif
#ifdef GL_POLYGON_MODE
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
#endif

    // Support for GL 4.5 rarely used glClipControl(GL_UPPER_LEFT)
#if defined(GL_CLIP_ORIGIN) && !defined(__APPLE__)
    bool clip_origin_lower_left = true;
    GLenum current_clip_origin = 0; glGetIntegerv(GL_CLIP_ORIGIN, (GLint*)&current_clip_origin);
    if (current_clip_origin == GL_UPPER_LEFT)
        clip_origin_lower_left = false;
#endif

    // Setup viewport, orthographic projection matrix
    // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
    glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
    float L = draw_data->DisplayPos.x;
    float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
    float T = draw_data->DisplayPos.y;
    float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
#if defined(GL_CLIP_ORIGIN) && !defined(__APPLE__)
    if (!clip_origin_lower_left) { float tmp = T; T = B; B = tmp; } // Swap top and bottom if origin is upper left
#endif
    const float ortho_projection[4][4] =
    {
        { 2.0f/(R-L),   0.0f,         0.0f,   0.0f },
        { 0.0f,         2.0f/(T-B),   0.0f,   0.0f },
        { 0.0f,         0.0f,        -1.0f,   0.0f },
        { (R+L)/(L-R),  (T+B)/(B-T),  0.0f,   1.0f },
    };
    glUseProgram(g_ShaderHandle);
    glUniform1i(g_AttribLocationTex, 0);
    glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);

#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
    if (g_GlVersion >= 330)
        glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise.
#endif

    (void)vertex_array_object;
#ifndef IMGUI_IMPL_OPENGL_ES2
    glBindVertexArray(vertex_array_object);
#endif

    // Bind vertex/index buffers and setup attributes for ImDrawVert
    glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle);
    glEnableVertexAttribArray(g_AttribLocationVtxPos);
    glEnableVertexAttribArray(g_AttribLocationVtxUV);
    glEnableVertexAttribArray(g_AttribLocationVtxColor);
    glVertexAttribPointer(g_AttribLocationVtxPos,   2, GL_FLOAT,         GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos));
    glVertexAttribPointer(g_AttribLocationVtxUV,    2, GL_FLOAT,         GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv));
    glVertexAttribPointer(g_AttribLocationVtxColor, 4, GL_UNSIGNED_BYTE, GL_TRUE,  sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl $0xbe2, %edi            # imm = 0xBE2
callq 0xd5a0
movl $0x8006, %edi           # imm = 0x8006
movq 0xa4355(%rip), %rax     # 0x20dfb0
callq *(%rax)
movl $0x302, %edi            # imm = 0x302
movl $0x303, %esi            # imm = 0x303
callq 0xda40
movl $0xb44, %edi            # imm = 0xB44
callq 0xd8c0
movl $0xb71, %edi            # imm = 0xB71
callq 0xd8c0
movl $0xb90, %edi            # imm = 0xB90
callq 0xd8c0
movl $0xc11, %edi            # imm = 0xC11
callq 0xd5a0
cmpl $0x136, 0xaffd2(%rip)   # imm = 0x136
jb 0x169caa
movl $0x8f9d, %edi           # imm = 0x8F9D
callq 0xd8c0
movl $0x408, %edi            # imm = 0x408
movl $0x1b02, %esi           # imm = 0x1B02
callq 0xd3f0
movb $0x1, -0x15(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x935c, %edi           # imm = 0x935C
leaq -0x1c(%rbp), %rsi
callq 0xd800
cmpl $0x8ca2, -0x1c(%rbp)    # imm = 0x8CA2
jne 0x169cdf
movb $0x0, -0x15(%rbp)
movl -0xc(%rbp), %edx
movl -0x10(%rbp), %ecx
xorl %esi, %esi
movl %esi, %edi
callq 0xd440
movq -0x8(%rbp), %rax
movss 0x1c(%rax), %xmm0
movss %xmm0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movss 0x1c(%rax), %xmm0
movq -0x8(%rbp), %rax
addss 0x24(%rax), %xmm0
movss %xmm0, -0x24(%rbp)
movq -0x8(%rbp), %rax
movss 0x20(%rax), %xmm0
movss %xmm0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movss 0x20(%rax), %xmm0
movq -0x8(%rbp), %rax
addss 0x28(%rax), %xmm0
movss %xmm0, -0x2c(%rbp)
testb $0x1, -0x15(%rbp)
jne 0x169d5c
movss -0x28(%rbp), %xmm0
movss %xmm0, -0x30(%rbp)
movss -0x2c(%rbp), %xmm0
movss %xmm0, -0x28(%rbp)
movss -0x30(%rbp), %xmm0
movss %xmm0, -0x2c(%rbp)
movss -0x24(%rbp), %xmm1
subss -0x20(%rbp), %xmm1
movss 0x825e(%rip), %xmm0     # 0x171fcc
divss %xmm1, %xmm0
movss %xmm0, -0x70(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x6c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x68(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x64(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x60(%rbp)
movss -0x28(%rbp), %xmm1
subss -0x2c(%rbp), %xmm1
movss 0x8223(%rip), %xmm0     # 0x171fcc
divss %xmm1, %xmm0
movss %xmm0, -0x5c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x58(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x54(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x50(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x4c(%rbp)
movss 0x81a6(%rip), %xmm0     # 0x171f80
movss %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x44(%rbp)
movss -0x24(%rbp), %xmm0
addss -0x20(%rbp), %xmm0
movss -0x20(%rbp), %xmm1
subss -0x24(%rbp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x40(%rbp)
movss -0x28(%rbp), %xmm0
addss -0x2c(%rbp), %xmm0
movss -0x2c(%rbp), %xmm1
subss -0x28(%rbp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x3c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
movss 0x6e0b(%rip), %xmm0     # 0x170c3c
movss %xmm0, -0x34(%rbp)
movq 0xa41a3(%rip), %rax     # 0x20dfe0
movq (%rax), %rax
movl 0xafe5a(%rip), %edi     # 0x219ca0
callq *%rax
movq 0xa40f1(%rip), %rax     # 0x20df40
movq (%rax), %rax
movl 0xafe58(%rip), %edi     # 0x219cb0
xorl %esi, %esi
callq *%rax
movq 0xa407d(%rip), %rax     # 0x20dee0
movq (%rax), %rax
movl 0xafe48(%rip), %edi     # 0x219cb4
leaq -0x70(%rbp), %rcx
movl $0x1, %esi
xorl %edx, %edx
callq *%rax
cmpl $0x14a, 0xafded(%rip)   # imm = 0x14A
jb 0x169e92
xorl %esi, %esi
movq 0xa40f2(%rip), %rax     # 0x20df80
movl %esi, %edi
callq *(%rax)
movq 0xa4137(%rip), %rax     # 0x20dfd0
movq (%rax), %rax
movl -0x14(%rbp), %edi
callq *%rax
movq 0xa3ff8(%rip), %rax     # 0x20dea0
movq (%rax), %rax
movl 0xafe13(%rip), %esi     # 0x219cc4
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
movq 0xa3fe1(%rip), %rax     # 0x20dea0
movq (%rax), %rax
movl 0xafe00(%rip), %esi     # 0x219cc8
movl $0x8893, %edi           # imm = 0x8893
callq *%rax
movq 0xa40ca(%rip), %rax     # 0x20dfa0
movq (%rax), %rax
movl 0xafdd9(%rip), %edi     # 0x219cb8
callq *%rax
movq 0xa40b8(%rip), %rax     # 0x20dfa0
movq (%rax), %rax
movl 0xafdcb(%rip), %edi     # 0x219cbc
callq *%rax
movq 0xa40a6(%rip), %rax     # 0x20dfa0
movq (%rax), %rax
movl 0xafdbd(%rip), %edi     # 0x219cc0
callq *%rax
movq 0xa40b4(%rip), %rax     # 0x20dfc0
movq (%rax), %rax
movl 0xafda3(%rip), %edi     # 0x219cb8
movl $0x2, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl $0x14, %r8d
xorl %r9d, %r9d
callq *%rax
movq 0xa408d(%rip), %rax     # 0x20dfc0
movq (%rax), %rax
movl 0xafd80(%rip), %edi     # 0x219cbc
movl $0x2, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl $0x14, %r8d
movl $0x8, %r9d
callq *%rax
movq 0xa4063(%rip), %rax     # 0x20dfc0
movq (%rax), %rax
movl 0xafd5a(%rip), %edi     # 0x219cc0
movl $0x4, %esi
movl $0x1401, %edx           # imm = 0x1401
movl $0x1, %ecx
movl $0x14, %r8d
movl $0x10, %r9d
callq *%rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)