// File: /workspace/github_c_makefile_star2_O2/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 0x2e385
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 0x2e2d7
cmpq $-0x1, %rax
je 0x2e3aa
leaq 0x40d00(%rip), %rdx     # 0x6f078
pushq $0x68
popq %rsi
movq %rbx, %rdi
movl $0x2b1, %ecx            # imm = 0x2B1
jmp 0x2e397
leaq 0x40cec(%rip), %rdx     # 0x6f078
pushq $0xf
popq %rsi
movq %rbx, %rdi
movl $0x2ac, %ecx            # imm = 0x2AC
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1429e
movq %r13, 0x20(%rsp)
movq 0x28(%r14), %rax
movq 0x30(%r14), %r13
cmpq %rax, %r13
jne 0x2e41a
addq $0x10, %r13
movq 0x18(%r14), %rdi
imulq $0x148, %r13, %rsi      # imm = 0x148
callq 0x12210
testq %rax, %rax
je 0x2e4d4
movq %rax, 0x8(%rsp)
movq 0x20(%r14), %rdi
imulq $0x18, %r13, %rsi
callq 0x12210
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x2e4fe
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 0x2e428
movq %rax, 0x8(%rsp)
movq 0x20(%r14), %rax
movq %rax, 0x10(%rsp)
movq %r15, %rdi
callq 0x120f0
leaq 0x1(%rax), %rdi
callq 0x121d0
imulq $0x18, 0x8(%rsp), %r13
movq 0x10(%rsp), %rcx
movq %rax, (%rcx,%r13)
testq %rax, %rax
je 0x2e4bd
movq %rax, %rdi
movq %r15, %rsi
callq 0x12070
movq 0x10(%rsp), %rcx
movl %r12d, 0x8(%rcx,%r13)
movl 0x18(%rsp), %eax
movl %eax, 0xc(%rcx,%r13)
movl 0x1c(%rsp), %eax
movl %eax, 0x10(%rcx,%r13)
cmpl %r12d, (%rbp)
jae 0x2e47e
movl %r12d, (%rbp)
imulq $0x148, 0x8(%rsp), %rdi # imm = 0x148
addq 0x18(%r14), %rdi
movq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x2db73
cmpl $0x0, (%rbx)
je 0x2e4eb
movq 0x20(%r14), %rax
imulq $0x18, 0x28(%r14), %rcx
movq (%rax,%rcx), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x122c0
leaq 0x40bb4(%rip), %rdx     # 0x6f078
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl $0x2ca, %ecx            # imm = 0x2CA
jmp 0x2e397
leaq 0x40b9d(%rip), %rdx     # 0x6f078
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl $0x2ba, %ecx            # imm = 0x2BA
jmp 0x2e397
incq 0x28(%r14)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40b73(%rip), %rdx     # 0x6f078
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl $0x2c1, %ecx            # imm = 0x2C1
jmp 0x2e397