// File: /workspace/github_c_makefile_star2_O0/findstr[P]version-database/patch.c
// Function: patch_content
static dr_t
patch_content(dr_t old, dr_t patch)
{
	dr_t new;
	uint8_t *w;
	uint32_t size;
	const uint8_t *p = patch->buf;
	const uint8_t *e = p + patch->size;
	p = patch_total_read(p, &size);
	new = dr_new(size, NULL);
	w = new->buf;
	printf("patch size:%d total:%d\n", patch->size, size);
	while (p < e) {
		struct PATCH patch;
		p = patch_read(p, &patch);
		if (patch.act == PATCH_COPY) {
			uint32_t pos, size;
			pos = patch.u.copy.pos;
			size = patch.u.copy.size;
			//printf("COPY FROM %d TO %ld SIZE %d\n",
			//	pos, w - new->buf, size);
			assert(new->size - (w - new->buf) >= size);
			memcpy(w, &old->buf[pos], size);
			w += size;
		} else if (patch.act == PATCH_INSERT) {
			int sz = patch.u.insert.size;
			assert(new->size - (w - new->buf) >= sz);
			memcpy(w, patch.u.insert.p, sz);
			w += sz;
		} else {
			assert(0);
		}
	}
	return new;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x4(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x7990
movq %rax, -0x30(%rbp)
movl -0x24(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x4aa0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %esi
movl -0x24(%rbp), %edx
leaq 0x78a1(%rip), %rdi      # 0xc41e
movb $0x0, %al
callq 0x2100
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x4ccd
movq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x7ad0
movq %rax, -0x30(%rbp)
movzbl -0x50(%rbp), %eax
cmpl $0x1, %eax
jne 0x4c30
movl -0x48(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movslq 0x4(%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rdx
addq $0x8, %rdx
subq %rdx, %rcx
subq %rcx, %rax
movl -0x58(%rbp), %ecx
cmpq %rcx, %rax
jl 0x4be0
jmp 0x4bff
leaq 0x784f(%rip), %rdi      # 0xc436
leaq 0x786b(%rip), %rsi      # 0xc459
movl $0x22, %edx
leaq 0x7867(%rip), %rcx      # 0xc461
callq 0x2120
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x8, %rsi
movl -0x54(%rbp), %eax
addq %rax, %rsi
movl -0x58(%rbp), %eax
movl %eax, %edx
callq 0x21d0
movl -0x58(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
jmp 0x4cc8
movzbl -0x50(%rbp), %eax
cmpl $0x2, %eax
jne 0x4ca7
movl -0x40(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x18(%rbp), %rax
movslq 0x4(%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rdx
addq $0x8, %rdx
subq %rdx, %rcx
subq %rcx, %rax
movslq -0x5c(%rbp), %rcx
cmpq %rcx, %rax
jl 0x4c64
jmp 0x4c83
leaq 0x7815(%rip), %rdi      # 0xc480
leaq 0x77e7(%rip), %rsi      # 0xc459
movl $0x27, %edx
leaq 0x77e3(%rip), %rcx      # 0xc461
callq 0x2120
movq -0x20(%rbp), %rdi
movq -0x48(%rbp), %rsi
movslq -0x5c(%rbp), %rdx
callq 0x21d0
movl -0x5c(%rbp), %ecx
movq -0x20(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
jmp 0x4cc6
leaq 0x7cb6(%rip), %rdi      # 0xc964
leaq 0x77a4(%rip), %rsi      # 0xc459
movl $0x2b, %edx
leaq 0x77a0(%rip), %rcx      # 0xc461
callq 0x2120
jmp 0x4cc8
jmp 0x4b84
movq -0x18(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)