// File: /workspace/github_c_makefile_star2_O0/DrYerzinia[P]C_DigiMode/src/packet/APRSPacket.c
// Function: APRSPacket_from_data
void APRSPacket_from_data(APRSPacket *packet, char_array *data){

	int i;

	packet->data.len = data->len;
	packet->data.data = data->data;

	for(i = 0; i < 7; i++) packet->destination_address[i] = (signed char)((unsigned char)(data->data[i])>>1);
	packet->destination_address[7] = '\0';

	for(i = 7; i < 14; i++) packet->source_address[i-7] = (signed char)((unsigned char)(data->data[i])>>1);
	packet->source_address[7] = '\0';

	packet->repeaters = 0;
	packet->repeater_addresses = (signed char**) malloc(sizeof(void*)*8);

	int n = 14;
	while(true){

		if(n+1 >= data->len) break;

		// Check for 0 bit set on end of last address character indicating that there are no more repeater addresses
		if((data->data[n-1] & 0x01) != 0) break;

		if(packet->repeaters > 7) break;

		if(n+7 >= data->len) break;

		signed char* new_address = (signed char*) malloc(sizeof(char)*8);
		for(i = n; i < n+7; i++) new_address[i-n] = (signed char)((unsigned char)(data->data[i])>>1);
		new_address[7] = '\0';
		n+=7;

		packet->repeater_addresses[packet->repeaters] = new_address;
		packet->repeaters++;

	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movw (%rax), %cx
movq -0x8(%rbp), %rax
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x14(%rbp)
cmpl $0x7, -0x14(%rbp)
jge 0x1916
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x14(%rbp), %rcx
movzbl (%rax,%rcx), %eax
sarl %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movb %dl, 0x10(%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x18e5
movq -0x8(%rbp), %rax
movb $0x0, 0x17(%rax)
movl $0x7, -0x14(%rbp)
cmpl $0xe, -0x14(%rbp)
jge 0x195b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x14(%rbp), %rcx
movzbl (%rax,%rcx), %eax
sarl %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x7, %ecx
movslq %ecx, %rcx
movb %dl, 0x18(%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1925
movq -0x8(%rbp), %rax
movb $0x0, 0x1f(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x20(%rax)
movl $0x40, %edi
callq 0x10f0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x28(%rax)
movl $0xe, -0x18(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jl 0x199d
jmp 0x1a72
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x19bf
jmp 0x1a72
movq -0x8(%rbp), %rax
movzbl 0x20(%rax), %eax
cmpl $0x7, %eax
jle 0x19d1
jmp 0x1a72
movl -0x18(%rbp), %eax
addl $0x7, %eax
movq -0x10(%rbp), %rcx
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jl 0x19e7
jmp 0x1a72
movl $0x8, %edi
callq 0x10f0
movq %rax, -0x20(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl -0x18(%rbp), %ecx
addl $0x7, %ecx
cmpl %ecx, %eax
jge 0x1a37
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x14(%rbp), %rcx
movzbl (%rax,%rcx), %eax
sarl %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movl -0x14(%rbp), %ecx
subl -0x18(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x19fb
movq -0x20(%rbp), %rax
movb $0x0, 0x7(%rax)
movl -0x18(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x8(%rbp), %rcx
movzbl 0x20(%rcx), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movb 0x20(%rax), %cl
addb $0x1, %cl
movb %cl, 0x20(%rax)
jmp 0x1987
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)