// File: /workspace/github_cpp_makefile_star2_O3/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, %ebx
movq %rcx, %r14
movq %rdi, %r15
movl 0x80(%rsp), %r13d
leaq 0x448e(%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
movq $0x0, (%rcx)
movq %r14, %rdi
movq %r8, %rsi
callq 0x2230
testl %eax, %eax
jne 0x3925
movq 0x8(%rsp), %rax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x3952
movl 0x4(%rax), %edi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x2080
movl %eax, %ebp
testl %eax, %eax
js 0x3919
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rsi
movl 0x10(%rax), %edx
movl %ebp, %edi
callq 0x2190
testl %eax, %eax
jns 0x3919
leaq 0x1bdc(%rip), %rdi      # 0x54e4
callq 0x21a0
movl %ebp, %edi
callq 0x2360
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rdi
callq 0x2250
jmp 0x3952
movq 0x46ac(%rip), %rcx      # 0x7fd8
movq (%rcx), %r12
movl %eax, %edi
callq 0x2260
leaq 0x1b93(%rip), %rsi      # 0x54d0
movq %r12, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2290
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, 0x10(%r15)
movslq 0x8(%r15), %rax
leaq (%rax,%rax,2), %rbp
incq %rbp
movq %rbp, 0x18(%r15)
leal -0x4(%rbx), %eax
cltq
xorl %edx, %edx
divq %rbp
movq %rax, %rcx
movl %ecx, 0x20(%r15)
movslq 0xc(%r15), %r12
addl %r12d, %eax
decl %eax
cltd
idivl %ecx
movl %eax, 0x24(%r15)
movl %r13d, 0x28(%r15)
movslq %eax, %r13
movq %r13, %rdi
callq 0x2040
movq %rax, 0x30(%r15)
imulq %r12, %rbp
movq %rbp, %rdi
callq 0x2040
movq %rax, 0x38(%r15)
movl $0x0, 0x40(%r15)
movq %rax, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x2100
testq %r12, %r12
jle 0x39e9
xorl %eax, %eax
movq 0x38(%r15), %rcx
movzbl %al, %eax
movq 0x18(%r15), %rdx
imulq %rax, %rdx
movb %al, (%rcx,%rdx)
incb %al
movzbl %al, %ecx
movl 0xc(%r15), %r12d
cmpl %ecx, %r12d
jg 0x39c5
movl 0x24(%r15), %r13d
testl %r13d, %r13d
jle 0x39fc
movq 0x30(%r15), %rdi
movl %r13d, %edx
xorl %esi, %esi
callq 0x2100
movl 0x20(%r15), %r10d
movq 0x45d1(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
testl %r10d, %r10d
je 0x3a41
movl 0x8(%r15), %ecx
movl 0x18(%r15), %r11d
leaq 0x1a65(%rip), %rsi      # 0x5483
movq %r14, %rdx
movl %r12d, %r8d
movl %r13d, %r9d
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 0x19dc(%rip), %rsi      # 0x5428
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2290
callq 0x2110