// File: /workspace/github_cpp_makefile_star2_O1/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, %ax
movw %ax, 0x20(%r14)
movw $0x1, %r12w
xorl %r13d, %r13d
movb %r13b, 0x22(%r14)
leaq -0x120(%rbp), %r15
movq %r14, %rdi
movq %r15, %rdx
callq 0x54ea2
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), %r12
leaq -0x60(%rbp), %rdx
movl $0xff, %edi
movq %r12, %rsi
callq 0x57118
movl $0xff, %esi
movq %r15, %rdi
xorl %edx, %edx
callq 0x5717c
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%r12)
movaps %xmm0, (%r12)
movw $0x1, %ax
movw %ax, 0x20(%r12)
movb %r13b, 0x22(%r12)
movzwl 0x20(%r14), %edx
movw %dx, 0x20(%r12)
shll $0x3, %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0xe430
movb 0x22(%r14), %al
movb %al, 0x22(%r12)
leaq -0x60(%rbp), %r14
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x5741e
movq %rbx, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0xe730
movq %rax, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
movw $0x1, %ax
movw %ax, 0x20(%r14)
movb %r13b, 0x22(%r14)
cmpq $0x100, %rbx            # imm = 0x100
jl 0x2a1b6
cmpw $0x1, -0xd0(%rbp)
setne %al
cmpq $0x0, -0xf0(%rbp)
setne %cl
orb %al, %cl
movw $0x1, -0x40(%rbp)
movzbl %cl, %eax
movq %rax, -0x60(%rbp)
movb %al, -0x3e(%rbp)
jmp 0x2a2ba
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 0x2a2ba
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 0x57118
movl $0x1, %esi
movq %r12, %rdi
xorl %edx, %edx
callq 0x57a1e
xorps %xmm0, %xmm0
movaps %xmm0, -0xb0(%rbp)
movaps %xmm0, -0xc0(%rbp)
movb $0x0, -0x9e(%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 0x57721
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
jg 0x2a206
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 0x56958
leaq -0x90(%rbp), %r14
leaq -0x29(%rbp), %rcx
movq %r14, %rdi
movq %rbx, %rsi
movl $0x8, %edx
callq 0x60808
movq 0x8(%r14), %rbx
testq %rbx, %rbx
je 0x2a32e
movq -0x90(%rbp), %r14
xorl %r15d, %r15d
movsbl (%r14,%r15), %edi
callq 0xe7a0
movb %al, (%r14,%r15)
incq %r15
cmpq %r15, %rbx
jne 0x2a318
movq %fs:0x0, %rax
leaq -0xa0(%rax), %rbx
leaq -0x9e(%rax), %rdi
leaq -0x80(%rbp), %r15
movq -0x10(%r15), %r14
movq %r14, %rsi
callq 0xe4c0
cmpq %r15, %r14
je 0x2a369
movq -0x80(%rbp), %rsi
incq %rsi
movq %r14, %rdi
callq 0xe530
movq %rbx, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq