// File: /workspace/github_c_makefile_star2_O0/wjmelements[P]evm/tst/uint256.c
// Function: test_signextend
void test_signextend() {
    // first, test positive sign extension
    uint256_t a, b;
    UPPER(UPPER(a)) = 0x7777777777777777;
    LOWER(UPPER(a)) = 0x7777777777777777;
    UPPER(LOWER(a)) = 0x7777777777777777;
    LOWER(LOWER(a)) = 0x7777777777777777;

    signextend256(&a, 128, &b);
    assert(UPPER(UPPER(b)) == 0);
    assert(LOWER(UPPER(b)) == 0);
    assert(UPPER(LOWER(b)) == 0x7777777777777777);
    assert(LOWER(LOWER(b)) == 0x7777777777777777);

    signextend256(&a, 192, &b);
    assert(UPPER(UPPER(b)) == 0);
    assert(LOWER(UPPER(b)) == 0x7777777777777777);
    assert(UPPER(LOWER(b)) == 0x7777777777777777);
    assert(LOWER(LOWER(b)) == 0x7777777777777777);

    signextend256(&a, 200, &b);
    assert(UPPER(UPPER(b)) == 0x77);
    assert(LOWER(UPPER(b)) == 0x7777777777777777);
    assert(UPPER(LOWER(b)) == 0x7777777777777777);
    assert(LOWER(LOWER(b)) == 0x7777777777777777);

    // NOTE unsure if this is the correct specification
    signextend256(&a, 0, &b);
    assert(UPPER(UPPER(b)) == 0x0000000000000000);
    assert(LOWER(UPPER(b)) == 0x0000000000000000);
    assert(UPPER(LOWER(b)) == 0x0000000000000000);
    assert(LOWER(LOWER(b)) == 0x0000000000000000);

    // next, test negative sign extension
    signextend256(&a, 199, &b);
    assert(UPPER(UPPER(b)) == 0xfffffffffffffff7);
    assert(LOWER(UPPER(b)) == 0x7777777777777777);
    assert(UPPER(LOWER(b)) == 0x7777777777777777);
    assert(LOWER(LOWER(b)) == 0x7777777777777777);

    signextend256(&a, 1, &b);
    assert(UPPER(UPPER(b)) == 0xffffffffffffffff);
    assert(LOWER(UPPER(b)) == 0xffffffffffffffff);
    assert(UPPER(LOWER(b)) == 0xffffffffffffffff);
    assert(LOWER(LOWER(b)) == 0xffffffffffffffff);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movabsq $0x7777777777777777, %rax # imm = 0x7777777777777777
movq %rax, -0x20(%rbp)
movabsq $0x7777777777777777, %rax # imm = 0x7777777777777777
movq %rax, -0x18(%rbp)
movabsq $0x7777777777777777, %rax # imm = 0x7777777777777777
movq %rax, -0x10(%rbp)
movabsq $0x7777777777777777, %rax # imm = 0x7777777777777777
movq %rax, -0x8(%rbp)
leaq -0x20(%rbp), %rdi
movl $0x80, %esi
leaq -0x40(%rbp), %rdx
callq 0x5980
cmpq $0x0, -0x40(%rbp)
jne 0x2a8b
jmp 0x2aaa
leaq 0x53bc(%rip), %rdi      # 0x7e4e
leaq 0x45a2(%rip), %rsi      # 0x703b
movl $0x11c, %edx            # imm = 0x11C
leaq 0x53be(%rip), %rcx      # 0x7e63
callq 0x1030
cmpq $0x0, -0x38(%rbp)
jne 0x2ab3
jmp 0x2ad2
leaq 0x53c0(%rip), %rdi      # 0x7e7a
leaq 0x457a(%rip), %rsi      # 0x703b
movl $0x11d, %edx            # imm = 0x11D
leaq 0x5396(%rip), %rcx      # 0x7e63
callq 0x1030
movabsq $0x7777777777777777, %rax # imm = 0x7777777777777777
cmpq %rax, -0x30(%rbp)
jne 0x2ae4
jmp 0x2b03
leaq 0x53a4(%rip), %rdi      # 0x7e8f
leaq 0x4549(%rip), %rsi      # 0x703b
movl $0x11e, %edx            # imm = 0x11E
leaq 0x5365(%rip), %rcx      # 0x7e63
callq 0x1030
movabsq $0x7777777777777777, %rax # imm = 0x7777777777777777
cmpq %rax, -0x28(%rbp)
jne 0x2b15
jmp 0x2b34
leaq 0x5399(%rip), %rdi      # 0x7eb5
leaq 0x4518(%rip), %rsi      # 0x703b
movl $0x11f, %edx            # imm = 0x11F
leaq 0x5334(%rip), %rcx      # 0x7e63
callq 0x1030
leaq -0x20(%rbp), %rdi
movl $0xc0, %esi
leaq -0x40(%rbp), %rdx
callq 0x5980
cmpq $0x0, -0x40(%rbp)
jne 0x2b4f
jmp 0x2b6e
leaq 0x52f8(%rip), %rdi      # 0x7e4e
leaq 0x44de(%rip), %rsi      # 0x703b
movl $0x122, %edx            # imm = 0x122
leaq 0x52fa(%rip), %rcx      # 0x7e63
callq 0x1030
movabsq $0x7777777777777777, %rax # imm = 0x7777777777777777
cmpq %rax, -0x38(%rbp)
jne 0x2b80
jmp 0x2b9f
leaq 0x5354(%rip), %rdi      # 0x7edb
leaq 0x44ad(%rip), %rsi      # 0x703b
movl $0x123, %edx            # imm = 0x123
leaq 0x52c9(%rip), %rcx      # 0x7e63
callq 0x1030
movabsq $0x7777777777777777, %rax # imm = 0x7777777777777777
cmpq %rax, -0x30(%rbp)
jne 0x2bb1
jmp 0x2bd0
leaq 0x52d7(%rip), %rdi      # 0x7e8f
leaq 0x447c(%rip), %rsi      # 0x703b
movl $0x124, %edx            # imm = 0x124
leaq 0x5298(%rip), %rcx      # 0x7e63
callq 0x1030
movabsq $0x7777777777777777, %rax # imm = 0x7777777777777777
cmpq %rax, -0x28(%rbp)
jne 0x2be2
jmp 0x2c01
leaq 0x52cc(%rip), %rdi      # 0x7eb5
leaq 0x444b(%rip), %rsi      # 0x703b
movl $0x125, %edx            # imm = 0x125
leaq 0x5267(%rip), %rcx      # 0x7e63
callq 0x1030
leaq -0x20(%rbp), %rdi
movl $0xc8, %esi
leaq -0x40(%rbp), %rdx
callq 0x5980
cmpq $0x77, -0x40(%rbp)
jne 0x2c1c
jmp 0x2c3b
leaq 0x52de(%rip), %rdi      # 0x7f01
leaq 0x4411(%rip), %rsi      # 0x703b
movl $0x128, %edx            # imm = 0x128
leaq 0x522d(%rip), %rcx      # 0x7e63
callq 0x1030
movabsq $0x7777777777777777, %rax # imm = 0x7777777777777777
cmpq %rax, -0x38(%rbp)
jne 0x2c4d
jmp 0x2c6c
leaq 0x5287(%rip), %rdi      # 0x7edb
leaq 0x43e0(%rip), %rsi      # 0x703b
movl $0x129, %edx            # imm = 0x129
leaq 0x51fc(%rip), %rcx      # 0x7e63
callq 0x1030
movabsq $0x7777777777777777, %rax # imm = 0x7777777777777777
cmpq %rax, -0x30(%rbp)
jne 0x2c7e
jmp 0x2c9d
leaq 0x520a(%rip), %rdi      # 0x7e8f
leaq 0x43af(%rip), %rsi      # 0x703b
movl $0x12a, %edx            # imm = 0x12A
leaq 0x51cb(%rip), %rcx      # 0x7e63
callq 0x1030
movabsq $0x7777777777777777, %rax # imm = 0x7777777777777777
cmpq %rax, -0x28(%rbp)
jne 0x2caf
jmp 0x2cce
leaq 0x51ff(%rip), %rdi      # 0x7eb5
leaq 0x437e(%rip), %rsi      # 0x703b
movl $0x12b, %edx            # imm = 0x12B
leaq 0x519a(%rip), %rcx      # 0x7e63
callq 0x1030
leaq -0x20(%rbp), %rdi
xorl %esi, %esi
leaq -0x40(%rbp), %rdx
callq 0x5980
cmpq $0x0, -0x40(%rbp)
jne 0x2ce6
jmp 0x2d05
leaq 0x522c(%rip), %rdi      # 0x7f19
leaq 0x4347(%rip), %rsi      # 0x703b
movl $0x12f, %edx            # imm = 0x12F
leaq 0x5163(%rip), %rcx      # 0x7e63
callq 0x1030
cmpq $0x0, -0x38(%rbp)
jne 0x2d0e
jmp 0x2d2d
leaq 0x522a(%rip), %rdi      # 0x7f3f
leaq 0x431f(%rip), %rsi      # 0x703b
movl $0x130, %edx            # imm = 0x130
leaq 0x513b(%rip), %rcx      # 0x7e63
callq 0x1030
cmpq $0x0, -0x30(%rbp)
jne 0x2d36
jmp 0x2d55
leaq 0x5228(%rip), %rdi      # 0x7f65
leaq 0x42f7(%rip), %rsi      # 0x703b
movl $0x131, %edx            # imm = 0x131
leaq 0x5113(%rip), %rcx      # 0x7e63
callq 0x1030
cmpq $0x0, -0x28(%rbp)
jne 0x2d5e
jmp 0x2d7d
leaq 0x5226(%rip), %rdi      # 0x7f8b
leaq 0x42cf(%rip), %rsi      # 0x703b
movl $0x132, %edx            # imm = 0x132
leaq 0x50eb(%rip), %rcx      # 0x7e63
callq 0x1030
leaq -0x20(%rbp), %rdi
movl $0xc7, %esi
leaq -0x40(%rbp), %rdx
callq 0x5980
cmpq $-0x9, -0x40(%rbp)
jne 0x2d98
jmp 0x2db7
leaq 0x5212(%rip), %rdi      # 0x7fb1
leaq 0x4295(%rip), %rsi      # 0x703b
movl $0x136, %edx            # imm = 0x136
leaq 0x50b1(%rip), %rcx      # 0x7e63
callq 0x1030
movabsq $0x7777777777777777, %rax # imm = 0x7777777777777777
cmpq %rax, -0x38(%rbp)
jne 0x2dc9
jmp 0x2de8
leaq 0x510b(%rip), %rdi      # 0x7edb
leaq 0x4264(%rip), %rsi      # 0x703b
movl $0x137, %edx            # imm = 0x137
leaq 0x5080(%rip), %rcx      # 0x7e63
callq 0x1030
movabsq $0x7777777777777777, %rax # imm = 0x7777777777777777
cmpq %rax, -0x30(%rbp)
jne 0x2dfa
jmp 0x2e19
leaq 0x508e(%rip), %rdi      # 0x7e8f
leaq 0x4233(%rip), %rsi      # 0x703b
movl $0x138, %edx            # imm = 0x138
leaq 0x504f(%rip), %rcx      # 0x7e63
callq 0x1030
movabsq $0x7777777777777777, %rax # imm = 0x7777777777777777
cmpq %rax, -0x28(%rbp)
jne 0x2e2b
jmp 0x2e4a
leaq 0x5083(%rip), %rdi      # 0x7eb5
leaq 0x4202(%rip), %rsi      # 0x703b
movl $0x139, %edx            # imm = 0x139
leaq 0x501e(%rip), %rcx      # 0x7e63
callq 0x1030
leaq -0x20(%rbp), %rdi
movl $0x1, %esi
leaq -0x40(%rbp), %rdx
callq 0x5980
cmpq $-0x1, -0x40(%rbp)
jne 0x2e65
jmp 0x2e84
leaq 0x516b(%rip), %rdi      # 0x7fd7
leaq 0x41c8(%rip), %rsi      # 0x703b
movl $0x13c, %edx            # imm = 0x13C
leaq 0x4fe4(%rip), %rcx      # 0x7e63
callq 0x1030
cmpq $-0x1, -0x38(%rbp)
jne 0x2e8d
jmp 0x2eac
leaq 0x5169(%rip), %rdi      # 0x7ffd
leaq 0x41a0(%rip), %rsi      # 0x703b
movl $0x13d, %edx            # imm = 0x13D
leaq 0x4fbc(%rip), %rcx      # 0x7e63
callq 0x1030
cmpq $-0x1, -0x30(%rbp)
jne 0x2eb5
jmp 0x2ed4
leaq 0x5167(%rip), %rdi      # 0x8023
leaq 0x4178(%rip), %rsi      # 0x703b
movl $0x13e, %edx            # imm = 0x13E
leaq 0x4f94(%rip), %rcx      # 0x7e63
callq 0x1030
cmpq $-0x1, -0x28(%rbp)
jne 0x2edd
jmp 0x2efc
leaq 0x5165(%rip), %rdi      # 0x8049
leaq 0x4150(%rip), %rsi      # 0x703b
movl $0x13f, %edx            # imm = 0x13F
leaq 0x4f6c(%rip), %rcx      # 0x7e63
callq 0x1030
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)