// File: /workspace/github_c_makefile_star2_O0/k0n10pl4tr[P]minimal_crafter/main.c
// Function: initWindow
void
initWindow()
{
	int glxMajor, glxMinor;
	int fbConfigCount;
	int glMajorVersion, glMinorVersion;
	XSetWindowAttributes swa;
	glXCreateContextAttribsARBProc contextLoader = NULL;
	GLXFBConfig* fbConfigs;
	XVisualInfo* vi;

	dpy = XOpenDisplay(NULL);
	if(!dpy) {
		printf("Could not init X11\n");
		exit(-1);
	}
	screen = DefaultScreen(dpy);

	glXQueryVersion(dpy, &glxMajor, &glxMinor);
	if(glxMinor < 3) {
		printf("Invalid GLX Version\n");
		exit(-3);
	}
	fbConfigs = glXChooseFBConfig(dpy, screen, visualAttribs, &fbConfigCount);
	
	printf("Found %d config count, selecting the first one, anyway\n", fbConfigCount);

	fbConfig = fbConfigs[0];
	XFree(fbConfigs);

	vi = glXGetVisualFromFBConfig(dpy, fbConfig);
	
	rootWindow = DefaultRootWindow(dpy);
	wmDeleteWindow = XInternAtom(dpy, "WM_DELETE_WINDOW", 0);

	swa.colormap   = XCreateColormap(dpy, rootWindow, vi->visual, AllocNone);
	swa.event_mask = KeyPressMask | KeyReleaseMask | StructureNotifyMask;

	windowWidth = 800;
	windowHeight = 600;
	
	window = XCreateWindow(dpy, rootWindow, 0, 0, windowWidth, windowHeight, 0, vi->depth, InputOutput, vi->visual, CWEventMask | CWColormap, &swa);
	XSetWMProtocols(dpy, window, &wmDeleteWindow, 1);

	XStoreName(dpy, window, "Hello");
	XMapWindow(dpy, window);
	
	contextLoader = (glXCreateContextAttribsARBProc)glXGetProcAddressARB((const unsigned char*)"glXCreateContextAttribsARB");
	
	glContext = contextLoader(dpy, fbConfig, 0, True, glxContextAttribs);
	glXMakeCurrent(dpy, window, glContext);

	if(!gladLoadGLLoader((GLADloadproc)glXGetProcAddress)) {
		printf("Could not read the opengl functions.\n");
		exit(-2);
	}
	
	glGetIntegerv(GL_MAJOR_VERSION, &glMajorVersion);
	glGetIntegerv(GL_MINOR_VERSION, &glMinorVersion);
	
	if(glMajorVersion < 3 && glMinorVersion < 3) {
		printf("Sorry, your OpenGL Version is not that is used.\n");
		printf("OpenGL version used: 3.3, your OpenGL version: %d.%d\n", glMajorVersion, glMinorVersion);
		printf("Shutting down\n");
		exit(-5);
	}

	printf("OpenGL Version: %d.%d\n", glMajorVersion, glMinorVersion);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq $0x0, -0x90(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x2180
movq %rax, 0xb67a(%rip)      # 0xda70
cmpq $0x0, 0xb672(%rip)      # 0xda70
jne 0x2418
leaq 0x6ca5(%rip), %rdi      # 0x90ac
movb $0x0, %al
callq 0x2060
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x20d0
movq 0xb651(%rip), %rax      # 0xda70
movl 0xe0(%rax), %eax
movl %eax, 0xb64d(%rip)      # 0xda78
movq 0xb63e(%rip), %rdi      # 0xda70
leaq -0x4(%rbp), %rsi
leaq -0x8(%rbp), %rdx
callq 0x2130
cmpl $0x3, -0x8(%rbp)
jge 0x245d
leaq 0x6c74(%rip), %rdi      # 0x90c0
movb $0x0, %al
callq 0x2060
movl $0xfffffffd, %edi       # imm = 0xFFFFFFFD
callq 0x20d0
movq 0xb60c(%rip), %rdi      # 0xda70
movl 0xb60e(%rip), %esi      # 0xda78
leaq 0xad0f(%rip), %rdx      # 0xd180
leaq -0xc(%rbp), %rcx
callq 0x20f0
movq %rax, -0x98(%rbp)
movl -0xc(%rbp), %esi
leaq 0x6c4a(%rip), %rdi      # 0x90d5
movb $0x0, %al
callq 0x2060
movq -0x98(%rbp), %rax
movq (%rax), %rax
movq %rax, 0xb5dd(%rip)      # 0xda80
movq -0x98(%rbp), %rdi
callq 0x2050
movq 0xb5ba(%rip), %rdi      # 0xda70
movq 0xb5c3(%rip), %rsi      # 0xda80
callq 0x21e0
movq %rax, -0xa0(%rbp)
movq 0xb5a0(%rip), %rax      # 0xda70
movq 0xe8(%rax), %rax
movq 0xb592(%rip), %rcx      # 0xda70
movslq 0xe0(%rcx), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, 0xb591(%rip)      # 0xda88
movq 0xb572(%rip), %rdi      # 0xda70
leaq 0x6c08(%rip), %rsi      # 0x910d
xorl %edx, %edx
callq 0x2260
movq %rax, 0xb57d(%rip)      # 0xda90
movq 0xb556(%rip), %rdi      # 0xda70
movq 0xb567(%rip), %rsi      # 0xda88
movq -0xa0(%rbp), %rax
movq (%rax), %rdx
xorl %ecx, %ecx
callq 0x2170
movq %rax, -0x28(%rbp)
movq $0x20003, -0x40(%rbp)   # imm = 0x20003
movl $0x320, 0xb550(%rip)    # imm = 0x320
movl $0x258, 0xb54a(%rip)    # imm = 0x258
movq 0xb517(%rip), %rdi      # 0xda70
movq 0xb528(%rip), %rsi      # 0xda88
movl 0xb531(%rip), %r8d      # 0xda98
movl 0xb52e(%rip), %r9d      # 0xda9c
movq -0xa0(%rbp), %rax
movl 0x14(%rax), %r11d
movq -0xa0(%rbp), %rax
movq (%rax), %r10
xorl %ecx, %ecx
leaq -0x88(%rbp), %rax
movl %ecx, %edx
movl $0x0, (%rsp)
movl %r11d, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq $0x2800, 0x20(%rsp)     # imm = 0x2800
movq %rax, 0x28(%rsp)
callq 0x2150
movq %rax, 0xb4df(%rip)      # 0xdaa0
movq 0xb4a8(%rip), %rdi      # 0xda70
movq 0xb4d1(%rip), %rsi      # 0xdaa0
leaq 0xb4ba(%rip), %rdx      # 0xda90
movl $0x1, %ecx
callq 0x2200
movq 0xb489(%rip), %rdi      # 0xda70
movq 0xb4b2(%rip), %rsi      # 0xdaa0
leaq 0x6b29(%rip), %rdx      # 0x911e
callq 0x2080
movq 0xb46f(%rip), %rdi      # 0xda70
movq 0xb498(%rip), %rsi      # 0xdaa0
callq 0x2220
leaq 0x6b10(%rip), %rdi      # 0x9124
callq 0x20e0
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq 0xb442(%rip), %rdi      # 0xda70
movq 0xb44b(%rip), %rsi      # 0xda80
xorl %ecx, %ecx
movl %ecx, %edx
movl $0x1, %ecx
leaq 0xab9b(%rip), %r8       # 0xd1e0
callq *%rax
movq %rax, 0xb45a(%rip)      # 0xdaa8
movq 0xb41b(%rip), %rdi      # 0xda70
movq 0xb444(%rip), %rsi      # 0xdaa0
movq 0xb445(%rip), %rdx      # 0xdaa8
callq 0x2040
movq 0xa981(%rip), %rdi      # 0xcff0
callq 0x32c0
cmpl $0x0, %eax
jne 0x2691
leaq 0x6abf(%rip), %rdi      # 0x913f
movb $0x0, %al
callq 0x2060
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
callq 0x20d0
movl $0x821b, %edi           # imm = 0x821B
leaq -0x10(%rbp), %rsi
leaq 0xb8ef(%rip), %rax      # 0xdf90
callq *(%rax)
movl $0x821c, %edi           # imm = 0x821C
leaq -0x14(%rbp), %rsi
leaq 0xb8dd(%rip), %rax      # 0xdf90
callq *(%rax)
cmpl $0x3, -0x10(%rbp)
jge 0x26fb
cmpl $0x3, -0x14(%rbp)
jge 0x26fb
leaq 0x6a9d(%rip), %rdi      # 0x9165
movb $0x0, %al
callq 0x2060
movl -0x10(%rbp), %esi
movl -0x14(%rbp), %edx
leaq 0x6aba(%rip), %rdi      # 0x9196
movb $0x0, %al
callq 0x2060
leaq 0x6ae2(%rip), %rdi      # 0x91cc
movb $0x0, %al
callq 0x2060
movl $0xfffffffb, %edi       # imm = 0xFFFFFFFB
callq 0x20d0
movl -0x10(%rbp), %esi
movl -0x14(%rbp), %edx
leaq 0x6ad3(%rip), %rdi      # 0x91db
movb $0x0, %al
callq 0x2060
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax,%rax)