Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
// AOJ 1509 Rental DVD Shop NEO
// 2018.1.30 bal4u

#include <stdio.h>

#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int a, b, c, d, e, na, nb, nc, k, ans;
	
	while (a = in()) {
		b = in(), c = in(), d = in(), e = in();
		na = in(), nb = in(), nc = in();
		
		if (nc >= d) ans = e*nc + b*nb + a*na;
		else {
            ans = c*nc + b*nb + a*na;
			k = d-nc;
			if (k <= nb) nb -= k, k = 0;
			else         k -= nb, nb = 0;
			if (k <= na) na -= k;
			else         k -= na, na = 0;

			k = e*d + b*nb + a*na;
			if (ans > k) ans = k;
		}
		printf("%d\n", ans);
	}
	return 0;
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	in
	.type	in, @function
in:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	$0, -8(%rbp)
	call	getchar@PLT
	movl	%eax, -4(%rbp)
.L2:
	movl	-8(%rbp), %eax
	leal	0(,%rax,8), %edx
	movl	-8(%rbp), %eax
	addl	%eax, %eax
	addl	%eax, %edx
	movl	-4(%rbp), %eax
	andl	$15, %eax
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
	call	getchar@PLT
	movl	%eax, -4(%rbp)
	cmpl	$47, -4(%rbp)
	jg	.L2
	movl	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	in, .-in
	.section	.rodata
.LC0:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	jmp	.L5
.L12:
	movl	$0, %eax
	call	in
	movl	%eax, -20(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -16(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -12(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -8(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -40(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -36(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jl	.L6
	movl	-8(%rbp), %eax
	imull	-4(%rbp), %eax
	movl	%eax, %edx
	movl	-20(%rbp), %eax
	imull	-36(%rbp), %eax
	addl	%eax, %edx
	movl	-24(%rbp), %eax
	imull	-40(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -28(%rbp)
	jmp	.L7
.L6:
	movl	-16(%rbp), %eax
	imull	-4(%rbp), %eax
	movl	%eax, %edx
	movl	-20(%rbp), %eax
	imull	-36(%rbp), %eax
	addl	%eax, %edx
	movl	-24(%rbp), %eax
	imull	-40(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -28(%rbp)
	movl	-12(%rbp), %eax
	subl	-4(%rbp), %eax
	movl	%eax, -32(%rbp)
	movl	-32(%rbp), %eax
	cmpl	-36(%rbp), %eax
	jg	.L8
	movl	-32(%rbp), %eax
	subl	%eax, -36(%rbp)
	movl	$0, -32(%rbp)
	jmp	.L9
.L8:
	movl	-36(%rbp), %eax
	subl	%eax, -32(%rbp)
	movl	$0, -36(%rbp)
.L9:
	movl	-32(%rbp), %eax
	cmpl	-40(%rbp), %eax
	jg	.L10
	movl	-32(%rbp), %eax
	subl	%eax, -40(%rbp)
	jmp	.L11
.L10:
	movl	-40(%rbp), %eax
	subl	%eax, -32(%rbp)
	movl	$0, -40(%rbp)
.L11:
	movl	-8(%rbp), %eax
	imull	-12(%rbp), %eax
	movl	%eax, %edx
	movl	-20(%rbp), %eax
	imull	-36(%rbp), %eax
	addl	%eax, %edx
	movl	-24(%rbp), %eax
	imull	-40(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -32(%rbp)
	movl	-28(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jle	.L7
	movl	-32(%rbp), %eax
	movl	%eax, -28(%rbp)
.L7:
	movl	-28(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L5:
	movl	$0, %eax
	call	in
	movl	%eax, -24(%rbp)
	cmpl	$0, -24(%rbp)
	jne	.L12
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
user
	.file	"temp.c"
	.text
	.p2align 4
	.globl	in
	.type	in, @function
in:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	stdin(%rip), %rdi
	xorl	%r12d, %r12d
	call	getc@PLT
	.p2align 4,,10
	.p2align 3
.L2:
	movq	stdin(%rip), %rdi
	andl	$15, %eax
	leal	(%r12,%r12,4), %edx
	leal	(%rax,%rdx,2), %r12d
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L2
	movl	%r12d, %eax
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE23:
	.size	in, .-in
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.p2align 4,,10
	.p2align 3
.L7:
	movq	stdin(%rip), %rdi
	xorl	%ebp, %ebp
	call	getc@PLT
	.p2align 4,,10
	.p2align 3
.L20:
	movq	stdin(%rip), %rdi
	andl	$15, %eax
	leal	0(%rbp,%rbp,4), %edx
	leal	(%rax,%rdx,2), %ebp
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L20
	testl	%ebp, %ebp
	je	.L32
	movq	stdin(%rip), %rdi
	xorl	%r15d, %r15d
	call	getc@PLT
	.p2align 4,,10
	.p2align 3
.L8:
	movq	stdin(%rip), %rdi
	andl	$15, %eax
	leal	(%r15,%r15,4), %edx
	leal	(%rax,%rdx,2), %r15d
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L8
	movq	stdin(%rip), %rdi
	call	getc@PLT
	movl	$0, 8(%rsp)
	.p2align 4,,10
	.p2align 3
.L9:
	movl	8(%rsp), %esi
	andl	$15, %eax
	movq	stdin(%rip), %rdi
	leal	(%rsi,%rsi,4), %edx
	leal	(%rax,%rdx,2), %eax
	movl	%eax, 8(%rsp)
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L9
	movq	stdin(%rip), %rdi
	xorl	%r14d, %r14d
	call	getc@PLT
	.p2align 4,,10
	.p2align 3
.L10:
	movq	stdin(%rip), %rdi
	andl	$15, %eax
	leal	(%r14,%r14,4), %edx
	leal	(%rax,%rdx,2), %r14d
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L10
	movq	stdin(%rip), %rdi
	xorl	%ebx, %ebx
	call	getc@PLT
	.p2align 4,,10
	.p2align 3
.L11:
	movq	stdin(%rip), %rdi
	andl	$15, %eax
	leal	(%rbx,%rbx,4), %edx
	leal	(%rax,%rdx,2), %ebx
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L11
	movq	stdin(%rip), %rdi
	xorl	%r13d, %r13d
	call	getc@PLT
	.p2align 4,,10
	.p2align 3
.L12:
	movq	stdin(%rip), %rdi
	andl	$15, %eax
	leal	0(%r13,%r13,4), %edx
	leal	(%rax,%rdx,2), %r13d
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L12
	movq	stdin(%rip), %rdi
	xorl	%r12d, %r12d
	call	getc@PLT
	.p2align 4,,10
	.p2align 3
.L13:
	movq	stdin(%rip), %rdi
	andl	$15, %eax
	leal	(%r12,%r12,4), %edx
	leal	(%rax,%rdx,2), %r12d
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L13
	movq	stdin(%rip), %rdi
	call	getc@PLT
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L14:
	andl	$15, %eax
	movq	stdin(%rip), %rdi
	leal	(%rdx,%rdx,4), %edx
	leal	(%rax,%rdx,2), %edx
	movl	%edx, 12(%rsp)
	call	getc@PLT
	movl	12(%rsp), %edx
	cmpl	$47, %eax
	jg	.L14
	movl	%r12d, %esi
	movl	%r13d, %ecx
	imull	%r15d, %esi
	imull	%ebp, %ecx
	cmpl	%r14d, %edx
	jl	.L15
	imull	%edx, %ebx
	leal	(%rbx,%rsi), %edx
	addl	%ecx, %edx
.L16:
	leaq	.LC0(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L15:
	movl	8(%rsp), %eax
	imull	%edx, %eax
	addl	%esi, %eax
	addl	%ecx, %eax
	movl	%r14d, %ecx
	subl	%edx, %ecx
	cmpl	%r12d, %ecx
	jg	.L17
	subl	%ecx, %r12d
	xorl	%ecx, %ecx
	imull	%r15d, %r12d
.L18:
	xorl	%esi, %esi
	cmpl	%r13d, %ecx
	jg	.L19
	subl	%ecx, %r13d
	movl	%r13d, %esi
	imull	%ebp, %esi
.L19:
	imull	%r14d, %ebx
	leal	(%rbx,%r12), %edx
	addl	%esi, %edx
	cmpl	%eax, %edx
	cmovg	%eax, %edx
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L17:
	subl	%r12d, %ecx
	xorl	%r12d, %r12d
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L32:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

rule
	.file	"temp.c"
	.text
	.p2align 4
	.globl	in
	.type	in, @function
in:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	stdin(%rip), %rdi
	xorl	%r12d, %r12d
	call	getc@PLT
	.p2align 4,,10
	.p2align 3
.L2:
	movq	stdin(%rip), %rdi
	andl	$15, %eax
	leal	(%r12,%r12,4), %edx
	leal	(%rax,%rdx,2), %r12d
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L2
	movl	%r12d, %eax
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE23:
	.size	in, .-in
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.p2align 4,,10
	.p2align 3
.L7:
	movq	stdin(%rip), %rdi
	xorl	%ebp, %ebp
	call	getc@PLT
	.p2align 4,,10
	.p2align 3
.L20:
	movq	stdin(%rip), %rdi
	andl	$15, %eax
	leal	0(%rbp,%rbp,4), %edx
	leal	(%rax,%rdx,2), %ebp
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L20
	testl	%ebp, %ebp
	je	.L32
	movq	stdin(%rip), %rdi
	xorl	%r15d, %r15d
	call	getc@PLT
	.p2align 4,,10
	.p2align 3
.L8:
	movq	stdin(%rip), %rdi
	andl	$15, %eax
	leal	(%r15,%r15,4), %edx
	leal	(%rax,%rdx,2), %r15d
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L8
	movq	stdin(%rip), %rdi
	call	getc@PLT
	movl	$0, 8(%rsp)
	.p2align 4,,10
	.p2align 3
.L9:
	movl	8(%rsp), %esi
	andl	$15, %eax
	movq	stdin(%rip), %rdi
	leal	(%rsi,%rsi,4), %edx
	leal	(%rax,%rdx,2), %eax
	movl	%eax, 8(%rsp)
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L9
	movq	stdin(%rip), %rdi
	xorl	%r14d, %r14d
	call	getc@PLT
	.p2align 4,,10
	.p2align 3
.L10:
	movq	stdin(%rip), %rdi
	andl	$15, %eax
	leal	(%r14,%r14,4), %edx
	leal	(%rax,%rdx,2), %r14d
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L10
	movq	stdin(%rip), %rdi
	xorl	%ebx, %ebx
	call	getc@PLT
	.p2align 4,,10
	.p2align 3
.L11:
	movq	stdin(%rip), %rdi
	andl	$15, %eax
	leal	(%rbx,%rbx,4), %edx
	leal	(%rax,%rdx,2), %ebx
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L11
	movq	stdin(%rip), %rdi
	xorl	%r13d, %r13d
	call	getc@PLT
	.p2align 4,,10
	.p2align 3
.L12:
	movq	stdin(%rip), %rdi
	andl	$15, %eax
	leal	0(%r13,%r13,4), %edx
	leal	(%rax,%rdx,2), %r13d
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L12
	movq	stdin(%rip), %rdi
	xorl	%r12d, %r12d
	call	getc@PLT
	.p2align 4,,10
	.p2align 3
.L13:
	movq	stdin(%rip), %rdi
	andl	$15, %eax
	leal	(%r12,%r12,4), %edx
	leal	(%rax,%rdx,2), %r12d
	call	getc@PLT
	cmpl	$47, %eax
	jg	.L13
	movq	stdin(%rip), %rdi
	call	getc@PLT
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L14:
	andl	$15, %eax
	movq	stdin(%rip), %rdi
	leal	(%rdx,%rdx,4), %edx
	leal	(%rax,%rdx,2), %edx
	movl	%edx, 12(%rsp)
	call	getc@PLT
	movl	12(%rsp), %edx
	cmpl	$47, %eax
	jg	.L14
	movl	%r12d, %esi
	movl	%r13d, %ecx
	imull	%r15d, %esi
	imull	%ebp, %ecx
	cmpl	%r14d, %edx
	jl	.L15
	imull	%edx, %ebx
	leal	(%rbx,%rsi), %edx
	addl	%ecx, %edx
.L16:
	leaq	.LC0(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L15:
	movl	8(%rsp), %eax
	imull	%edx, %eax
	addl	%esi, %eax
	addl	%ecx, %eax
	movl	%r14d, %ecx
	subl	%edx, %ecx
	cmpl	%r12d, %ecx
	jg	.L17
	subl	%ecx, %r12d
	xorl	%ecx, %ecx
	imull	%r15d, %r12d
.L18:
	xorl	%esi, %esi
	cmpl	%r13d, %ecx
	jg	.L19
	subl	%ecx, %r13d
	movl	%r13d, %esi
	imull	%ebp, %esi
.L19:
	imull	%r14d, %ebx
	leal	(%rbx,%r12), %edx
	addl	%esi, %edx
	cmpl	%eax, %edx
	cmovg	%eax, %edx
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L17:
	subl	%r12d, %ecx
	xorl	%r12d, %r12d
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L32:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

// AOJ 1509 Rental DVD Shop NEO
// 2018.1.30 bal4u

#include <stdio.h>

#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int a, b, c, d, e, na, nb, nc, k, ans;
	
	while (a = in()) {
		b = in(), c = in(), d = in(), e = in();
		na = in(), nb = in(), nc = in();
		
		if (nc >= d) ans = e*nc + b*nb + a*na;
		else {
            ans = c*nc + b*nb + a*na;
			k = d-nc;
			if (k <= nb) nb -= k, k = 0;
			else         k -= nb, nb = 0;
			if (k <= na) na -= k;
			else         k -= na, na = 0;

			k = e*d + b*nb + a*na;
			if (ans > k) ans = k;
		}
		printf("%d\n", ans);
	}
	return 0;
}


70 100 340 4 200
1 1 4
70 100 340 4 200
0 1 3
70 100 340 6 200
1 1 2
0 0 0 0 0
 135 100 340 4 200
1 1 4
70 100 340 4 200
0 1 3
70 100 340 6 200
1 1 2
0 0 0 0 0
 135 100 340 4 200
1 1 4
70 100 351 5 200
0 1 3
70 100 340 6 288
1 1 2
0 0 0 0 0
 70 100 340 4 200
1 1 4
70 100 340 4 131
0 1 3
70 100 340 4 200
1 1 2
0 0 0 0 0
 135 100 340 4 200
1 1 4
70 100 351 5 200
0 1 3
70 100 340 6 343
1 1 3
0 0 0 0 0
 70 100 340 4 200
2 1 4
70 100 340 4 131
0 1 3
70 100 340 4 200
1 1 2
0 0 0 0 0
 70 100 340 4 200
1 1 4
70 100 340 2 200
0 0 3
70 100 340 6 200
1 1 2
0 0 0 0 0
 6 100 340 4 200
1 1 4
70 100 340 2 200
0 0 3
70 100 340 6 200
1 1 2
0 0 0 0 0
 135 100 496 4 200
1 1 4
20 100 351 5 200
0 1 3
15 100 340 6 288
1 1 2
0 0 0 0 0
 6 100 340 4 200
1 1 4
70 100 340 2 200
0 0 3
70 100 420 6 200
1 1 2
0 0 0 0 0

970
800
850
 1035
800
850
 1035
1000
850
 970
524
800
 1035
1000
1190
 1040
524
800
 970
600
850
 906
600
850
 1035
1000
795
 906
600
1010

Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
// AOJ 1509 Rental DVD Shop NEO
// 2018.1.30 bal4u

#include <stdio.h>

#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int a, b, c, d, e, na, nb, nc, k, ans;
	
	while (a = in()) {
		b = in(), c = in(), d = in(), e = in();
		na = in(), nb = in(), nc = in();
		
		if (nc >= d) ans = e*nc + b*nb + a*na;
		else {
            ans = c*nc + b*nb + a*na;
			k = d-nc;
			if (k <= nb) nb -= k, k = 0;
			else         k -= nb, nb = 0;
			if (k <= na) na -= k;
			else         k -= na, na = 0;

			k = e*d + b*nb + a*na;
			if (ans > k) ans = k;
		}
		printf("%d\n", ans);
	}
	return 0;
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	in
	.type	in, @function
in:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	$0, -8(%rbp)
	call	getchar@PLT
	movl	%eax, -4(%rbp)
.L2:
	movl	-8(%rbp), %eax
	leal	0(,%rax,8), %edx
	movl	-8(%rbp), %eax
	addl	%eax, %eax
	addl	%eax, %edx
	movl	-4(%rbp), %eax
	andl	$15, %eax
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
	call	getchar@PLT
	movl	%eax, -4(%rbp)
	cmpl	$47, -4(%rbp)
	jg	.L2
	movl	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	in, .-in
	.section	.rodata
.LC0:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	jmp	.L5
.L12:
	movl	$0, %eax
	call	in
	movl	%eax, -20(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -16(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -12(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -8(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -40(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -36(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jl	.L6
	movl	-8(%rbp), %eax
	imull	-4(%rbp), %eax
	movl	%eax, %edx
	movl	-20(%rbp), %eax
	imull	-36(%rbp), %eax
	addl	%eax, %edx
	movl	-24(%rbp), %eax
	imull	-40(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -28(%rbp)
	jmp	.L7
.L6:
	movl	-16(%rbp), %eax
	imull	-4(%rbp), %eax
	movl	%eax, %edx
	movl	-20(%rbp), %eax
	imull	-36(%rbp), %eax
	addl	%eax, %edx
	movl	-24(%rbp), %eax
	imull	-40(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -28(%rbp)
	movl	-12(%rbp), %eax
	subl	-4(%rbp), %eax
	movl	%eax, -32(%rbp)
	movl	-32(%rbp), %eax
	cmpl	-36(%rbp), %eax
	jg	.L8
	movl	-32(%rbp), %eax
	subl	%eax, -36(%rbp)
	movl	$0, -32(%rbp)
	jmp	.L9
.L8:
	movl	-36(%rbp), %eax
	subl	%eax, -32(%rbp)
	movl	$0, -36(%rbp)
.L9:
	movl	-32(%rbp), %eax
	cmpl	-40(%rbp), %eax
	jg	.L10
	movl	-32(%rbp), %eax
	subl	%eax, -40(%rbp)
	jmp	.L11
.L10:
	movl	-40(%rbp), %eax
	subl	%eax, -32(%rbp)
	movl	$0, -40(%rbp)
.L11:
	movl	-8(%rbp), %eax
	imull	-12(%rbp), %eax
	movl	%eax, %edx
	movl	-20(%rbp), %eax
	imull	-36(%rbp), %eax
	addl	%eax, %edx
	movl	-24(%rbp), %eax
	imull	-40(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -32(%rbp)
	movl	-28(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jle	.L7
	movl	-32(%rbp), %eax
	movl	%eax, -28(%rbp)
.L7:
	movl	-28(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L5:
	movl	$0, %eax
	call	in
	movl	%eax, -24(%rbp)
	cmpl	$0, -24(%rbp)
	jne	.L12
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
train
	.file	"temp.c"
	.text
	.globl	in
	.type	in, @function
in:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	$0, -8(%rbp)
	call	getchar@PLT
	movl	%eax, -4(%rbp)
.L2:
	movl	-8(%rbp), %eax
	leal	0(,%rax,8), %edx
	movl	-8(%rbp), %eax
	addl	%eax, %eax
	addl	%eax, %edx
	movl	-4(%rbp), %eax
	andl	$15, %eax
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
	call	getchar@PLT
	movl	%eax, -4(%rbp)
	cmpl	$47, -4(%rbp)
	jg	.L2
	movl	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	in, .-in
	.section	.rodata
.LC0:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	jmp	.L5
.L12:
	movl	$0, %eax
	call	in
	movl	%eax, -20(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -16(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -12(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -8(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -40(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -36(%rbp)
	movl	$0, %eax
	call	in
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jl	.L6
	movl	-8(%rbp), %eax
	imull	-4(%rbp), %eax
	movl	%eax, %edx
	movl	-20(%rbp), %eax
	imull	-36(%rbp), %eax
	addl	%eax, %edx
	movl	-24(%rbp), %eax
	imull	-40(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -28(%rbp)
	jmp	.L7
.L6:
	movl	-16(%rbp), %eax
	imull	-4(%rbp), %eax
	movl	%eax, %edx
	movl	-20(%rbp), %eax
	imull	-36(%rbp), %eax
	addl	%eax, %edx
	movl	-24(%rbp), %eax
	imull	-40(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -28(%rbp)
	movl	-12(%rbp), %eax
	subl	-4(%rbp), %eax
	movl	%eax, -32(%rbp)
	movl	-32(%rbp), %eax
	cmpl	-36(%rbp), %eax
	jg	.L8
	movl	-32(%rbp), %eax
	subl	%eax, -36(%rbp)
	movl	$0, -32(%rbp)
	jmp	.L9
.L8:
	movl	-36(%rbp), %eax
	subl	%eax, -32(%rbp)
	movl	$0, -36(%rbp)
.L9:
	movl	-32(%rbp), %eax
	cmpl	-40(%rbp), %eax
	jg	.L10
	movl	-32(%rbp), %eax
	subl	%eax, -40(%rbp)
	jmp	.L11
.L10:
	movl	-40(%rbp), %eax
	subl	%eax, -32(%rbp)
	movl	$0, -40(%rbp)
.L11:
	movl	-8(%rbp), %eax
	imull	-12(%rbp), %eax
	movl	%eax, %edx
	movl	-20(%rbp), %eax
	imull	-36(%rbp), %eax
	addl	%eax, %edx
	movl	-24(%rbp), %eax
	imull	-40(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -32(%rbp)
	movl	-28(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jle	.L7
	movl	-32(%rbp), %eax
	movl	%eax, -28(%rbp)
.L7:
	movl	-28(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L5:
	movl	$0, %eax
	call	in
	movl	%eax, -24(%rbp)
	cmpl	$0, -24(%rbp)
	jne	.L12
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
