// File: /workspace/github_cpp_makefile_star2_O2/hzeller[P]FlaschenTaschen-PixelPusher-bridge/pixel-pusher-client.cc
// Function: PixelPusherClient::PixelPusherClient(int, int, char const*, char const*, int, int)
PixelPusherClient::PixelPusherClient(int strip_len, int strips,
                                     const char *pp_host,
                                     const char *pp_port,
                                     int max_transmit_bytes, int brightness)
    : width_(strip_len), height_(strips),
      socket_(OpenPPSocket(pp_host, pp_port)),
      // Each row is one byte longer, because we use the first byte to
      // indicate the strip-index which we use in the
      row_size_(1 + sizeof(Color) * width_),
      rows_per_packet_((max_transmit_bytes - 4) / row_size_),
      packets_needed_((height_ + rows_per_packet_ - 1) / rows_per_packet_),
      brightness_percent_(brightness),
      block_dirty_(new bool[packets_needed_]),
      pixel_buffer_(new char[row_size_ * height_]),
      sequence_number_(0) {
    // Prepare the pixel index at the beginning of each row
    memset(pixel_buffer_, 0, row_size_ * height_);
    for (uint8_t i = 0; i < height_; ++i) {
        pixel_buffer_[i * row_size_] = i;
    }
    ResetDirtyFlags();
    if (rows_per_packet_ == 0) {
        fprintf(stderr, "Doh', can't even send a single row per packet ("
                "one row=%d bytes, but max packet-size=%d!)\n",
                (int)row_size_, max_transmit_bytes);
        abort();
    }
    fprintf(stderr, "PP %s: %dx%d; %d UDP packets/frame "
            "(packet contains %d rows @ %d bytes/row)\n",
            pp_host, width_, height_, packets_needed_, rows_per_packet_,
            (int)row_size_);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, %r14d
movq %rcx, %rbx
movq %rdi, %r15
leaq 0x4536(%rip), %rax      # 0x7d10
movq %rax, (%rdi)
movl %esi, 0x8(%rdi)
movl %edx, 0xc(%rdi)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm0, 0x20(%rdx)
movaps %xmm0, 0x10(%rdx)
movabsq $0x200000002, %rax      # imm = 0x200000002
movq %rax, 0x4(%rdx)
leaq 0x8(%rsp), %rcx
andq $0x0, (%rcx)
movq %rbx, %rdi
movq %r8, %rsi
callq 0x2230
testl %eax, %eax
jne 0x3873
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x389b
movl 0x4(%rax), %edi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x2080
movl %eax, %ebp
testl %eax, %eax
js 0x3867
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rsi
movl 0x10(%rax), %edx
movl %ebp, %edi
callq 0x2190
testl %eax, %eax
jns 0x3867
leaq 0x1c8c(%rip), %rdi      # 0x54e4
callq 0x21a0
movl %ebp, %edi
callq 0x2360
pushq $-0x1
popq %rbp
movq 0x8(%rsp), %rdi
callq 0x2250
jmp 0x389e
movq 0x475e(%rip), %rcx      # 0x7fd8
movq (%rcx), %r12
movl %eax, %edi
callq 0x2260
leaq 0x1c45(%rip), %rsi      # 0x54d0
movq %r12, %rdi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2290
pushq $-0x1
popq %rbp
movl %ebp, 0x10(%r15)
movslq 0x8(%r15), %rax
leaq (%rax,%rax,2), %r12
incq %r12
movq %r12, 0x18(%r15)
leal -0x4(%r14), %eax
cltq
xorl %ebp, %ebp
xorl %edx, %edx
divq %r12
movq %rax, %rcx
movl %ecx, 0x20(%r15)
movslq 0xc(%r15), %r13
addl %r13d, %eax
decl %eax
cltd
idivl %ecx
movl %eax, 0x24(%r15)
movl 0x80(%rsp), %ecx
movl %ecx, 0x28(%r15)
movslq %eax, %rdi
callq 0x2040
movq %rax, 0x30(%r15)
imulq %r13, %r12
movq %r12, %rdi
callq 0x2040
movq %rax, 0x38(%r15)
andl $0x0, 0x40(%r15)
movq %rax, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x2100
movzbl %bpl, %ebp
cmpl %ebp, %r13d
jle 0x3930
movq 0x38(%r15), %rax
movq 0x18(%r15), %rcx
imulq %rbp, %rcx
movb %bpl, (%rax,%rcx)
incb %bpl
movl 0xc(%r15), %r13d
jmp 0x390e
movq %r15, %rdi
callq 0x399a
movl 0x20(%r15), %r10d
movq 0x4695(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
testl %r10d, %r10d
je 0x397f
movl 0x8(%r15), %ecx
movl 0xc(%r15), %r8d
movl 0x24(%r15), %r9d
movl 0x18(%r15), %r11d
leaq 0x1b21(%rip), %rsi      # 0x5483
movq %rbx, %rdx
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x2290
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x18(%r15), %edx
leaq 0x1a9e(%rip), %rsi      # 0x5428
movl %r14d, %ecx
xorl %eax, %eax
callq 0x2290
callq 0x2110
nop