// File: /workspace/github_c_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x48, %rsp
movaps 0x258f(%rip), %xmm0     # 0x5010
leaq 0x20(%rsp), %rdi
movaps %xmm0, (%rdi)
movaps %xmm0, 0x10(%rdi)
movq %rsp, %rbx
movl $0x80, %esi
movq %rbx, %rdx
callq 0x45e6
cmpq $0x0, (%rbx)
jne 0x2c1c
cmpq $0x0, 0x8(%rsp)
jne 0x2c3b
movabsq $0x7777777777777777, %r14 # imm = 0x7777777777777777
cmpq %r14, 0x10(%rsp)
jne 0x2c5a
cmpq %r14, 0x18(%rsp)
jne 0x2c79
leaq 0x20(%rsp), %rdi
movq %rsp, %rbx
movl $0xc0, %esi
movq %rbx, %rdx
callq 0x45e6
cmpq $0x0, (%rbx)
jne 0x2c98
cmpq %r14, 0x8(%rsp)
jne 0x2cb7
cmpq %r14, 0x10(%rsp)
jne 0x2cd6
cmpq %r14, 0x18(%rsp)
jne 0x2cf5
leaq 0x20(%rsp), %rdi
movq %rsp, %rbx
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x45e6
cmpq $0x77, (%rbx)
jne 0x2d14
cmpq %r14, 0x8(%rsp)
jne 0x2d33
cmpq %r14, 0x10(%rsp)
jne 0x2d52
cmpq %r14, 0x18(%rsp)
jne 0x2d71
leaq 0x20(%rsp), %rdi
movq %rsp, %rbx
xorl %esi, %esi
movq %rbx, %rdx
callq 0x45e6
cmpq $0x0, (%rbx)
jne 0x2d90
cmpq $0x0, 0x8(%rsp)
jne 0x2daf
cmpq $0x0, 0x10(%rsp)
jne 0x2dce
cmpq $0x0, 0x18(%rsp)
jne 0x2ded
leaq 0x20(%rsp), %rdi
movq %rsp, %rbx
movl $0xc7, %esi
movq %rbx, %rdx
callq 0x45e6
cmpq $-0x9, (%rbx)
jne 0x2e0c
cmpq %r14, 0x8(%rsp)
jne 0x2e2b
cmpq %r14, 0x10(%rsp)
jne 0x2e4a
cmpq %r14, 0x18(%rsp)
jne 0x2e69
leaq 0x20(%rsp), %rdi
pushq $0x1
popq %rsi
movq %rsp, %rbx
movq %rbx, %rdx
callq 0x45e6
cmpq $-0x1, (%rbx)
jne 0x2e88
cmpq $-0x1, 0x8(%rsp)
jne 0x2ea7
cmpq $-0x1, 0x10(%rsp)
jne 0x2ec6
cmpq $-0x1, 0x18(%rsp)
jne 0x2ee5
addq $0x48, %rsp
popq %rbx
popq %r14
retq
leaq 0x3267(%rip), %rdi      # 0x5e8a
leaq 0x244d(%rip), %rsi      # 0x5077
leaq 0x326e(%rip), %rcx      # 0x5e9f
movl $0x11c, %edx            # imm = 0x11C
callq 0x1030
leaq 0x3274(%rip), %rdi      # 0x5eb6
leaq 0x242e(%rip), %rsi      # 0x5077
leaq 0x324f(%rip), %rcx      # 0x5e9f
movl $0x11d, %edx            # imm = 0x11D
callq 0x1030
leaq 0x326a(%rip), %rdi      # 0x5ecb
leaq 0x240f(%rip), %rsi      # 0x5077
leaq 0x3230(%rip), %rcx      # 0x5e9f
movl $0x11e, %edx            # imm = 0x11E
callq 0x1030
leaq 0x3271(%rip), %rdi      # 0x5ef1
leaq 0x23f0(%rip), %rsi      # 0x5077
leaq 0x3211(%rip), %rcx      # 0x5e9f
movl $0x11f, %edx            # imm = 0x11F
callq 0x1030
leaq 0x31eb(%rip), %rdi      # 0x5e8a
leaq 0x23d1(%rip), %rsi      # 0x5077
leaq 0x31f2(%rip), %rcx      # 0x5e9f
movl $0x122, %edx            # imm = 0x122
callq 0x1030
leaq 0x3259(%rip), %rdi      # 0x5f17
leaq 0x23b2(%rip), %rsi      # 0x5077
leaq 0x31d3(%rip), %rcx      # 0x5e9f
movl $0x123, %edx            # imm = 0x123
callq 0x1030
leaq 0x31ee(%rip), %rdi      # 0x5ecb
leaq 0x2393(%rip), %rsi      # 0x5077
leaq 0x31b4(%rip), %rcx      # 0x5e9f
movl $0x124, %edx            # imm = 0x124
callq 0x1030
leaq 0x31f5(%rip), %rdi      # 0x5ef1
leaq 0x2374(%rip), %rsi      # 0x5077
leaq 0x3195(%rip), %rcx      # 0x5e9f
movl $0x125, %edx            # imm = 0x125
callq 0x1030
leaq 0x3222(%rip), %rdi      # 0x5f3d
leaq 0x2355(%rip), %rsi      # 0x5077
leaq 0x3176(%rip), %rcx      # 0x5e9f
movl $0x128, %edx            # imm = 0x128
callq 0x1030
leaq 0x31dd(%rip), %rdi      # 0x5f17
leaq 0x2336(%rip), %rsi      # 0x5077
leaq 0x3157(%rip), %rcx      # 0x5e9f
movl $0x129, %edx            # imm = 0x129
callq 0x1030
leaq 0x3172(%rip), %rdi      # 0x5ecb
leaq 0x2317(%rip), %rsi      # 0x5077
leaq 0x3138(%rip), %rcx      # 0x5e9f
movl $0x12a, %edx            # imm = 0x12A
callq 0x1030
leaq 0x3179(%rip), %rdi      # 0x5ef1
leaq 0x22f8(%rip), %rsi      # 0x5077
leaq 0x3119(%rip), %rcx      # 0x5e9f
movl $0x12b, %edx            # imm = 0x12B
callq 0x1030
leaq 0x31be(%rip), %rdi      # 0x5f55
leaq 0x22d9(%rip), %rsi      # 0x5077
leaq 0x30fa(%rip), %rcx      # 0x5e9f
movl $0x12f, %edx            # imm = 0x12F
callq 0x1030
leaq 0x31c5(%rip), %rdi      # 0x5f7b
leaq 0x22ba(%rip), %rsi      # 0x5077
leaq 0x30db(%rip), %rcx      # 0x5e9f
movl $0x130, %edx            # imm = 0x130
callq 0x1030
leaq 0x31cc(%rip), %rdi      # 0x5fa1
leaq 0x229b(%rip), %rsi      # 0x5077
leaq 0x30bc(%rip), %rcx      # 0x5e9f
movl $0x131, %edx            # imm = 0x131
callq 0x1030
leaq 0x31d3(%rip), %rdi      # 0x5fc7
leaq 0x227c(%rip), %rsi      # 0x5077
leaq 0x309d(%rip), %rcx      # 0x5e9f
movl $0x132, %edx            # imm = 0x132
callq 0x1030
leaq 0x31da(%rip), %rdi      # 0x5fed
leaq 0x225d(%rip), %rsi      # 0x5077
leaq 0x307e(%rip), %rcx      # 0x5e9f
movl $0x136, %edx            # imm = 0x136
callq 0x1030
leaq 0x30e5(%rip), %rdi      # 0x5f17
leaq 0x223e(%rip), %rsi      # 0x5077
leaq 0x305f(%rip), %rcx      # 0x5e9f
movl $0x137, %edx            # imm = 0x137
callq 0x1030
leaq 0x307a(%rip), %rdi      # 0x5ecb
leaq 0x221f(%rip), %rsi      # 0x5077
leaq 0x3040(%rip), %rcx      # 0x5e9f
movl $0x138, %edx            # imm = 0x138
callq 0x1030
leaq 0x3081(%rip), %rdi      # 0x5ef1
leaq 0x2200(%rip), %rsi      # 0x5077
leaq 0x3021(%rip), %rcx      # 0x5e9f
movl $0x139, %edx            # imm = 0x139
callq 0x1030
leaq 0x3184(%rip), %rdi      # 0x6013
leaq 0x21e1(%rip), %rsi      # 0x5077
leaq 0x3002(%rip), %rcx      # 0x5e9f
movl $0x13c, %edx            # imm = 0x13C
callq 0x1030
leaq 0x318b(%rip), %rdi      # 0x6039
leaq 0x21c2(%rip), %rsi      # 0x5077
leaq 0x2fe3(%rip), %rcx      # 0x5e9f
movl $0x13d, %edx            # imm = 0x13D
callq 0x1030
leaq 0x3192(%rip), %rdi      # 0x605f
leaq 0x21a3(%rip), %rsi      # 0x5077
leaq 0x2fc4(%rip), %rcx      # 0x5e9f
movl $0x13e, %edx            # imm = 0x13E
callq 0x1030
leaq 0x3199(%rip), %rdi      # 0x6085
leaq 0x2184(%rip), %rsi      # 0x5077
leaq 0x2fa5(%rip), %rcx      # 0x5e9f
movl $0x13f, %edx            # imm = 0x13F
callq 0x1030