// File: /workspace/github_c_makefile_star2_O2/mabdi[P]bunney/bunny-flow.c
// Function: commit_data_fd
static void commit_data_fd(_u32 fd) {
  _u32 i;
  _s32 of;

  /* Save a copy to output dir first - chat with the app may go wrong,
     especially over the network, we do not want to lose data. */

  for (i=0;i<infcount;i++) {
  
    load_data(i);

    if (chdir(outdir)) fatal("cannot enter '%s'",outdir);

    unlink(infile[i].fname);

    if (!infile[i].dirty) {
    
      _u8 *fin = malloc(strlen(workdir) + strlen(indir) + strlen(infile[i].fname) + 5);
      if (!fin) fatal("out of memory");
      if (indir[0] == '/') 
        snprintf(fin,MAXTOKEN,"%s/%s", indir, infile[i].fname);
	else snprintf(fin,MAXTOKEN,"%s/%s/%s", workdir, indir, infile[i].fname);
      if (link(fin,infile[i].fname)) pfatal("cannot hardlink '%s'",fin);
      free(fin);
      
    } else {
    
      of = open(infile[i].fname,O_WRONLY|O_CREAT|O_TRUNC|O_EXCL,0600);
      if (of < 0) pfatal("unable to create '%s/%s'",outdir,infile[i].fname);

      if (infile[i].cur_len)
        if (write(of,infile[i].data,infile[i].cur_len) != infile[i].cur_len)
          fatal("short write to '%s/%s'",outdir,infile[i].fname);    
  
      close(of);
    
    }
    
    if (chdir(workdir)) fatal("unable to go back to work directory");

  }
  
  for (i=0;i<infcount;i++) {
    
    if (infile[i].cur_len) {
    
      /* Keep this non-fatal: we're trying to crash the client, so
         it might at some point become incapable of receiving our
	 data. */
    
      if (write(fd,infile[i].data,infile[i].cur_len) != infile[i].cur_len)
        debug("WARNING: Unable to complete write to output stream.\n");
	
    } else if (infile[i].asis) {
    
      /* Empty .keep file == sink client output. On output to WRONLY file or
         prematurely closed sockets, this will silently fail, which is 
	 precisely what we want. */
	 
      _u8 sink[MAXTOKEN];
      read(fd,sink,MAXTOKEN);
    }
    
  }
  
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1018, %rsp           # imm = 0x1018
movl %edi, 0xc(%rsp)
leaq 0x3cff(%rip), %rbx      # 0x7190
xorl %r14d, %r14d
xorl %r13d, %r13d
movl 0x4cf3(%rip), %eax      # 0x8190
cmpq %rax, %r13
jae 0x364d
movl %r13d, %edi
callq 0x2fea
movq 0x3cd3(%rip), %rdi      # 0x7188
callq 0x11e0
testl %eax, %eax
jne 0x36ec
movq 0x4ccf(%rip), %rax      # 0x8198
movq (%rax,%r14), %rdi
callq 0x10a0
movq 0x4cbf(%rip), %r12      # 0x8198
cmpb $0x0, 0x1c(%r12,%r14)
je 0x353e
movq (%r12,%r14), %rdi
movl $0x2c1, %esi            # imm = 0x2C1
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x10d0
testl %eax, %eax
js 0x372e
movl %eax, %ebp
movq 0x4c91(%rip), %rax      # 0x8198
movl 0x18(%rax,%r14), %edx
testq %rdx, %rdx
je 0x3532
movq 0x8(%rax,%r14), %rsi
movl %ebp, %edi
callq 0x1080
movq 0x4c74(%rip), %rcx      # 0x8198
movl 0x18(%rcx,%r14), %edx
cmpq %rdx, %rax
jne 0x377b
movl %ebp, %edi
callq 0x12a0
jmp 0x35f7
movq %rbx, %rdi
callq 0x1090
movq %rax, %rbp
movq 0x3c30(%rip), %r15      # 0x7180
movq %r15, %rdi
callq 0x1090
movq %rax, %rbx
movq (%r12,%r14), %r12
movq %r12, %rdi
callq 0x1090
addq %rbp, %rbx
leaq (%rax,%rbx), %rdi
addq $0x5, %rdi
callq 0x1190
testq %rax, %rax
je 0x37be
movq %rax, %rbp
cmpb $0x2f, (%r15)
jne 0x35ae
movl $0x1000, %esi           # imm = 0x1000
movq %rbp, %rdi
leaq 0x1098(%rip), %rdx      # 0x4630
movq %r15, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x1220
leaq 0x3be4(%rip), %rbx      # 0x7190
jmp 0x35d4
movl $0x1000, %esi           # imm = 0x1000
movq %rbp, %rdi
leaq 0x1070(%rip), %rdx      # 0x462d
leaq 0x3bcc(%rip), %rbx      # 0x7190
movq %rbx, %rcx
movq %r15, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0x1220
movq 0x4bbd(%rip), %rax      # 0x8198
movq (%rax,%r14), %rsi
movq %rbp, %rdi
callq 0x1060
testl %eax, %eax
jne 0x3801
movq %rbp, %rdi
callq 0x1170
movq %rbx, %rdi
callq 0x11e0
incq %r13
addq $0x20, %r14
testl %eax, %eax
je 0x3497
movq 0x39cb(%rip), %rbx      # 0x6fe0
movq (%rbx), %rcx
leaq 0x109f(%rip), %rdi      # 0x46be
pushq $0x3a
popq %rsi
pushq $0x1
popq %rdx
callq 0x1290
movq (%rbx), %rdi
leaq 0xa38(%rip), %rsi       # 0x406c
leaq 0xfe3(%rip), %rdx       # 0x461e
leaq 0xa3f(%rip), %rcx       # 0x4081
movl $0x205, %r8d            # imm = 0x205
jmp 0x37f8
pushq $0x18
popq %rbx
xorl %ebp, %ebp
leaq 0x10(%rsp), %r14
leaq 0x109b(%rip), %r15      # 0x46f9
pushq $0x34
popq %r12
pushq $0x1
popq %r13
movl %eax, %eax
cmpq %rax, %rbp
jae 0x36da
movq 0x4b24(%rip), %rax      # 0x8198
movl (%rax,%rbx), %edx
testq %rdx, %rdx
je 0x36b3
movq -0x10(%rax,%rbx), %rsi
movl 0xc(%rsp), %edi
callq 0x1080
movq 0x4b07(%rip), %rcx      # 0x8198
movl (%rcx,%rbx), %ecx
cmpq %rcx, %rax
je 0x36cb
movq 0x3940(%rip), %rax      # 0x6fe0
movq (%rax), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x1290
jmp 0x36cb
cmpb $0x0, -0x8(%rax,%rbx)
je 0x36cb
movl $0x1000, %edx           # imm = 0x1000
movl 0xc(%rsp), %edi
movq %r14, %rsi
callq 0x11c0
incq %rbp
movl 0x4abc(%rip), %eax      # 0x8190
addq $0x20, %rbx
jmp 0x3666
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x38ed(%rip), %rbx      # 0x6fe0
movq (%rbx), %rdi
movq 0x3a8b(%rip), %rdx      # 0x7188
leaq 0xef1(%rip), %rsi       # 0x45f5
xorl %eax, %eax
callq 0x11b0
movq (%rbx), %rdi
leaq 0x957(%rip), %rsi       # 0x406c
leaq 0xf02(%rip), %rdx       # 0x461e
leaq 0x95e(%rip), %rcx       # 0x4081
movl $0x1ea, %r8d            # imm = 0x1EA
jmp 0x37f8
movq 0x38ab(%rip), %rbx      # 0x6fe0
movq (%rbx), %rdi
movq 0x3a49(%rip), %rdx      # 0x7188
movq 0x4a52(%rip), %rax      # 0x8198
movq (%rax,%r14), %rcx
leaq 0xf10(%rip), %rsi       # 0x4661
xorl %eax, %eax
callq 0x11b0
movq (%rbx), %rdi
leaq 0x90a(%rip), %rsi       # 0x406c
leaq 0xeb5(%rip), %rdx       # 0x461e
leaq 0x911(%rip), %rcx       # 0x4081
movl $0x1fb, %r8d            # imm = 0x1FB
jmp 0x383a
movq 0x385e(%rip), %rbx      # 0x6fe0
movq (%rbx), %rdi
movq 0x39fc(%rip), %rdx      # 0x7188
movq (%rcx,%r14), %rcx
leaq 0xef9(%rip), %rsi       # 0x4690
xorl %eax, %eax
callq 0x11b0
movq (%rbx), %rdi
leaq 0x8c4(%rip), %rsi       # 0x406c
leaq 0xe6f(%rip), %rdx       # 0x461e
leaq 0x8cb(%rip), %rcx       # 0x4081
movl $0x1ff, %r8d            # imm = 0x1FF
jmp 0x37f8
movq 0x381b(%rip), %rbx      # 0x6fe0
movq (%rbx), %rcx
leaq 0xa7b(%rip), %rdi       # 0x424a
pushq $0x24
popq %rsi
pushq $0x1
popq %rdx
callq 0x1290
movq (%rbx), %rdi
leaq 0x888(%rip), %rsi       # 0x406c
leaq 0xe33(%rip), %rdx       # 0x461e
leaq 0x88f(%rip), %rcx       # 0x4081
movl $0x1f1, %r8d            # imm = 0x1F1
xorl %eax, %eax
callq 0x11b0
jmp 0x384d
movq 0x37d8(%rip), %rbx      # 0x6fe0
movq (%rbx), %rdi
leaq 0xe24(%rip), %rsi       # 0x4636
movq %rbp, %rdx
xorl %eax, %eax
callq 0x11b0
movq (%rbx), %rdi
leaq 0x846(%rip), %rsi       # 0x406c
leaq 0xdf1(%rip), %rdx       # 0x461e
leaq 0x84d(%rip), %rcx       # 0x4081
movl $0x1f5, %r8d            # imm = 0x1F5
xorl %eax, %eax
callq 0x11b0
leaq 0x904(%rip), %rdi       # 0x414c
callq 0x1100
pushq $0x1
popq %rdi
callq 0x1180