// File: /workspace/github_c_makefile_star2_O3/regularfry[P]tinynbd/src/tinynbd_sendfile.c
// Function: main
int main(int argc, char **argv){
  if(argc<2){err("Need a file to serve\n");}
  fd=open(argv[1],O_RDWR|O_SYNC); if(-1==fd){err("Couldn't open file\n");};
  off64_t size=lseek64(fd,0,SEEK_END);__be64 wsz=htobe64(size);
  __be64 wmag=htobe64(init_magic); __be32 rmag=htobe32(reply_magic);
  W("NBDMAGIC",8);W(&wmag,8);W(&wsz,8); int i; for(i=0;i<128;i++){W("\0",1);}
  while(1){
    uint32_t m,t,l;char h[8];uint64_t f;
    R(&m,4);R(&t,4);R(h,8);R(&f,8);R(&l,4);
    in4(&m);in4(&t);in8(&f);in4(&l);
    if(m == request_magic && f < (uint64_t)1<<63 && l+f <= size){
      int64_t ll=l; off64_t fo=(off64_t)f;
      if(t==0){
        W(&rmag,4);W("\0\0\0\0",4);W(h,8);WS(&fo,ll);
      } else if(t==1){
        for(;ll>0;ll-=B){R(rbuf,clip(ll));w(rbuf,clip(ll));}
        W(&rmag,4);W("\0\0\0\0",4);W(h,8);
      }
    } else {
      fprintf(stderr, "Error\n");
      W(&rmag,4);W("\1\0\0\0",4);W(h,8);
    }
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
cmpl $0x1, %edi
jle 0x1772
movq 0x8(%rsi), %rdi
movl $0x101002, %esi         # imm = 0x101002
xorl %eax, %eax
callq 0x1090
movl %eax, 0x2ca7(%rip)      # 0x4090
cmpl $-0x1, %eax
je 0x177e
xorl %ebx, %ebx
movl %eax, %edi
xorl %esi, %esi
movl $0x2, %edx
callq 0x10c0
movq %rax, -0x48(%rbp)
bswapq %rax
movq %rax, -0x68(%rbp)
movq 0x2c6c(%rip), %rax      # 0x4080
bswapq %rax
movq %rax, -0x60(%rbp)
movl 0x2c6b(%rip), %eax      # 0x408c
bswapl %eax
movl %eax, -0x2c(%rbp)
leaq 0xc01(%rip), %r14       # 0x202e
leaq (%r14,%rbx), %rsi
movl $0x8, %edx
subq %rbx, %rdx
movl $0x1, %edi
callq 0x1040
addl %eax, %ebx
movslq %ebx, %rbx
cmpq $0x8, %rbx
jb 0x142d
xorl %ebx, %ebx
leaq (%rbx,%rbp), %rsi
addq $-0x60, %rsi
movl $0x8, %edx
subq %rbx, %rdx
movl $0x1, %edi
callq 0x1040
addl %eax, %ebx
movslq %ebx, %rbx
cmpq $0x8, %rbx
jb 0x1450
xorl %ebx, %ebx
leaq (%rbx,%rbp), %rsi
addq $-0x68, %rsi
movl $0x8, %edx
subq %rbx, %rdx
movl $0x1, %edi
callq 0x1040
addl %eax, %ebx
movslq %ebx, %rbx
cmpq $0x8, %rbx
jb 0x1477
xorl %ebx, %ebx
leaq 0xb99(%rip), %r14       # 0x203e
movl $0x1, %edx
movl $0x1, %edi
movq %r14, %rsi
callq 0x1040
testl %eax, %eax
je 0x14a5
incl %ebx
cmpl $0x80, %ebx
jne 0x14a5
leaq 0xb74(%rip), %r13       # 0x2040
movl $0x100000, %r14d        # imm = 0x100000
leaq 0x2bd7(%rip), %r15      # 0x40b0
movl $0x4, %esi
leaq -0x38(%rbp), %rdi
callq 0x12d6
movl $0x4, %esi
leaq -0x34(%rbp), %rdi
callq 0x12d6
movl $0x8, %esi
leaq -0x40(%rbp), %rdi
callq 0x12d6
movl $0x8, %esi
leaq -0x58(%rbp), %rdi
callq 0x12d6
movl $0x4, %esi
leaq -0x30(%rbp), %rdi
callq 0x12d6
movq -0x58(%rbp), %rax
bswapq %rax
testq %rax, %rax
js 0x16d5
movl -0x38(%rbp), %ecx
bswapl %ecx
cmpl 0x2b4e(%rip), %ecx      # 0x4088
jne 0x16d5
movl -0x30(%rbp), %r12d
movl %r12d, %ebx
bswapl %ebx
leaq (%rax,%rbx), %rcx
cmpq -0x48(%rbp), %rcx
ja 0x16d5
movl -0x34(%rbp), %ecx
bswapl %ecx
movq %rax, -0x50(%rbp)
cmpl $0x1, %ecx
je 0x1622
testl %ecx, %ecx
jne 0x16ca
xorl %r14d, %r14d
leaq (%r14,%rbp), %rsi
addq $-0x2c, %rsi
movl $0x4, %edx
subq %r14, %rdx
movl $0x1, %edi
callq 0x1040
addl %eax, %r14d
movslq %r14d, %r14
cmpq $0x4, %r14
jb 0x1574
xorl %r14d, %r14d
leaq (%r14,%r13), %rsi
movl $0x4, %edx
subq %r14, %rdx
movl $0x1, %edi
callq 0x1040
addl %eax, %r14d
movslq %r14d, %r14
cmpq $0x4, %r14
jb 0x159d
xorl %r14d, %r14d
leaq (%r14,%rbp), %rsi
addq $-0x40, %rsi
movl $0x8, %edx
subq %r14, %rdx
movl $0x1, %edi
callq 0x1040
addl %eax, %r14d
movslq %r14d, %r14
cmpq $0x8, %r14
jb 0x15c2
testl %r12d, %r12d
je 0x16ca
xorl %r14d, %r14d
movl 0x2a96(%rip), %esi      # 0x4090
leaq -0x50(,%r14,8), %rdx
addq %rbp, %rdx
movq %rbx, %rcx
subq %r14, %rcx
movl $0x1, %edi
callq 0x1322
addq %rax, %r14
cmpq %rbx, %r14
jb 0x15f4
jmp 0x16ca
testl %r12d, %r12d
je 0x1659
cmpq %r14, %rbx
movl $0x100000, %r12d        # imm = 0x100000
cmovbq %rbx, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x12d6
movq %r15, %rdi
movq %r12, %rsi
callq 0x120e
leaq -0x100000(%rbx), %rax
cmpq %r14, %rbx
movq %rax, %rbx
ja 0x1627
xorl %ebx, %ebx
leaq (%rbx,%rbp), %rsi
addq $-0x2c, %rsi
movl $0x4, %edx
subq %rbx, %rdx
movl $0x1, %edi
callq 0x1040
addl %eax, %ebx
movslq %ebx, %rbx
cmpq $0x4, %rbx
jb 0x165b
xorl %ebx, %ebx
leaq (%rbx,%r13), %rsi
movl $0x4, %edx
subq %rbx, %rdx
movl $0x1, %edi
callq 0x1040
addl %eax, %ebx
movslq %ebx, %rbx
cmpq $0x4, %rbx
jb 0x1682
xorl %ebx, %ebx
leaq (%rbx,%rbp), %rsi
addq $-0x40, %rsi
movl $0x8, %edx
subq %rbx, %rdx
movl $0x1, %edi
callq 0x1040
addl %eax, %ebx
movslq %ebx, %rbx
cmpq $0x8, %rbx
jb 0x16a5
movl $0x100000, %r14d        # imm = 0x100000
jmp 0x14d9
movq 0x291c(%rip), %rax      # 0x3ff8
movq (%rax), %rcx
movl $0x6, %esi
movl $0x1, %edx
leaq 0x947(%rip), %rdi       # 0x2037
callq 0x10b0
xorl %ebx, %ebx
leaq (%rbx,%rbp), %rsi
addq $-0x2c, %rsi
movl $0x4, %edx
subq %rbx, %rdx
movl $0x1, %edi
callq 0x1040
addl %eax, %ebx
movslq %ebx, %rbx
cmpq $0x4, %rbx
jb 0x16f7
xorl %ebx, %ebx
leaq 0x920(%rip), %r12       # 0x2045
leaq (%r12,%rbx), %rsi
movl $0x4, %edx
subq %rbx, %rdx
movl $0x1, %edi
callq 0x1040
addl %eax, %ebx
movslq %ebx, %rbx
cmpq $0x4, %rbx
jb 0x1725
xorl %ebx, %ebx
leaq (%rbx,%rbp), %rsi
addq $-0x40, %rsi
movl $0x8, %edx
subq %rbx, %rdx
movl $0x1, %edi
callq 0x1040
addl %eax, %ebx
movslq %ebx, %rbx
cmpq $0x8, %rbx
jb 0x1748
jmp 0x14d9
leaq 0x88b(%rip), %rdi       # 0x2004
callq 0x11dc
leaq 0x895(%rip), %rdi       # 0x201a
callq 0x11dc