// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movq -0x8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x48(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x3ed45
movl -0x1c(%rbp), %eax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x3ed64
movq 0x10(%rbp), %rdi
movl $0xf, %esi
leaq 0x6d32b(%rip), %rdx     # 0xac080
movl $0x2ac, %ecx            # imm = 0x2AC
callq 0x158e0
jmp 0x3efa9
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3ec80
cmpq $-0x1, %rax
je 0x3ed96
movq 0x10(%rbp), %rdi
movl $0x68, %esi
leaq 0x6d2f9(%rip), %rdx     # 0xac080
movl $0x2b1, %ecx            # imm = 0x2B1
callq 0x158e0
jmp 0x3efa9
movq -0x48(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x48(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jne 0x3ee64
movq -0x48(%rbp), %rax
movq 0x28(%rax), %rax
addq $0x10, %rax
movq %rax, -0x30(%rbp)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
imulq $0x148, -0x30(%rbp), %rsi # imm = 0x148
callq 0x121e0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x3edfb
movq 0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x6d294(%rip), %rdx     # 0xac080
movl $0x2ba, %ecx            # imm = 0x2BA
callq 0x158e0
jmp 0x3efa9
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rdi
imulq $0x18, -0x30(%rbp), %rsi
callq 0x121e0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x3ee40
movq -0x40(%rbp), %rdi
callq 0x12290
movq 0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x6d24f(%rip), %rdx     # 0xac080
movl $0x2c1, %ecx            # imm = 0x2C1
callq 0x158e0
jmp 0x3efa9
movq -0x38(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rdi
callq 0x120d0
movq %rax, %rdi
addq $0x1, %rdi
callq 0x121b0
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x48(%rbp), %rdx
imulq $0x18, 0x20(%rdx), %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x48(%rbp), %rcx
imulq $0x18, 0x20(%rcx), %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
jne 0x3eecc
movq 0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x6d1c3(%rip), %rdx     # 0xac080
movl $0x2ca, %ecx            # imm = 0x2CA
callq 0x158e0
jmp 0x3efa9
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x48(%rbp), %rcx
imulq $0x18, 0x20(%rcx), %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x12060
movl -0x1c(%rbp), %ecx
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x48(%rbp), %rdx
imulq $0x18, 0x20(%rdx), %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movl -0x20(%rbp), %ecx
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x48(%rbp), %rdx
imulq $0x18, 0x20(%rdx), %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movl -0x24(%rbp), %ecx
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x48(%rbp), %rdx
imulq $0x18, 0x20(%rdx), %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0x48(%rbp), %rax
movl (%rax), %eax
cmpl -0x1c(%rbp), %eax
jae 0x3ef4e
movl -0x1c(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, (%rax)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x48(%rbp), %rax
imulq $0x148, 0x20(%rax), %rax # imm = 0x148
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x3dec0
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x3ef99
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x48(%rbp), %rcx
imulq $0x18, 0x20(%rcx), %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x12290
jmp 0x3efa9
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
addq $0x50, %rsp
popq %rbp
retq
nop