// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/common/type.c
// Function: subtilis_type_rec_add_field
void subtilis_type_rec_add_field(subtilis_type_t *dst, const char *name,
				 const subtilis_type_t *field,
				 uint32_t alignment, uint32_t size,
				 int32_t vec_dim, subtilis_error_t *err)
{
	size_t new_max;
	subtilis_type_t *new_field_types;
	subtilis_type_field_t *new_fields;
	subtilis_type_rec_t *rec = &dst->params.rec;

	/*
	 * Alignment must be a power of 2.
	 */

	if ((alignment == 0) || (alignment & (alignment - 1))) {
		subtilis_error_set_assertion_failed(err);
		return;
	}

	if (subtilis_type_rec_find_field(rec, name) != SIZE_MAX) {
		subtilis_error_set_type_already_defined(err);
		return;
	}

	if (rec->max_fields == rec->num_fields) {
		new_max = rec->max_fields + SUBTILIS_FIELD_GRANULARITY;
		new_field_types = realloc(rec->field_types,
					  new_max * sizeof(*new_field_types));
		if (!new_field_types) {
			subtilis_error_set_oom(err);
			return;
		}
		new_fields =
		    realloc(rec->fields, new_max * sizeof(*new_fields));
		if (!new_fields) {
			free(new_fields);
			subtilis_error_set_oom(err);
			return;
		}
		rec->field_types = new_field_types;
		rec->fields = new_fields;
		rec->max_fields = new_max;
	}
	rec->fields[rec->num_fields].name = malloc(strlen(name) + 1);
	if (!rec->fields[rec->num_fields].name) {
		subtilis_error_set_oom(err);
		return;
	}
	strcpy(rec->fields[rec->num_fields].name, name);
	rec->fields[rec->num_fields].alignment = alignment;
	rec->fields[rec->num_fields].size = size;
	rec->fields[rec->num_fields].vec_dim = vec_dim;
	if (rec->alignment < alignment)
		rec->alignment = alignment;

	subtilis_type_init_copy(&rec->field_types[rec->num_fields], field, err);
	if (err->type != SUBTILIS_ERROR_OK) {
		free(rec->fields[rec->num_fields].name);
		return;
	}
	rec->num_fields++;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %r12d
movq 0x60(%rsp), %rbx
leal -0x1(%r12), %eax
xorl %eax, %ecx
cmpl %eax, %ecx
jbe 0x2fcc4
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r14
movl %r8d, 0x18(%rsp)
movl %r9d, 0x1c(%rsp)
leaq 0x8(%rdi), %rbp
movq %rbp, %rdi
callq 0x2fc17
cmpq $-0x1, %rax
je 0x2fceb
leaq 0x45413(%rip), %rdx     # 0x750c8
movq %rbx, %rdi
movl $0x68, %esi
movl $0x2b1, %ecx            # imm = 0x2B1
jmp 0x2fcd8
leaq 0x453fd(%rip), %rdx     # 0x750c8
movq %rbx, %rdi
movl $0xf, %esi
movl $0x2ac, %ecx            # imm = 0x2AC
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x145a4
movq %r13, 0x20(%rsp)
movq 0x28(%r14), %rax
movq 0x30(%r14), %r13
cmpq %rax, %r13
jne 0x2fd63
addq $0x10, %r13
movq 0x18(%r14), %rdi
imulq $0x148, %r13, %rsi      # imm = 0x148
callq 0x12210
testq %rax, %rax
je 0x2fe25
movq %rax, 0x8(%rsp)
movq 0x20(%r14), %rdi
leaq (,%r13,8), %rax
leaq (%rax,%rax,2), %rsi
callq 0x12210
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x2fe51
movq 0x8(%rsp), %rax
movq %rax, 0x18(%r14)
movq 0x10(%rsp), %rax
movq %rax, 0x20(%r14)
movq %r13, 0x30(%r14)
movq 0x28(%r14), %rax
movq %rax, 0x8(%rsp)
jmp 0x2fd71
movq %rax, 0x8(%rsp)
movq 0x20(%r14), %rax
movq %rax, 0x10(%rsp)
movq %r15, %rdi
callq 0x120f0
leaq 0x1(%rax), %rdi
callq 0x121d0
movq 0x8(%rsp), %rcx
leaq (%rcx,%rcx,2), %r13
movq 0x10(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
testq %rax, %rax
je 0x2fe0c
movq %rax, %rdi
movq %r15, %rsi
callq 0x12070
movq 0x10(%rsp), %rcx
movl %r12d, 0x8(%rcx,%r13,8)
movl 0x18(%rsp), %eax
movl %eax, 0xc(%rcx,%r13,8)
movl 0x1c(%rsp), %eax
movl %eax, 0x10(%rcx,%r13,8)
cmpl %r12d, (%rbp)
jae 0x2fdca
movl %r12d, (%rbp)
imulq $0x148, 0x8(%rsp), %rdi # imm = 0x148
addq 0x18(%r14), %rdi
movq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x2f457
cmpl $0x0, (%rbx)
je 0x2fe3e
movq 0x20(%r14), %rax
movq 0x28(%r14), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x122c0
leaq 0x452b5(%rip), %rdx     # 0x750c8
movq %rbx, %rdi
movl $0x1, %esi
movl $0x2ca, %ecx            # imm = 0x2CA
jmp 0x2fcd8
leaq 0x4529c(%rip), %rdx     # 0x750c8
movq %rbx, %rdi
movl $0x1, %esi
movl $0x2ba, %ecx            # imm = 0x2BA
jmp 0x2fcd8
incq 0x28(%r14)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x45270(%rip), %rdx     # 0x750c8
movq %rbx, %rdi
movl $0x1, %esi
movl $0x2c1, %ecx            # imm = 0x2C1
jmp 0x2fcd8