// File: /workspace/github_c_makefile_star2_O1/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 0x34ba(%rip), %xmm0     # 0x6010
leaq 0x20(%rsp), %rdi
movaps %xmm0, (%rdi)
movaps %xmm0, 0x10(%rdi)
movq %rsp, %rbx
movl $0x80, %esi
movq %rbx, %rdx
callq 0x4993
cmpq $0x0, (%rbx)
jne 0x2cf3
cmpq $0x0, 0x8(%rsp)
jne 0x2d12
movabsq $0x7777777777777777, %r14 # imm = 0x7777777777777777
cmpq %r14, 0x10(%rsp)
jne 0x2d31
cmpq %r14, 0x18(%rsp)
jne 0x2d50
leaq 0x20(%rsp), %rdi
movq %rsp, %rbx
movl $0xc0, %esi
movq %rbx, %rdx
callq 0x4993
cmpq $0x0, (%rbx)
jne 0x2d6f
cmpq %r14, 0x8(%rsp)
jne 0x2d8e
cmpq %r14, 0x10(%rsp)
jne 0x2dad
cmpq %r14, 0x18(%rsp)
jne 0x2dcc
leaq 0x20(%rsp), %rdi
movq %rsp, %rbx
movl $0xc8, %esi
movq %rbx, %rdx
callq 0x4993
cmpq $0x77, (%rbx)
jne 0x2deb
cmpq %r14, 0x8(%rsp)
jne 0x2e0a
cmpq %r14, 0x10(%rsp)
jne 0x2e29
cmpq %r14, 0x18(%rsp)
jne 0x2e48
leaq 0x20(%rsp), %rdi
movq %rsp, %rbx
xorl %esi, %esi
movq %rbx, %rdx
callq 0x4993
cmpq $0x0, (%rbx)
jne 0x2e67
cmpq $0x0, 0x8(%rsp)
jne 0x2e86
cmpq $0x0, 0x10(%rsp)
jne 0x2ea5
cmpq $0x0, 0x18(%rsp)
jne 0x2ec4
leaq 0x20(%rsp), %rdi
movq %rsp, %rbx
movl $0xc7, %esi
movq %rbx, %rdx
callq 0x4993
cmpq $-0x9, (%rbx)
jne 0x2ee3
cmpq %r14, 0x8(%rsp)
jne 0x2f02
cmpq %r14, 0x10(%rsp)
jne 0x2f21
cmpq %r14, 0x18(%rsp)
jne 0x2f40
leaq 0x20(%rsp), %rdi
movq %rsp, %rbx
movl $0x1, %esi
movq %rbx, %rdx
callq 0x4993
cmpq $-0x1, (%rbx)
jne 0x2f5f
cmpq $-0x1, 0x8(%rsp)
jne 0x2f7e
cmpq $-0x1, 0x10(%rsp)
jne 0x2f9d
cmpq $-0x1, 0x18(%rsp)
jne 0x2fbc
addq $0x48, %rsp
popq %rbx
popq %r14
retq
leaq 0x4190(%rip), %rdi      # 0x6e8a
leaq 0x3376(%rip), %rsi      # 0x6077
leaq 0x4197(%rip), %rcx      # 0x6e9f
movl $0x11c, %edx            # imm = 0x11C
callq 0x1030
leaq 0x419d(%rip), %rdi      # 0x6eb6
leaq 0x3357(%rip), %rsi      # 0x6077
leaq 0x4178(%rip), %rcx      # 0x6e9f
movl $0x11d, %edx            # imm = 0x11D
callq 0x1030
leaq 0x4193(%rip), %rdi      # 0x6ecb
leaq 0x3338(%rip), %rsi      # 0x6077
leaq 0x4159(%rip), %rcx      # 0x6e9f
movl $0x11e, %edx            # imm = 0x11E
callq 0x1030
leaq 0x419a(%rip), %rdi      # 0x6ef1
leaq 0x3319(%rip), %rsi      # 0x6077
leaq 0x413a(%rip), %rcx      # 0x6e9f
movl $0x11f, %edx            # imm = 0x11F
callq 0x1030
leaq 0x4114(%rip), %rdi      # 0x6e8a
leaq 0x32fa(%rip), %rsi      # 0x6077
leaq 0x411b(%rip), %rcx      # 0x6e9f
movl $0x122, %edx            # imm = 0x122
callq 0x1030
leaq 0x4182(%rip), %rdi      # 0x6f17
leaq 0x32db(%rip), %rsi      # 0x6077
leaq 0x40fc(%rip), %rcx      # 0x6e9f
movl $0x123, %edx            # imm = 0x123
callq 0x1030
leaq 0x4117(%rip), %rdi      # 0x6ecb
leaq 0x32bc(%rip), %rsi      # 0x6077
leaq 0x40dd(%rip), %rcx      # 0x6e9f
movl $0x124, %edx            # imm = 0x124
callq 0x1030
leaq 0x411e(%rip), %rdi      # 0x6ef1
leaq 0x329d(%rip), %rsi      # 0x6077
leaq 0x40be(%rip), %rcx      # 0x6e9f
movl $0x125, %edx            # imm = 0x125
callq 0x1030
leaq 0x414b(%rip), %rdi      # 0x6f3d
leaq 0x327e(%rip), %rsi      # 0x6077
leaq 0x409f(%rip), %rcx      # 0x6e9f
movl $0x128, %edx            # imm = 0x128
callq 0x1030
leaq 0x4106(%rip), %rdi      # 0x6f17
leaq 0x325f(%rip), %rsi      # 0x6077
leaq 0x4080(%rip), %rcx      # 0x6e9f
movl $0x129, %edx            # imm = 0x129
callq 0x1030
leaq 0x409b(%rip), %rdi      # 0x6ecb
leaq 0x3240(%rip), %rsi      # 0x6077
leaq 0x4061(%rip), %rcx      # 0x6e9f
movl $0x12a, %edx            # imm = 0x12A
callq 0x1030
leaq 0x40a2(%rip), %rdi      # 0x6ef1
leaq 0x3221(%rip), %rsi      # 0x6077
leaq 0x4042(%rip), %rcx      # 0x6e9f
movl $0x12b, %edx            # imm = 0x12B
callq 0x1030
leaq 0x40e7(%rip), %rdi      # 0x6f55
leaq 0x3202(%rip), %rsi      # 0x6077
leaq 0x4023(%rip), %rcx      # 0x6e9f
movl $0x12f, %edx            # imm = 0x12F
callq 0x1030
leaq 0x40ee(%rip), %rdi      # 0x6f7b
leaq 0x31e3(%rip), %rsi      # 0x6077
leaq 0x4004(%rip), %rcx      # 0x6e9f
movl $0x130, %edx            # imm = 0x130
callq 0x1030
leaq 0x40f5(%rip), %rdi      # 0x6fa1
leaq 0x31c4(%rip), %rsi      # 0x6077
leaq 0x3fe5(%rip), %rcx      # 0x6e9f
movl $0x131, %edx            # imm = 0x131
callq 0x1030
leaq 0x40fc(%rip), %rdi      # 0x6fc7
leaq 0x31a5(%rip), %rsi      # 0x6077
leaq 0x3fc6(%rip), %rcx      # 0x6e9f
movl $0x132, %edx            # imm = 0x132
callq 0x1030
leaq 0x4103(%rip), %rdi      # 0x6fed
leaq 0x3186(%rip), %rsi      # 0x6077
leaq 0x3fa7(%rip), %rcx      # 0x6e9f
movl $0x136, %edx            # imm = 0x136
callq 0x1030
leaq 0x400e(%rip), %rdi      # 0x6f17
leaq 0x3167(%rip), %rsi      # 0x6077
leaq 0x3f88(%rip), %rcx      # 0x6e9f
movl $0x137, %edx            # imm = 0x137
callq 0x1030
leaq 0x3fa3(%rip), %rdi      # 0x6ecb
leaq 0x3148(%rip), %rsi      # 0x6077
leaq 0x3f69(%rip), %rcx      # 0x6e9f
movl $0x138, %edx            # imm = 0x138
callq 0x1030
leaq 0x3faa(%rip), %rdi      # 0x6ef1
leaq 0x3129(%rip), %rsi      # 0x6077
leaq 0x3f4a(%rip), %rcx      # 0x6e9f
movl $0x139, %edx            # imm = 0x139
callq 0x1030
leaq 0x40ad(%rip), %rdi      # 0x7013
leaq 0x310a(%rip), %rsi      # 0x6077
leaq 0x3f2b(%rip), %rcx      # 0x6e9f
movl $0x13c, %edx            # imm = 0x13C
callq 0x1030
leaq 0x40b4(%rip), %rdi      # 0x7039
leaq 0x30eb(%rip), %rsi      # 0x6077
leaq 0x3f0c(%rip), %rcx      # 0x6e9f
movl $0x13d, %edx            # imm = 0x13D
callq 0x1030
leaq 0x40bb(%rip), %rdi      # 0x705f
leaq 0x30cc(%rip), %rsi      # 0x6077
leaq 0x3eed(%rip), %rcx      # 0x6e9f
movl $0x13e, %edx            # imm = 0x13E
callq 0x1030
leaq 0x40c2(%rip), %rdi      # 0x7085
leaq 0x30ad(%rip), %rsi      # 0x6077
leaq 0x3ece(%rip), %rcx      # 0x6e9f
movl $0x13f, %edx            # imm = 0x13F
callq 0x1030