// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/backend/asmgen_gas32.c
// Function: new_string
static int _new_string(
	ASMGeneratorGas32Context *ctx,
	ResizableString *name,
	const char *str,
	size_t len
) {
	assert(ctx);
	assert(str);

	// .section __TEXT,__cstring,cstring_literals
	// _STR.[X]
	// .asciz [STRING]

	size_t no = _next_no(ctx);

	if (name != NULL) {
		rstr_appendf(name, "_STR.%zu", no);
	}
	
	ResizableString unescaped_str;
	rstr_init(&unescaped_str);

	be_lexer_unescape_string(
		ctx->psrctx->lexctx,
		&unescaped_str,
		str, len
	);
	int unescaped_str_len = RSTR_LEN(&unescaped_str);

	// rstr_append_with_cstr(
	// 	ctx->head,
	// 	".section __TEXT,__cstring,cstring_literals\n"
	// );
	rstr_append_with_cstr(
		ctx->head,
		".text\n"
	);

	rstr_appendf(
		ctx->head,
		"_STR.%zu:\n",
		no
	);

	rstr_append_with_cstr(
		ctx->head,
		".asciz \""
	);
	for (int i = 0; i < unescaped_str_len; i++) {
		char chr = RSTR_CHAR(&unescaped_str, i);
		if (isprint(chr)) {
			rstr_append_with_char(ctx->head, chr);
		} else {
			rstr_appendf(ctx->head, "\\%03o", chr);
		}
	}
	rstr_append_with_cstr(
		ctx->head,
		"\"\n\n"
	);

	rstr_free(&unescaped_str);

	return unescaped_str_len + 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x115d1
jmp 0x115f0
leaq 0x6eb89(%rip), %rdi     # 0x80161
leaq 0x64319(%rip), %rsi     # 0x758f8
movl $0x45, %edx
leaq 0x648d2(%rip), %rcx     # 0x75ebd
callq 0x30a0
cmpq $0x0, -0x18(%rbp)
je 0x115f9
jmp 0x11618
leaq 0x62578(%rip), %rdi     # 0x73b78
leaq 0x642f1(%rip), %rsi     # 0x758f8
movl $0x46, %edx
leaq 0x648aa(%rip), %rcx     # 0x75ebd
callq 0x30a0
movq -0x8(%rbp), %rdi
callq 0x11790
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x11642
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x648d7(%rip), %rsi     # 0x75f12
movb $0x0, %al
callq 0x94d0
leaq -0x38(%rbp), %rdi
callq 0x8c90
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0x38(%rbp), %rsi
callq 0x395e0
movl -0x34(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0x648a0(%rip), %rsi     # 0x75f1b
callq 0x8d70
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x6488f(%rip), %rsi     # 0x75f22
movb $0x0, %al
callq 0x94d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0x64884(%rip), %rsi     # 0x75f2d
callq 0x8d70
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x1175e
movl -0x40(%rbp), %eax
cmpl -0x34(%rbp), %eax
jl 0x116d3
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x48(%rbp)
jmp 0x116fe
cmpq $0x0, -0x30(%rbp)
jne 0x116e7
leaq 0x6485e(%rip), %rax     # 0x75f3f
movq %rax, -0x50(%rbp)
jmp 0x116ef
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movb %al, -0x41(%rbp)
callq 0x3190
movq (%rax), %rax
movsbl -0x41(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
je 0x11734
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movsbl -0x41(%rbp), %esi
callq 0x8ea0
jmp 0x1174e
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movsbl -0x41(%rbp), %edx
leaq 0x647ef(%rip), %rsi     # 0x75f36
movb $0x0, %al
callq 0x94d0
jmp 0x11750
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x116b5
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0x647cf(%rip), %rsi     # 0x75f3c
callq 0x8d70
leaq -0x38(%rbp), %rdi
callq 0x9310
movl -0x3c(%rbp), %eax
addl $0x1, %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)