// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/backend/asmgen_gas32.c
// Function: be_asmgen_gas32_new_context
ASMGeneratorGas32Context * be_asmgen_gas32_new_context(
	ParserContext *psrctx,
	FILE *out,
	int platform
) {
	assert(psrctx);
	assert(psrctx->ast);
	assert(out);
	assert(
		platform == BE_ASMGEN_PLATFORM_WINDOWS
			|| platform == BE_ASMGEN_PLATFORM_SYSTEM_V
			|| platform == BE_ASMGEN_PLATFORM_ISYSTEM
	);
	
	ASMGeneratorGas32Context *ctx = (ASMGeneratorGas32Context *)malloc(sizeof(ASMGeneratorGas32Context));
	if (ctx == NULL) {
		_error("cannot allocate memory for a new context!");
	}

	ctx->psrctx = psrctx;
	ctx->out = out;

	ctx->global = rstr_new();
	ctx->head = rstr_new();
	ctx->body = rstr_new();
	ctx->foot = rstr_new();
	ctx->local_var_defs = NULL;

	ctx->local_var_address_counter = 0;
	ctx->local_var_size = 0;

	rstr_init(ctx->global);
	rstr_init(ctx->head);
	rstr_init(ctx->body);
	rstr_init(ctx->foot);

	ctx->counter = 0;
	ctx->func_symbol = NULL;

	ctx->platform = platform;

	size_t reg_alloc_table_count = sizeof(ctx->_reg_alloc_table) / sizeof(ctx->_reg_alloc_table[0]);
	for (int i = 0; i < reg_alloc_table_count; i++) {
		ctx->_reg_alloc_table[i] = false;
	}

	return ctx;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0xf71c
jmp 0xf73b
leaq 0x66234(%rip), %rdi     # 0x75957
leaq 0x661ce(%rip), %rsi     # 0x758f8
movl $0x2cca, %edx           # imm = 0x2CCA
leaq 0x6626b(%rip), %rcx     # 0x759a1
callq 0x30a0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xf748
jmp 0xf767
leaq 0x66214(%rip), %rdi     # 0x75963
leaq 0x661a2(%rip), %rsi     # 0x758f8
movl $0x2ccb, %edx           # imm = 0x2CCB
leaq 0x6623f(%rip), %rcx     # 0x759a1
callq 0x30a0
cmpq $0x0, -0x10(%rbp)
je 0xf770
jmp 0xf78f
leaq 0x66226(%rip), %rdi     # 0x7599d
leaq 0x6617a(%rip), %rsi     # 0x758f8
movl $0x2ccc, %edx           # imm = 0x2CCC
leaq 0x66217(%rip), %rcx     # 0x759a1
callq 0x30a0
cmpl $0x1, -0x14(%rbp)
je 0xf7a1
cmpl $0x2, -0x14(%rbp)
je 0xf7a1
cmpl $0x3, -0x14(%rbp)
jne 0xf7a3
jmp 0xf7c2
leaq 0x6624b(%rip), %rdi     # 0x759f5
leaq 0x66147(%rip), %rsi     # 0x758f8
movl $0x2cd1, %edx           # imm = 0x2CD1
leaq 0x661e4(%rip), %rcx     # 0x759a1
callq 0x30a0
movl $0x68, %edi
callq 0x3120
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xf7e3
leaq 0x66293(%rip), %rdi     # 0x75a71
callq 0xf8f0
movq -0x8(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
callq 0x91e0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
callq 0x91e0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
callq 0x91e0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
callq 0x91e0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x8c90
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x8c90
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x8c90
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x8c90
movq -0x20(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x58(%rax)
movl -0x14(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x60(%rax)
movq $0x4, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movslq -0x2c(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0xf8e5
movq -0x20(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb $0x0, 0x64(%rax,%rcx)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xf8c3
movq -0x20(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nop