// File: /workspace/github_cpp_makefile_star2_O3/yanniss[P]souffle-num-addon/./num256.cpp
// Function: sar_256
const char* sar_256(const char *x, const char *y) {
    thread_local static char out[STRING_LEN] = {"0x"};
    int256_t my_x(y);
    int256_t minus_zero = ((int256_t) 1) << 255;
    int256_t sign_bit = my_x & minus_zero;
    long my_y = strtol(x, NULL, 16);
    int256_t result;
    if (my_y >= 256) {
      if (sign_bit) result = -1;
      else result = 0;
    } else {  // there must be a better way to implement SAR w/ Boost, but who cares?
      for (result = my_x; my_y > 0; my_y--) {
        result = (result >> 1) | sign_bit;
      }
    }
    uint256_t unsigned_result(result);
    string str_result = unsigned_result.str(32, ios_base::hex);
    transform(str_result.begin(), str_result.end(), str_result.begin(), ::tolower);
    strcpy(out+2, str_result.c_str());
    return out;
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq -0x150(%rbp), %r14
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
movw $0x1, %r12w
movw %r12w, 0x20(%r14)
xorl %r13d, %r13d
movb %r13b, 0x22(%r14)
leaq -0x120(%rbp), %r15
movq %r14, %rdi
movq %r15, %rdx
callq 0x5445a
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r15)
movq $0x0, 0x18(%r15)
movq $0x1, (%r15)
movw %r12w, 0x20(%r15)
movb %r13b, 0x22(%r15)
leaq -0xf0(%rbp), %r15
leaq -0x60(%rbp), %rdx
movl $0xff, %edi
movq %r15, %rsi
callq 0x56696
leaq -0x120(%rbp), %r12
movl $0xff, %esi
movq %r12, %rdi
xorl %edx, %edx
callq 0x566fa
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
movzwl 0x20(%r14), %edx
movw %dx, 0x20(%r15)
shll $0x3, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0xe430
movb 0x22(%r14), %al
movb %al, 0x22(%r15)
leaq -0x60(%rbp), %r14
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5699c
movq %rbx, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0xe730
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
cmpq $0x100, %rax            # imm = 0x100
jl 0x29cbb
cmpw $0x1, -0xd0(%rbp)
movq -0xf0(%rbp), %rax
movw $0x1, -0x40(%rbp)
jne 0x29dbd
testq %rax, %rax
jne 0x29dbd
xorl %eax, %eax
jmp 0x29dc7
movq %rax, %rbx
leaq -0x150(%rbp), %r14
movzwl 0x20(%r14), %edx
leaq -0x60(%rbp), %r15
movw %dx, 0x20(%r15)
shll $0x3, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0xe430
movb 0x22(%r14), %al
movb %al, 0x22(%r15)
testq %rbx, %rbx
jle 0x29dca
incq %rbx
leaq -0xc0(%rbp), %r14
leaq -0x29(%rbp), %r15
leaq -0x90(%rbp), %r12
leaq -0xf0(%rbp), %r13
movaps -0x60(%rbp), %xmm0
movaps -0x50(%rbp), %xmm1
movaps %xmm1, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
movzwl -0x40(%rbp), %eax
movw %ax, -0x70(%rbp)
movb -0x3e(%rbp), %al
movb %al, -0x6e(%rbp)
movl $0x1, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x56696
movl $0x1, %esi
movq %r12, %rdi
xorl %edx, %edx
callq 0x56f92
xorps %xmm0, %xmm0
movaps %xmm0, -0xb0(%rbp)
movaps %xmm0, -0xc0(%rbp)
movzwl -0x70(%rbp), %edx
movw %dx, -0xa0(%rbp)
shll $0x3, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0xe430
movb -0x6e(%rbp), %al
movb %al, -0x9e(%rbp)
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x56c9b
movaps -0xc0(%rbp), %xmm0
movaps -0xb0(%rbp), %xmm1
movaps %xmm0, -0x60(%rbp)
movaps %xmm1, -0x50(%rbp)
movl -0xa1(%rbp), %eax
movl %eax, -0x41(%rbp)
decq %rbx
cmpq $0x1, %rbx
ja 0x29d0e
jmp 0x29dca
movq $0x1, -0x60(%rbp)
movb $0x1, %al
movb %al, -0x3e(%rbp)
xorps %xmm0, %xmm0
leaq -0xc0(%rbp), %rbx
movaps %xmm0, 0x10(%rbx)
movaps %xmm0, (%rbx)
movq $0x1, 0x20(%rbx)
leaq -0x60(%rbp), %rsi
leaq -0x90(%rbp), %rdx
leaq -0x29(%rbp), %rcx
movq %rbx, %rdi
callq 0x55ede
leaq -0x90(%rbp), %r14
leaq -0x29(%rbp), %rcx
movq %r14, %rdi
movq %rbx, %rsi
movl $0x8, %edx
callq 0x5fc4e
movq (%r14), %rbx
movq 0x8(%r14), %r14
testq %r14, %r14
je 0x29e41
xorl %r15d, %r15d
movsbl (%rbx,%r15), %edi
callq 0xe7a0
movb %al, (%rbx,%r15)
incq %r15
cmpq %r15, %r14
jne 0x29e24
movq -0x90(%rbp), %rbx
movq %fs:0x0, %rax
leaq -0xa0(%rax), %r14
leaq -0x9e(%rax), %rdi
movq %rbx, %rsi
callq 0xe4c0
leaq -0x80(%rbp), %rax
cmpq %rax, %rbx
je 0x29e78
movq -0x80(%rbp), %rsi
incq %rsi
movq %rbx, %rdi
callq 0xe530
movq %r14, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq