// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
cmpl $0x1, %edi
jle 0x1702
movq 0x8(%rsi), %rdi
movl $0x101002, %esi         # imm = 0x101002
xorl %eax, %eax
callq 0x1070
movl %eax, 0x2d31(%rip)      # 0x4070
cmpl $-0x1, %eax
je 0x170e
movl 0x2d22(%rip), %edi      # 0x4070
xorl %ebx, %ebx
xorl %esi, %esi
movl $0x2, %edx
callq 0x1090
movq %rax, -0x58(%rbp)
bswapq %rax
movq %rax, -0x68(%rbp)
movq 0x2cf2(%rip), %rax      # 0x4060
bswapq %rax
movq %rax, -0x60(%rbp)
movl 0x2cf1(%rip), %eax      # 0x406c
bswapl %eax
movl %eax, -0x2c(%rbp)
leaq 0xca7(%rip), %r14       # 0x202e
leaq (%r14,%rbx), %rsi
movl $0x8, %edx
subq %rbx, %rdx
movl $0x1, %edi
callq 0x1030
addl %eax, %ebx
movslq %ebx, %rbx
cmpq $0x8, %rbx
jb 0x1387
xorl %ebx, %ebx
leaq (%rbx,%rbp), %rsi
addq $-0x60, %rsi
movl $0x8, %edx
subq %rbx, %rdx
movl $0x1, %edi
callq 0x1030
addl %eax, %ebx
movslq %ebx, %rbx
cmpq $0x8, %rbx
jb 0x13aa
xorl %ebx, %ebx
leaq (%rbx,%rbp), %rsi
addq $-0x68, %rsi
movl $0x8, %edx
subq %rbx, %rdx
movl $0x1, %edi
callq 0x1030
addl %eax, %ebx
movslq %ebx, %rbx
cmpq $0x8, %rbx
jb 0x13d1
xorl %ebx, %ebx
leaq 0xc38(%rip), %r14       # 0x2037
xorl %esi, %esi
addq %r14, %rsi
movl $0x1, %edx
movl $0x1, %edi
callq 0x1030
movslq %eax, %rsi
shlq $0x20, %rax
je 0x1401
incl %ebx
cmpl $0x80, %ebx
jne 0x13ff
leaq 0x2c63(%rip), %r14      # 0x4090
leaq 0xc0a(%rip), %rbx       # 0x203e
movl $0x4, %esi
leaq -0x38(%rbp), %rdi
callq 0x1296
movl $0x4, %esi
leaq -0x34(%rbp), %rdi
callq 0x1296
movl $0x8, %esi
leaq -0x44(%rbp), %rdi
callq 0x1296
movl $0x8, %esi
leaq -0x50(%rbp), %rdi
callq 0x1296
movl $0x4, %esi
leaq -0x30(%rbp), %rdi
callq 0x1296
movl -0x38(%rbp), %eax
bswapl %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %r12d
bswapl %r12d
movl %r12d, -0x34(%rbp)
movq -0x50(%rbp), %rsi
bswapq %rsi
movq %rsi, -0x50(%rbp)
movl -0x30(%rbp), %r15d
movl %r15d, %ecx
bswapl %ecx
movl %ecx, -0x30(%rbp)
testq %rsi, %rsi
js 0x14be
cmpl 0x2bb9(%rip), %eax      # 0x4068
jne 0x14be
movl %ecx, %r13d
leaq (%rsi,%r13), %rax
cmpq -0x58(%rbp), %rax
jbe 0x153a
xorl %r15d, %r15d
leaq (%r15,%rbp), %rsi
addq $-0x2c, %rsi
movl $0x4, %edx
subq %r15, %rdx
movl $0x1, %edi
callq 0x1030
addl %eax, %r15d
movslq %r15d, %r15
cmpq $0x4, %r15
jb 0x14c1
xorl %r15d, %r15d
leaq (%rbx,%r15), %rsi
movl $0x4, %edx
subq %r15, %rdx
movl $0x1, %edi
callq 0x1030
addl %eax, %r15d
movslq %r15d, %r15
cmpq $0x4, %r15
jb 0x14ea
xorl %r15d, %r15d
leaq (%r15,%rbp), %rsi
addq $-0x44, %rsi
movl $0x8, %edx
subq %r15, %rdx
movl $0x1, %edi
callq 0x1030
addl %eax, %r15d
movslq %r15d, %r15
cmpq $0x8, %r15
jb 0x150f
jmp 0x1434
movl 0x2b30(%rip), %edi      # 0x4070
xorl %edx, %edx
callq 0x1090
cmpl $0x1, %r12d
je 0x1642
testl %r12d, %r12d
jne 0x1434
movl %r15d, -0x3c(%rbp)
xorl %r12d, %r12d
leaq (%r12,%rbp), %rsi
addq $-0x2c, %rsi
movl $0x4, %edx
subq %r12, %rdx
movl $0x1, %edi
callq 0x1030
addl %eax, %r12d
movslq %r12d, %r12
cmpq $0x4, %r12
jb 0x1561
xorl %r12d, %r12d
leaq 0xaa8(%rip), %r15       # 0x2039
leaq (%r15,%r12), %rsi
movl $0x4, %edx
subq %r12, %rdx
movl $0x1, %edi
callq 0x1030
addl %eax, %r12d
movslq %r12d, %r12
cmpq $0x4, %r12
jb 0x1591
xorl %r12d, %r12d
leaq (%r12,%rbp), %rsi
addq $-0x44, %rsi
movl $0x8, %edx
subq %r12, %rdx
movl $0x1, %edi
callq 0x1030
addl %eax, %r12d
movslq %r12d, %r12
cmpq $0x8, %r12
jb 0x15b6
cmpl $0x0, -0x3c(%rbp)
movl $0x100000, %eax         # imm = 0x100000
je 0x1434
cmpq %rax, %r13
movl $0x100000, %r15d        # imm = 0x100000
cmovlq %r13, %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x1211
xorl %r12d, %r12d
leaq (%r14,%r12), %rsi
movq %r15, %rdx
subq %r12, %rdx
movl $0x1, %edi
callq 0x1030
addl %eax, %r12d
movslq %r12d, %r12
cmpq %r15, %r12
jb 0x1606
leaq -0x100000(%r13), %rax
cmpq $0x100000, %r13         # imm = 0x100000
movq %rax, %r13
movl $0x100000, %eax         # imm = 0x100000
jg 0x15eb
jmp 0x1434
testl %r15d, %r15d
movl $0x100000, %r12d        # imm = 0x100000
je 0x167f
cmpq %r12, %r13
movl $0x100000, %r15d        # imm = 0x100000
cmovlq %r13, %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x1296
movq %r14, %rdi
movq %r15, %rsi
callq 0x11ce
leaq -0x100000(%r13), %rax
cmpq %r12, %r13
movq %rax, %r13
jg 0x164d
xorl %r15d, %r15d
leaq 0x9b0(%rip), %r12       # 0x2039
leaq (%r15,%rbp), %rsi
addq $-0x2c, %rsi
movl $0x4, %edx
subq %r15, %rdx
movl $0x1, %edi
callq 0x1030
addl %eax, %r15d
movslq %r15d, %r15
cmpq $0x4, %r15
jb 0x1689
xorl %r15d, %r15d
leaq (%r12,%r15), %rsi
movl $0x4, %edx
subq %r15, %rdx
movl $0x1, %edi
callq 0x1030
addl %eax, %r15d
movslq %r15d, %r15
cmpq $0x4, %r15
jb 0x16b2
xorl %r15d, %r15d
leaq (%r15,%rbp), %rsi
addq $-0x44, %rsi
movl $0x8, %edx
subq %r15, %rdx
movl $0x1, %edi
callq 0x1030
addl %eax, %r15d
movslq %r15d, %r15
cmpq $0x8, %r15
jb 0x16d7
jmp 0x1434
leaq 0x8fb(%rip), %rdi       # 0x2004
callq 0x119c
leaq 0x905(%rip), %rdi       # 0x201a
callq 0x119c