// File: /workspace/github_c_makefile_star2_O2/wjmelements[P]evm/evm.c
// Function: assemble
static void assemble(const char *contents) {
    op_t *programStart = &ops[CONSTRUCTOR_OFFSET];
    uint32_t programLength = 0;
    scanInit();
    for (; scanValid(&contents); programLength++) {
        if (programLength > (PROGRAM_BUFFER_LENGTH - CONSTRUCTOR_OFFSET)) {
            fprintf(stderr, "Program size exceeds limit; terminating");
            break;
        }
        programStart[programLength] = scanNextOp(&contents);
    }
    scanFinalize(programStart, &programLength);
    if (labelJumpdests) {
        fprintLabels(stdout);
        return;
    }
    if (wrapConstructor) {
        if (programLength < 0x20) {
            // PUSHx<>3d5260xx60xxf3
            programStart -= 1;
            *programStart = (PUSH1 - 1) + programLength;
            *((uint32_t *)(programStart + programLength + 1)) = 0x0060523d + (programLength << 24);
            *((uint32_t *)(programStart + programLength + 5)) = 0xf30060 + ((32 - programLength) << 8);
            programLength += 8;
        } else if (programLength == 0x20) {
            // 7f<>3d5260203df3
            programStart -= 1;
            *programStart = PUSH32;
            *((uint32_t *)(programStart + programLength + 1)) = 0x2060523d;
            *((uint16_t *)(programStart + programLength + 5)) = 0xf33d;
            programLength += 7;
        } else {
            programStart -= 4;
            *((uint32_t *)programStart) = 0xf33d393d;
            if (programLength < 0x100) {
                // 60xx8060093d393df3<>
                programStart -= 3;
                *((uint32_t *)programStart) = 0x3d096080;
                programStart -= 2;
                *((uint16_t *)programStart) = 0x0060 | programLength << 8;
                programLength += 9;
            } else if (programLength < 0x10000) {
                // 61xxxx80600a3d393df3<>
                programStart -= 3;
                *((uint32_t *)programStart) = 0x3d0a6080;
                programStart -= 3;
                *((uint32_t *)programStart) = 0x80000061 | (programLength & 0xff) << 16 | (programLength & 0xff00);
                programLength += 10;
            }
        }
    }

    for (; programLength--;) printf("%02x", *programStart++);
    putchar('\n');
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
leaq 0x8(%rsp), %rbx
movq %rdi, (%rbx)
andl $0x0, 0x4(%rsp)
xorl %r15d, %r15d
xorl %eax, %eax
callq 0xcc7c
leaq 0x13026(%rip), %r14     # 0x16a30
movq %rbx, %rdi
callq 0xccab
testl %eax, %eax
je 0x3a55
cmpl $0x7001, %r15d          # imm = 0x7001
jae 0x3a39
movq %rbx, %rdi
callq 0xcfa2
movb %al, 0x1000(%r15,%r14)
incq %r15
movl %r15d, 0x4(%rsp)
jmp 0x3a0a
movq 0x125b8(%rip), %rax     # 0x15ff8
movq (%rax), %rcx
leaq 0xb793(%rip), %rdi      # 0xf1dd
pushq $0x27
popq %rsi
pushq $0x1
popq %rdx
callq 0x3290
leaq 0x13fd4(%rip), %rbx     # 0x17a30
leaq 0x4(%rsp), %rsi
movq %rbx, %rdi
callq 0xd458
cmpb $0x1, 0x12fa0(%rip)     # 0x16a10
jne 0x3a86
movq 0x1254f(%rip), %rax     # 0x15fc8
movq (%rax), %rdi
callq 0xd673
jmp 0x3bb2
cmpb $0x1, 0x12f7b(%rip)     # 0x16a08
jne 0x3b8a
movl 0x4(%rsp), %eax
cmpq $0x1f, %rax
ja 0x3ae0
leal 0x5f(%rax), %ecx
movb %cl, 0x13f89(%rip)      # 0x17a2f
leaq 0x13f82(%rip), %rbx     # 0x17a2f
movl %eax, %ecx
shll $0x18, %ecx
orl $0x60523d, %ecx         # imm = 0x60523D
movl %ecx, 0x1000(%rax,%r14)
movl %eax, %ecx
shll $0x8, %ecx
movl $0xf32060, %edx         # imm = 0xF32060
subl %ecx, %edx
movl %edx, 0x1004(%rax,%r14)
addl $0x8, %eax
movl %eax, 0x4(%rsp)
jmp 0x3b8a
cmpl $0x20, %eax
jne 0x3b10
movb $0x7f, 0x13f43(%rip)    # 0x17a2f
leaq 0x13f3c(%rip), %rbx     # 0x17a2f
movl $0x2060523d, 0x13f53(%rip) # imm = 0x2060523D
movw $0xf33d, 0x13f4e(%rip)  # imm = 0xF33D
movl $0x27, 0x4(%rsp)
jmp 0x3b8a
movl $0xf33d393d, 0x13f12(%rip) # imm = 0xF33D393D
cmpl $0xff, %eax
ja 0x3b46
movl $0x3d096080, 0x13efe(%rip) # imm = 0x3D096080
movl %eax, %ecx
shll $0x8, %ecx
orl $0x60, %ecx
movw %cx, 0x13eed(%rip)      # 0x17a27
leaq 0x13ee6(%rip), %rbx     # 0x17a27
addl $0x9, %eax
jmp 0x3b7d
cmpl $0xffff, %eax           # imm = 0xFFFF
ja 0x3b83
movl $0x3d0a6080, 0x13ed2(%rip) # imm = 0x3D0A6080
movzbl %al, %ecx
shll $0x10, %ecx
movl %eax, %edx
andl $0xff00, %edx           # imm = 0xFF00
addl %edx, %ecx
addl $0x80000061, %ecx       # imm = 0x80000061
movl %ecx, 0x13eb3(%rip)     # 0x17a26
leaq 0x13eac(%rip), %rbx     # 0x17a26
addl $0xa, %eax
movl %eax, 0x4(%rsp)
jmp 0x3b8a
leaq 0x13ea2(%rip), %rbx     # 0x17a2c
leaq 0xb7ed(%rip), %r14      # 0xf37e
subl $0x1, 0x4(%rsp)
jb 0x3baa
movzbl (%rbx), %esi
incq %rbx
movq %r14, %rdi
xorl %eax, %eax
callq 0x3100
jmp 0x3b91
pushq $0xa
popq %rdi
callq 0x3050
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq