// File: /workspace/github_c_makefile_star2_O1/Ihsoh[P]ilang/compiler/frontend/irgen_llvmir.c
// Function: ir_constexpr
static void _ir_constexpr(
	IRGeneratorLlvmirContext *ctx,
	ResizableString *rstr_type,
	ResizableString *rstr_val,
	ParserASTNode *node_constexpr
) {
	assert(ctx);
	assert(rstr_val);
	assert(node_constexpr);
	assert(FE_EXPR_AST_NODE_GET_CONSTANT(node_constexpr));

	if (rstr_type != NULL) {
		_ir_type(ctx, rstr_type, FE_EXPR_AST_NODE_GET_TYPE_NODE(node_constexpr));
	}

	switch (FE_EXPR_AST_NODE_GET_CONSTANT_TYPE(node_constexpr)) {
		case FE_TYPE_CHAR: {
			char str[128];
			snprintf(
				str, sizeof(str), "%d",
				FE_EXPR_AST_NODE_GET_CONSTEXPR_RESULT_CHAR_VAL(node_constexpr)
			);
			rstr_append_with_cstr(rstr_val, str);
			break;
		}
		case FE_TYPE_INT8: {
			char str[128];
			snprintf(
				str, sizeof(str), "%d",
				FE_EXPR_AST_NODE_GET_CONSTEXPR_RESULT_INT8_VAL(node_constexpr)
			);
			rstr_append_with_cstr(rstr_val, str);
			break;
		}
		case FE_TYPE_INT16: {
			char str[128];
			snprintf(
				str, sizeof(str), "%d",
				FE_EXPR_AST_NODE_GET_CONSTEXPR_RESULT_INT16_VAL(node_constexpr)
			);
			rstr_append_with_cstr(rstr_val, str);
			break;
		}
		case FE_TYPE_INT32: {
			char str[128];
			snprintf(
				str, sizeof(str), "%d",
				FE_EXPR_AST_NODE_GET_CONSTEXPR_RESULT_INT32_VAL(node_constexpr)
			);
			rstr_append_with_cstr(rstr_val, str);
			break;
		}
		case FE_TYPE_INT64: {
			char str[128];
			snprintf(
				str, sizeof(str), "%lld",
				FE_EXPR_AST_NODE_GET_CONSTEXPR_RESULT_INT64_VAL(node_constexpr)
			);
			rstr_append_with_cstr(rstr_val, str);
			break;
		}
		case FE_TYPE_UINT8: {
			char str[128];
			snprintf(
				str, sizeof(str), "%u",
				FE_EXPR_AST_NODE_GET_CONSTEXPR_RESULT_UINT8_VAL(node_constexpr)
			);
			rstr_append_with_cstr(rstr_val, str);
			break;
		}
		case FE_TYPE_UINT16: {
			char str[128];
			snprintf(
				str, sizeof(str), "%u",
				FE_EXPR_AST_NODE_GET_CONSTEXPR_RESULT_UINT16_VAL(node_constexpr)
			);
			rstr_append_with_cstr(rstr_val, str);
			break;
		}
		case FE_TYPE_UINT32: {
			char str[128];
			snprintf(
				str, sizeof(str), "%u",
				FE_EXPR_AST_NODE_GET_CONSTEXPR_RESULT_UINT32_VAL(node_constexpr)
			);
			rstr_append_with_cstr(rstr_val, str);
			break;
		}
		case FE_TYPE_UINT64: {
			char str[128];
			snprintf(
				str, sizeof(str), "%llu",
				FE_EXPR_AST_NODE_GET_CONSTEXPR_RESULT_UINT64_VAL(node_constexpr)
			);
			rstr_append_with_cstr(rstr_val, str);
			break;
		}
		case FE_TYPE_FLOAT: {
			char str[128];
			double val = FE_EXPR_AST_NODE_GET_CONSTEXPR_RESULT_FLOAT_VAL(node_constexpr);
			snprintf(
				str, sizeof(str), "0x%llX",
				*(uint64_t *)&val
			);
			rstr_append_with_cstr(rstr_val, str);
			break;
		}
		case FE_TYPE_DOUBLE: {
			char str[128];
			double val = FE_EXPR_AST_NODE_GET_CONSTEXPR_RESULT_DOUBLE_VAL(node_constexpr);
			snprintf(
				str, sizeof(str), "0x%llX",
				*(uint64_t *)&val
			);
			rstr_append_with_cstr(rstr_val, str);
			break;
		}
		case FE_TYPE_POINTER: {
			if (FE_EXPR_AST_NODE_GET_HAS_CONSTSTR(node_constexpr)) {
				FeParserConstexprString *conststr = FE_EXPR_AST_NODE_GET_CONSTSTR(node_constexpr);
				uint64_t ptr_val = FE_EXPR_AST_NODE_GET_CONSTEXPR_RESULT_POINTER_VAL(node_constexpr);

				ResizableString conststr_name;
				rstr_init(&conststr_name);

				int len = _new_string(ctx, &conststr_name, conststr->str, conststr->len);

				ResizableString target_type;
				rstr_init(&target_type);

				_ir_type(ctx, &target_type, FE_EXPR_AST_NODE_GET_TYPE_NODE(node_constexpr));

				char *offset_type = "";
				if (ctx->psrctx->arch == FE_ARCH_32) {
					offset_type = "i32";
				} else if (ctx->psrctx->arch == FE_ARCH_64) {
					offset_type = "i64";
				} else {
					assert(0);
				}

				if (ptr_val == 0) {
					rstr_appendf(
						rstr_val,
						"bitcast (i8* getelementptr inbounds ([%zu x i8], [%zu x i8]* %s, i32 0, %s 0) to %s)",
						len,
						len,
						RSTR_CSTR(&conststr_name),
						offset_type,
						RSTR_CSTR(&target_type)
					);
				} else {
					rstr_appendf(
						rstr_val,
						"bitcast (i8* getelementptr inbounds ([%zu x i8], [%zu x i8]* %s, i32 0, %s %u) to %s)",
						len,
						len,
						RSTR_CSTR(&conststr_name),
						offset_type,
						ptr_val,
						RSTR_CSTR(&target_type)
					);
				}

				rstr_free(&conststr_name);
				rstr_free(&target_type);
			} else {
				char *source_type = "";
				if (ctx->psrctx->arch == FE_ARCH_32) {
					source_type = "i32";
				} else if (ctx->psrctx->arch == FE_ARCH_64) {
					source_type = "i64";
				} else {
					assert(0);
				}

				ResizableString target_type;
				rstr_init(&target_type);
				_ir_type(ctx, &target_type, FE_EXPR_AST_NODE_GET_TYPE_NODE(node_constexpr));

				char str[128];
				snprintf(
					str, sizeof(str), "inttoptr (%s %llu to %s)",
					source_type,
					FE_EXPR_AST_NODE_GET_CONSTEXPR_RESULT_POINTER_VAL(node_constexpr),
					RSTR_CSTR(&target_type)
				);
				rstr_append_with_cstr(rstr_val, str);

				rstr_free(&target_type);
			}
			break;
		}
		default: {
			assert(0);
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
testq %rdx, %rdx
je 0x1abcf
movq %rcx, %r14
cmpb $0x0, 0x70(%rcx)
je 0x1abee
movq %rdx, %rbx
movq %rdi, %r15
testq %rsi, %rsi
je 0x1a869
movq 0x68(%r14), %rax
movq %rsi, %rdi
movq %rax, %rsi
callq 0x198ea
movzbl 0x71(%r14), %eax
decl %eax
cmpl $0xf, %eax
ja 0x1ac0d
leaq 0x2af2c(%rip), %rcx     # 0x457ac
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movsbl 0x88(%r14), %ecx
jmp 0x1aa83
cmpb $0x1, 0x72(%r14)
jne 0x1aace
movq %rbx, -0x40(%rbp)
movq 0x88(%r14), %rax
movq %rax, -0x38(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x7548
movq 0x78(%r14), %r12
testq %r12, %r12
je 0x1ac2c
movq 0x80(%r14), %rax
movq %rax, -0x30(%rbp)
movq 0x38(%r15), %r13
leaq 0x1(%r13), %rax
movq %rax, 0x38(%r15)
leaq 0x2b578(%rip), %rsi     # 0x45e5c
leaq -0x50(%rbp), %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x7b31
leaq -0xd0(%rbp), %rbx
movq %rbx, %rdi
callq 0x7548
movq (%r15), %rax
movq (%rax), %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq -0x30(%rbp), %rcx
callq 0x21abe
movslq 0x4(%rbx), %r12
movq 0x18(%r15), %rdi
leal 0x1(%r12), %ecx
leaq 0x2b53c(%rip), %rsi     # 0x45e66
movq %r13, %rdx
movl %ecx, -0x30(%rbp)
xorl %eax, %eax
callq 0x7b31
testq %r12, %r12
jle 0x1a9a6
callq 0x3180
movq %rax, %r13
xorl %ebx, %ebx
movslq -0xcc(%rbp), %rcx
movb $-0x1, %al
cmpq %rcx, %rbx
jge 0x1a96c
movq -0xc8(%rbp), %rax
testq %rax, %rax
leaq 0x29555(%rip), %rcx     # 0x43eba
cmoveq %rcx, %rax
movb (%rax,%rbx), %al
movq (%r13), %rcx
movsbq %al, %rdx
testb $0x40, 0x1(%rcx,%rdx,2)
jne 0x1a992
movsbl %al, %edx
movq 0x18(%r15), %rdi
leaq 0x2b514(%rip), %rsi     # 0x45e9d
xorl %eax, %eax
callq 0x7b31
jmp 0x1a99e
movq 0x18(%r15), %rdi
movsbl %al, %esi
callq 0x76cb
incq %rbx
cmpq %rbx, %r12
jne 0x1a946
movq 0x18(%r15), %rdi
leaq 0x2b4f2(%rip), %rsi     # 0x45ea3
callq 0x75cf
leaq -0xd0(%rbp), %rdi
callq 0x7a38
leaq -0xd0(%rbp), %r12
movq %r12, %rdi
callq 0x7548
movq 0x68(%r14), %rsi
movq %r12, %rdi
callq 0x198ea
movq (%r15), %rax
movl 0x30(%rax), %eax
cmpl $0x1, %eax
je 0x1ab53
cmpl $0x2, %eax
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %r11
jne 0x1ac6a
leaq 0x2b180(%rip), %r9      # 0x45b84
jmp 0x1ab62
cvtss2sd 0x88(%r14), %xmm0
movq %xmm0, %rcx
jmp 0x1aa20
movq 0x88(%r14), %rcx
leaq 0x2b315(%rip), %rdx     # 0x45d3c
jmp 0x1aa47
movq 0x88(%r14), %rcx
leaq 0x2a0de(%rip), %rdx     # 0x44b15
jmp 0x1aa47
movq 0x88(%r14), %rcx
leaq 0x2a0c6(%rip), %rdx     # 0x44b0d
leaq -0xd0(%rbp), %r14
movl $0x80, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x3090
jmp 0x1aab1
movzbl 0x88(%r14), %ecx
jmp 0x1aa94
movswl 0x88(%r14), %ecx
jmp 0x1aa83
movl 0x88(%r14), %ecx
jmp 0x1aa94
movl 0x88(%r14), %ecx
leaq 0x2b069(%rip), %rdx     # 0x45af3
jmp 0x1aa9b
movzwl 0x88(%r14), %ecx
leaq 0x2a077(%rip), %rdx     # 0x44b12
leaq -0xd0(%rbp), %r14
movl $0x80, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x3090
movq %rbx, %rdi
movq %r14, %rsi
callq 0x75cf
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %rax
movl 0x30(%rax), %eax
cmpl $0x1, %eax
je 0x1aaeb
cmpl $0x2, %eax
jne 0x1ac4b
leaq 0x2b09b(%rip), %r12     # 0x45b84
jmp 0x1aaf2
leaq 0x2b08e(%rip), %r12     # 0x45b80
leaq -0x50(%rbp), %r15
movq %r15, %rdi
callq 0x7548
movq 0x68(%r14), %rsi
movq %r15, %rdi
callq 0x198ea
movq 0x88(%r14), %r8
movq 0x8(%r15), %rax
testq %rax, %rax
leaq 0x2939b(%rip), %r9      # 0x43eba
cmovneq %rax, %r9
leaq 0x2b2c4(%rip), %rdx     # 0x45dee
leaq -0xd0(%rbp), %r14
movl $0x80, %esi
movq %r14, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x3090
movq %rbx, %rdi
movq %r14, %rsi
callq 0x75cf
movq %r15, %rdi
jmp 0x1abc5
leaq 0x2b026(%rip), %r9      # 0x45b80
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %r11
movl -0x30(%rbp), %ecx
movq -0x48(%rbp), %r8
testq %r8, %r8
leaq 0x29347(%rip), %rax     # 0x43eba
cmoveq %rax, %r8
movq -0xc8(%rbp), %r10
testq %r10, %r10
cmoveq %rax, %r10
testq %r11, %r11
je 0x1ab9b
leaq 0x2b207(%rip), %rsi     # 0x45d98
movl %ecx, %edx
xorl %eax, %eax
pushq %r10
pushq %r11
jmp 0x1abac
subq $0x8, %rsp
leaq 0x2b19d(%rip), %rsi     # 0x45d43
movl %ecx, %edx
xorl %eax, %eax
pushq %r10
callq 0x7b31
addq $0x10, %rsp
leaq -0x50(%rbp), %rdi
callq 0x7a38
leaq -0xd0(%rbp), %rdi
callq 0x7a38
jmp 0x1aabc
leaq 0x27ec2(%rip), %rdi     # 0x42a98
leaq 0x2ac97(%rip), %rsi     # 0x45874
leaq 0x2b0f2(%rip), %rcx     # 0x45cd6
movl $0x327, %edx            # imm = 0x327
callq 0x30a0
leaq 0x27e28(%rip), %rdi     # 0x42a1d
leaq 0x2ac78(%rip), %rsi     # 0x45874
leaq 0x2b0d3(%rip), %rcx     # 0x45cd6
movl $0x329, %edx            # imm = 0x329
callq 0x30a0
leaq 0x25770(%rip), %rdi     # 0x40384
leaq 0x2ac59(%rip), %rsi     # 0x45874
leaq 0x2b0b4(%rip), %rcx     # 0x45cd6
movl $0x3e2, %edx            # imm = 0x3E2
callq 0x30a0
leaq 0x25e88(%rip), %rdi     # 0x40abb
leaq 0x2ac3a(%rip), %rsi     # 0x45874
leaq 0x2b1c6(%rip), %rcx     # 0x45e07
movl $0x11d, %edx            # imm = 0x11D
callq 0x30a0
leaq 0x25732(%rip), %rdi     # 0x40384
leaq 0x2ac1b(%rip), %rsi     # 0x45874
leaq 0x2b076(%rip), %rcx     # 0x45cd6
movl $0x3cd, %edx            # imm = 0x3CD
callq 0x30a0
leaq 0x25713(%rip), %rdi     # 0x40384
leaq 0x2abfc(%rip), %rsi     # 0x45874
leaq 0x2b057(%rip), %rcx     # 0x45cd6
movl $0x3aa, %edx            # imm = 0x3AA
callq 0x30a0