// File: /workspace/github_c_makefile_star2_O1/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 %r14
pushq %rbx
subq $0x18, %rsp
leaq 0x10(%rsp), %rbx
movq %rdi, (%rbx)
movl $0x0, 0xc(%rsp)
xorl %eax, %eax
callq 0xfe60
movq %rbx, %rdi
callq 0xfe95
testl %eax, %eax
je 0x4b4b
leaq 0x10(%rsp), %rbx
leaq 0x14f1a(%rip), %r14     # 0x19a30
cmpl $0x7001, 0xc(%rsp)      # imm = 0x7001
jae 0x4c53
movq %rbx, %rdi
callq 0x1025e
movl 0xc(%rsp), %ecx
movb %al, 0x1000(%rcx,%r14)
leal 0x1(%rcx), %eax
movl %eax, 0xc(%rsp)
movq %rbx, %rdi
callq 0xfe95
testl %eax, %eax
jne 0x4b16
leaq 0x15ede(%rip), %rbx     # 0x1aa30
leaq 0xc(%rsp), %rsi
movq %rbx, %rdi
callq 0x1065d
cmpb $0x1, 0x14eaa(%rip)     # 0x19a10
jne 0x4b7c
movq 0x14459(%rip), %rax     # 0x18fc8
movq (%rax), %rdi
callq 0x1088b
jmp 0x4ccf
cmpb $0x1, 0x14e85(%rip)     # 0x19a08
jne 0x4ca0
movl 0xc(%rsp), %eax
cmpq $0x1f, %rax
ja 0x4bdd
movl %eax, %ecx
addb $0x5f, %cl
movb %cl, 0x15e91(%rip)      # 0x1aa2f
leaq 0x15e8a(%rip), %rbx     # 0x1aa2f
leaq 0x14e84(%rip), %rcx     # 0x19a30
movl %eax, %edx
shll $0x18, %edx
orl $0x60523d, %edx         # imm = 0x60523D
movl %edx, 0x1000(%rax,%rcx)
movl %eax, %edx
shll $0x8, %edx
movl $0xf32060, %esi         # imm = 0xF32060
subl %edx, %esi
movl %esi, 0x1004(%rax,%rcx)
addl $0x8, %eax
movl %eax, 0xc(%rsp)
jmp 0x4ca0
cmpl $0x20, %eax
jne 0x4c19
movb $0x7f, 0x15e46(%rip)    # 0x1aa2f
leaq 0x15e3f(%rip), %rbx     # 0x1aa2f
leaq 0x14e39(%rip), %rcx     # 0x19a30
movl $0x2060523d, 0x1000(%rax,%rcx) # imm = 0x2060523D
movw $0xf33d, 0x1004(%rax,%rcx) # imm = 0xF33D
movl $0x27, 0xc(%rsp)
jmp 0x4ca0
movl $0xf33d393d, 0x15e09(%rip) # imm = 0xF33D393D
cmpl $0xff, %eax
ja 0x4c5d
movl $0x3d096080, 0x15df5(%rip) # imm = 0x3D096080
movl %eax, %ecx
shll $0x8, %ecx
orl $0x60, %ecx
movw %cx, 0x15de4(%rip)      # 0x1aa27
leaq 0x15ddd(%rip), %rbx     # 0x1aa27
addl $0x9, %eax
movl %eax, 0xc(%rsp)
jmp 0x4ca0
callq 0x33fa
jmp 0x4b4b
cmpl $0xffff, %eax           # imm = 0xFFFF
ja 0x4c99
movl $0x3d0a6080, 0x15dbb(%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, 0x15d9c(%rip)     # 0x1aa26
leaq 0x15d95(%rip), %rbx     # 0x1aa26
addl $0xa, %eax
jmp 0x4bd4
leaq 0x15d8c(%rip), %rbx     # 0x1aa2c
subl $0x1, 0xc(%rsp)
jb 0x4cc5
leaq 0xd6d0(%rip), %r14      # 0x1237e
movzbl (%rbx), %esi
incq %rbx
movq %r14, %rdi
xorl %eax, %eax
callq 0x3100
subl $0x1, 0xc(%rsp)
jae 0x4cae
movl $0xa, %edi
callq 0x3050
addq $0x18, %rsp
popq %rbx
popq %r14
retq
nop