// File: /workspace/github_c_makefile_star2_O1/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)
cmpl $0x0, 0x4627(%rip)      # 0x8190
je 0x3cf3
leaq 0x361a(%rip), %rbx      # 0x7190
xorl %r14d, %r14d
xorl %r13d, %r13d
movl %r13d, %edi
callq 0x38ae
movq 0x35fd(%rip), %rdi      # 0x7188
callq 0x11e0
testl %eax, %eax
jne 0x3d78
movq 0x45f9(%rip), %rax      # 0x8198
movq (%rax,%r14), %rdi
callq 0x10a0
movq 0x45e9(%rip), %r12      # 0x8198
cmpb $0x0, 0x1c(%r12,%r14)
je 0x3c14
movq (%r12,%r14), %rdi
movl $0x2c1, %esi            # imm = 0x2C1
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x10d0
testl %eax, %eax
js 0x3d82
movl %eax, %ebp
movq 0x45bb(%rip), %rax      # 0x8198
movl 0x18(%rax,%r14), %edx
testq %rdx, %rdx
je 0x3c08
movq 0x8(%rax,%r14), %rsi
movl %ebp, %edi
callq 0x1080
movq 0x459e(%rip), %rdi      # 0x8198
movl 0x18(%rdi,%r14), %ecx
cmpq %rcx, %rax
jne 0x3d8a
movl %ebp, %edi
callq 0x12a0
jmp 0x3ccd
movq %rbx, %rdi
callq 0x1090
movq %rax, %rbp
movq 0x355a(%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 0x3d97
movq %rax, %rbp
cmpb $0x2f, (%r15)
jne 0x3c84
movl $0x1000, %esi           # imm = 0x1000
movq %rbp, %rdi
leaq 0x9c2(%rip), %rdx       # 0x4630
movq %r15, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x1220
leaq 0x350e(%rip), %rbx      # 0x7190
jmp 0x3caa
movl $0x1000, %esi           # imm = 0x1000
movq %rbp, %rdi
leaq 0x99a(%rip), %rdx       # 0x462d
leaq 0x34f6(%rip), %rbx      # 0x7190
movq %rbx, %rcx
movq %r15, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0x1220
movq 0x44e7(%rip), %rax      # 0x8198
movq (%rax,%r14), %rsi
movq %rbp, %rdi
callq 0x1060
movq %rbp, %rdi
testl %eax, %eax
jne 0x3d92
callq 0x1170
movq %rbx, %rdi
callq 0x11e0
testl %eax, %eax
jne 0x3d7d
incq %r13
movl 0x44aa(%rip), %eax      # 0x8190
addq $0x20, %r14
cmpq %rax, %r13
jb 0x3b7c
cmpl $0x0, 0x4496(%rip)      # 0x8190
movl 0xc(%rsp), %ebp
je 0x3d66
movl $0x18, %ebx
xorl %r15d, %r15d
leaq 0x10(%rsp), %r14
movq 0x4484(%rip), %rax      # 0x8198
movl (%rax,%rbx), %edx
testq %rdx, %rdx
je 0x3d3e
movq -0x10(%rax,%rbx), %rsi
movl %ebp, %edi
callq 0x1080
movq 0x4469(%rip), %rcx      # 0x8198
movl (%rcx,%rbx), %ecx
cmpq %rcx, %rax
je 0x3d54
callq 0x2609
jmp 0x3d54
cmpb $0x0, -0x8(%rax,%rbx)
je 0x3d54
movl $0x1000, %edx           # imm = 0x1000
movl %ebp, %edi
movq %r14, %rsi
callq 0x11c0
incq %r15
movl 0x4433(%rip), %eax      # 0x8190
addq $0x20, %rbx
cmpq %rax, %r15
jb 0x3d0d
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2415
callq 0x2575
movq %r13, %rdi
callq 0x24b5
addq %r14, %rdi
callq 0x2462
callq 0x2520
callq 0x25bf