// File: /workspace/github_c_makefile_star2_O0/Seclabs-htc[P]slip39/trezor-crypto/sha2.c
// Function: sha1_Update
void sha1_Update(SHA1_CTX* context, const sha2_byte *data, size_t len) {
	unsigned int	freespace, usedspace;

	if (len == 0) {
		/* Calling with no data is valid - we do nothing */
		return;
	}

	usedspace = (context->bitcount >> 3) % SHA1_BLOCK_LENGTH;
	if (usedspace > 0) {
		/* Calculate how much free space is available in the buffer */
		freespace = SHA1_BLOCK_LENGTH - usedspace;

		if (len >= freespace) {
			/* Fill the buffer completely and process it */
			MEMCPY_BCOPY(((uint8_t*)context->buffer) + usedspace, data, freespace);
			context->bitcount += freespace << 3;
			len -= freespace;
			data += freespace;
#if BYTE_ORDER == LITTLE_ENDIAN
			/* Convert TO host byte order */
			for (int j = 0; j < 16; j++) {
				REVERSE32(context->buffer[j],context->buffer[j]);
			}
#endif
			sha1_Transform(context->state, context->buffer, context->state);
		} else {
			/* The buffer is not yet full */
			MEMCPY_BCOPY(((uint8_t*)context->buffer) + usedspace, data, len);
			context->bitcount += len << 3;
			/* Clean up: */
			usedspace = freespace = 0;
			return;
		}
	}
	while (len >= SHA1_BLOCK_LENGTH) {
		/* Process as many complete blocks as we can */
		MEMCPY_BCOPY(context->buffer, data, SHA1_BLOCK_LENGTH);
#if BYTE_ORDER == LITTLE_ENDIAN
		/* Convert TO host byte order */
		for (int j = 0; j < 16; j++) {
			REVERSE32(context->buffer[j],context->buffer[j]);
		}
#endif
		sha1_Transform(context->state, context->buffer, context->state);
		context->bitcount += SHA1_BLOCK_LENGTH << 3;
		len -= SHA1_BLOCK_LENGTH;
		data += SHA1_BLOCK_LENGTH;
	}
	if (len > 0) {
		/* There's left-overs, so save 'em */
		MEMCPY_BCOPY(context->buffer, data, len);
		context->bitcount += len << 3;
	}
	/* Clean up: */
	usedspace = freespace = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x90f0
jmp 0x9351
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x3, %rax
andq $0x3f, %rax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jbe 0x9240
movl $0x40, %eax
subl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
cmpq %rcx, %rax
jb 0x91fc
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
movl -0x20(%rbp), %eax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movl -0x1c(%rbp), %eax
movl %eax, %edx
callq 0x8090
movl -0x1c(%rbp), %eax
shll $0x3, %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x8(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movl -0x1c(%rbp), %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x10, -0x24(%rbp)
jge 0x91e5
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl 0x20(%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
shrl $0x10, %eax
movl -0x28(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movabsq $0xff00ff00, %rcx       # imm = 0xFF00FF00
andq %rcx, %rax
shrq $0x8, %rax
movl -0x28(%rbp), %ecx
andq $0xff00ff, %rcx         # imm = 0xFF00FF
shlq $0x8, %rcx
orq %rcx, %rax
movl %eax, %edx
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl %edx, 0x20(%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x9181
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x20, %rsi
movq -0x8(%rbp), %rdx
callq 0x8c50
jmp 0x923e
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
movl -0x20(%rbp), %eax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x8090
movq -0x18(%rbp), %rcx
shlq $0x3, %rcx
movq -0x8(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
jmp 0x9351
jmp 0x9240
jmp 0x9242
cmpq $0x40, -0x18(%rbp)
jb 0x9313
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
movq -0x10(%rbp), %rsi
movl $0x40, %edx
callq 0x8090
movl $0x0, -0x2c(%rbp)
cmpl $0x10, -0x2c(%rbp)
jge 0x92ce
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl 0x20(%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
shrl $0x10, %eax
movl -0x30(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movabsq $0xff00ff00, %rcx       # imm = 0xFF00FF00
andq %rcx, %rax
shrq $0x8, %rax
movl -0x30(%rbp), %ecx
andq $0xff00ff, %rcx         # imm = 0xFF00FF
shlq $0x8, %rcx
orq %rcx, %rax
movl %eax, %edx
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl %edx, 0x20(%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x926a
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x20, %rsi
movq -0x8(%rbp), %rdx
callq 0x8c50
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x200, %rcx            # imm = 0x200
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
subq $0x40, %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x10(%rbp)
jmp 0x9242
cmpq $0x0, -0x18(%rbp)
jbe 0x9343
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x8090
movq -0x18(%rbp), %rcx
shlq $0x3, %rcx
movq -0x8(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)