// File: /workspace/github_c_makefile_star2_O3/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
cmpl $0x0, 0x45f8(%rip)      # 0x8190
je 0x3d94
movl %edi, 0xc(%rsp)
leaq 0x35e7(%rip), %rbx      # 0x7190
xorl %r14d, %r14d
xorl %r13d, %r13d
movl %r13d, %edi
callq 0x38d9
movq 0x35ca(%rip), %rdi      # 0x7188
callq 0x11e0
testl %eax, %eax
jne 0x3da6
movq 0x45c6(%rip), %rax      # 0x8198
movq (%rax,%r14), %rdi
callq 0x10a0
movq 0x45b6(%rip), %r12      # 0x8198
cmpb $0x0, 0x1c(%r12,%r14)
je 0x3c47
movq (%r12,%r14), %rdi
movl $0x2c1, %esi            # imm = 0x2C1
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x10d0
testl %eax, %eax
js 0x3db0
movl %eax, %ebp
movq 0x4588(%rip), %rax      # 0x8198
movl 0x18(%rax,%r14), %edx
testq %rdx, %rdx
je 0x3c3b
movq 0x8(%rax,%r14), %rsi
movl %ebp, %edi
callq 0x1080
movq 0x456b(%rip), %rdi      # 0x8198
movl 0x18(%rdi,%r14), %ecx
cmpq %rcx, %rax
jne 0x3db8
movl %ebp, %edi
callq 0x12a0
jmp 0x3d00
movq %rbx, %rdi
callq 0x1090
movq %rax, %rbp
movq 0x3527(%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 0x3dc5
movq %rax, %rbp
cmpb $0x2f, (%r15)
jne 0x3cb7
movl $0x1000, %esi           # imm = 0x1000
movq %rbp, %rdi
leaq 0x98f(%rip), %rdx       # 0x4630
movq %r15, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x1220
leaq 0x34db(%rip), %rbx      # 0x7190
jmp 0x3cdd
movl $0x1000, %esi           # imm = 0x1000
movq %rbp, %rdi
leaq 0x967(%rip), %rdx       # 0x462d
leaq 0x34c3(%rip), %rbx      # 0x7190
movq %rbx, %rcx
movq %r15, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0x1220
movq 0x44b4(%rip), %rax      # 0x8198
movq (%rax,%r14), %rsi
movq %rbp, %rdi
callq 0x1060
movq %rbp, %rdi
testl %eax, %eax
jne 0x3dc0
callq 0x1170
movq %rbx, %rdi
callq 0x11e0
testl %eax, %eax
jne 0x3dab
incq %r13
movl 0x4477(%rip), %eax      # 0x8190
addq $0x20, %r14
cmpq %rax, %r13
jb 0x3baf
testl %eax, %eax
movl 0xc(%rsp), %ebp
je 0x3d94
movl $0x18, %ebx
xorl %r15d, %r15d
leaq 0x10(%rsp), %r14
movq 0x4456(%rip), %rax      # 0x8198
movl (%rax,%rbx), %edx
testq %rdx, %rdx
je 0x3d6c
movq -0x10(%rax,%rbx), %rsi
movl %ebp, %edi
callq 0x1080
movq 0x443b(%rip), %rcx      # 0x8198
movl (%rcx,%rbx), %ecx
cmpq %rcx, %rax
je 0x3d82
callq 0x25c8
jmp 0x3d82
cmpb $0x0, -0x8(%rax,%rbx)
je 0x3d82
movl $0x1000, %edx           # imm = 0x1000
movl %ebp, %edi
movq %r14, %rsi
callq 0x11c0
incq %r15
movl 0x4405(%rip), %eax      # 0x8190
addq $0x20, %rbx
cmpq %rax, %r15
jb 0x3d3b
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x241e
callq 0x257e
movq %r13, %rdi
callq 0x24be
addq %r14, %rdi
callq 0x246b
callq 0x2529
callq 0x25e4