// File: /workspace/github_c_makefile_star2_O0/regularfry[P]tinynbd/src/tinynbd.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;
      lseek64(fd,f,SEEK_SET);
      if(t==0){
        W(&rmag,4);W("\0\0\0\0",4);W(h,8);
        for(;ll>0;ll-=B){r(rbuf,clip(ll));W(rbuf,clip(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 {
      W(&rmag,4);W("\1\0\0\0",4);W(h,8);
    }
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x1508
leaq 0xb01(%rip), %rdi       # 0x2004
callq 0x11a0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x101002, %esi         # imm = 0x101002
movb $0x0, %al
callq 0x1070
movl %eax, 0x2b4e(%rip)      # 0x4070
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl 0x2b43(%rip), %eax      # 0x4070
jne 0x153b
leaq 0xae4(%rip), %rdi       # 0x201a
callq 0x11a0
movl 0x2b2f(%rip), %edi      # 0x4070
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x1090
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1400
movq %rax, -0x20(%rbp)
movq 0x2af9(%rip), %rdi      # 0x4060
callq 0x1400
movq %rax, -0x28(%rbp)
movl 0x2af6(%rip), %edi      # 0x406c
callq 0x1390
movl %eax, -0x2c(%rbp)
leaq 0xaa9(%rip), %rdi       # 0x202e
movl $0x8, %esi
callq 0x12a0
leaq -0x28(%rbp), %rdi
movl $0x8, %esi
callq 0x12a0
leaq -0x20(%rbp), %rdi
movl $0x8, %esi
callq 0x12a0
movl $0x0, -0x30(%rbp)
cmpl $0x80, -0x30(%rbp)
jge 0x15d7
leaq 0xa75(%rip), %rdi       # 0x2037
movl $0x1, %esi
callq 0x12a0
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x15b2
jmp 0x15d9
leaq -0x34(%rbp), %rdi
movl $0x4, %esi
callq 0x1300
leaq -0x38(%rbp), %rdi
movl $0x4, %esi
callq 0x1300
leaq -0x44(%rbp), %rdi
movl $0x8, %esi
callq 0x1300
leaq -0x50(%rbp), %rdi
movl $0x8, %esi
callq 0x1300
leaq -0x3c(%rbp), %rdi
movl $0x4, %esi
callq 0x1300
leaq -0x34(%rbp), %rdi
callq 0x1360
leaq -0x38(%rbp), %rdi
callq 0x1360
leaq -0x50(%rbp), %rdi
callq 0x13d0
leaq -0x3c(%rbp), %rdi
callq 0x1360
movl -0x34(%rbp), %eax
cmpl 0x2a1c(%rip), %eax      # 0x4068
jne 0x178b
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
cmpq %rax, -0x50(%rbp)
jae 0x178b
movl -0x3c(%rbp), %eax
addq -0x50(%rbp), %rax
cmpq -0x18(%rbp), %rax
ja 0x178b
movl -0x3c(%rbp), %eax
movq %rax, -0x58(%rbp)
movl 0x29ec(%rip), %edi      # 0x4070
movq -0x50(%rbp), %rsi
xorl %edx, %edx
callq 0x1090
cmpl $0x0, -0x38(%rbp)
jne 0x170b
leaq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x12a0
leaq 0x98f(%rip), %rdi       # 0x2039
movl $0x4, %esi
callq 0x12a0
leaq -0x44(%rbp), %rdi
movl $0x8, %esi
callq 0x12a0
cmpq $0x0, -0x58(%rbp)
jle 0x1709
movq -0x58(%rbp), %rdi
callq 0x14b0
movq %rax, %rsi
leaq 0x29b4(%rip), %rdi      # 0x4090
callq 0x1240
movq -0x58(%rbp), %rdi
callq 0x14b0
movq %rax, %rsi
leaq 0x299c(%rip), %rdi      # 0x4090
callq 0x12a0
movq -0x58(%rbp), %rax
subq $0x100000, %rax         # imm = 0x100000
movq %rax, -0x58(%rbp)
jmp 0x16c2
jmp 0x1789
cmpl $0x1, -0x38(%rbp)
jne 0x1787
jmp 0x1713
cmpq $0x0, -0x58(%rbp)
jle 0x175a
movq -0x58(%rbp), %rdi
callq 0x14b0
movq %rax, %rsi
leaq 0x2963(%rip), %rdi      # 0x4090
callq 0x1300
movq -0x58(%rbp), %rdi
callq 0x14b0
movq %rax, %rsi
leaq 0x294b(%rip), %rdi      # 0x4090
callq 0x11e0
movq -0x58(%rbp), %rax
subq $0x100000, %rax         # imm = 0x100000
movq %rax, -0x58(%rbp)
jmp 0x1713
leaq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x12a0
leaq 0x8ca(%rip), %rdi       # 0x2039
movl $0x4, %esi
callq 0x12a0
leaq -0x44(%rbp), %rdi
movl $0x8, %esi
callq 0x12a0
jmp 0x1789
jmp 0x17b8
leaq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x12a0
leaq 0x89e(%rip), %rdi       # 0x203e
movl $0x4, %esi
callq 0x12a0
leaq -0x44(%rbp), %rdi
movl $0x8, %esi
callq 0x12a0
jmp 0x15d9