// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1030, %rsp           # imm = 0x1030
movl %edi, -0x4(%rbp)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl 0x3e02(%rip), %eax      # 0x8190
jae 0x47f0
movl -0x8(%rbp), %edi
callq 0x3b00
movq 0x2de5(%rip), %rdi      # 0x7188
callq 0x11e0
cmpl $0x0, %eax
je 0x4404
jmp 0x43af
movq 0x2c2a(%rip), %rax      # 0x6fe0
movq (%rax), %rdi
movq 0x2dc8(%rip), %rdx      # 0x7188
leaq 0x11fe(%rip), %rsi      # 0x55c5
movb $0x0, %al
callq 0x11b0
movq 0x2c0b(%rip), %rax      # 0x6fe0
movq (%rax), %rdi
leaq 0xc5d(%rip), %rsi       # 0x503c
leaq 0x1208(%rip), %rdx      # 0x55ee
leaq 0xc64(%rip), %rcx       # 0x5051
movl $0x1ea, %r8d            # imm = 0x1EA
movb $0x0, %al
callq 0x11b0
movl $0x1, %edi
callq 0x1180
movq 0x3d8d(%rip), %rax      # 0x8198
movl -0x8(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x10a0
movq 0x3d74(%rip), %rax      # 0x8198
movl -0x8(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
cmpb $0x0, 0x1c(%rax)
jne 0x45fe
leaq 0x2d51(%rip), %rdi      # 0x7190
callq 0x1090
movq %rax, -0x1030(%rbp)
movq 0x2d2e(%rip), %rdi      # 0x7180
callq 0x1090
movq %rax, %rcx
movq -0x1030(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x1028(%rbp)
movq 0x3d26(%rip), %rax      # 0x8198
movl -0x8(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x1090
movq -0x1028(%rbp), %rdi
addq %rax, %rdi
addq $0x5, %rdi
callq 0x1190
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x44f2
jmp 0x44a4
movq 0x2b35(%rip), %rax      # 0x6fe0
movq (%rax), %rdi
leaq 0xd65(%rip), %rsi       # 0x521a
movb $0x0, %al
callq 0x11b0
movq 0x2b1d(%rip), %rax      # 0x6fe0
movq (%rax), %rdi
leaq 0xb6f(%rip), %rsi       # 0x503c
leaq 0x111a(%rip), %rdx      # 0x55ee
leaq 0xb76(%rip), %rcx       # 0x5051
movl $0x1f1, %r8d            # imm = 0x1F1
movb $0x0, %al
callq 0x11b0
movl $0x1, %edi
callq 0x1180
movq 0x2c87(%rip), %rax      # 0x7180
movzbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x4535
movq -0x18(%rbp), %rdi
movq 0x2c74(%rip), %rcx      # 0x7180
movq 0x3c85(%rip), %rax      # 0x8198
movl -0x8(%rbp), %edx
shlq $0x5, %rdx
addq %rdx, %rax
movq (%rax), %r8
movl $0x1000, %esi           # imm = 0x1000
leaq 0x10d4(%rip), %rdx      # 0x5600
movb $0x0, %al
callq 0x1220
jmp 0x456e
movq -0x18(%rbp), %rdi
movq 0x2c40(%rip), %r8       # 0x7180
movq 0x3c51(%rip), %rax      # 0x8198
movl -0x8(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %r9
movl $0x1000, %esi           # imm = 0x1000
leaq 0x109d(%rip), %rdx      # 0x55fd
leaq 0x2c29(%rip), %rcx      # 0x7190
movb $0x0, %al
callq 0x1220
movq -0x18(%rbp), %rdi
movq 0x3c1f(%rip), %rax      # 0x8198
movl -0x8(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x1060
cmpl $0x0, %eax
je 0x45f0
jmp 0x4592
movq 0x2a47(%rip), %rax      # 0x6fe0
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x105f(%rip), %rsi      # 0x5606
movb $0x0, %al
callq 0x11b0
movq 0x2a2b(%rip), %rax      # 0x6fe0
movq (%rax), %rdi
leaq 0xa7d(%rip), %rsi       # 0x503c
leaq 0x1028(%rip), %rdx      # 0x55ee
leaq 0xa84(%rip), %rcx       # 0x5051
movl $0x1f5, %r8d            # imm = 0x1F5
movb $0x0, %al
callq 0x11b0
leaq 0xb3b(%rip), %rdi       # 0x511c
callq 0x1100
movl $0x1, %edi
callq 0x1180
movq -0x18(%rbp), %rdi
callq 0x1170
jmp 0x477f
movq 0x3b93(%rip), %rax      # 0x8198
movl -0x8(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movl $0x2c1, %esi            # imm = 0x2C1
movl $0x180, %edx            # imm = 0x180
movb $0x0, %al
callq 0x10d0
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jge 0x46a3
jmp 0x462e
movq 0x29ab(%rip), %rax      # 0x6fe0
movq (%rax), %rdi
movq 0x2b49(%rip), %rdx      # 0x7188
movq 0x3b52(%rip), %rax      # 0x8198
movl -0x8(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rcx
leaq 0xfd7(%rip), %rsi       # 0x5631
movb $0x0, %al
callq 0x11b0
movq 0x2978(%rip), %rax      # 0x6fe0
movq (%rax), %rdi
leaq 0x9ca(%rip), %rsi       # 0x503c
leaq 0xf75(%rip), %rdx       # 0x55ee
leaq 0x9d1(%rip), %rcx       # 0x5051
movl $0x1fb, %r8d            # imm = 0x1FB
movb $0x0, %al
callq 0x11b0
leaq 0xa88(%rip), %rdi       # 0x511c
callq 0x1100
movl $0x1, %edi
callq 0x1180
movq 0x3aee(%rip), %rax      # 0x8198
movl -0x8(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $0x0, 0x18(%rax)
je 0x4777
movl -0xc(%rbp), %edi
movq 0x3ad0(%rip), %rax      # 0x8198
movl -0x8(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
movq 0x3abb(%rip), %rax      # 0x8198
movl -0x8(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movl %eax, %edx
callq 0x1080
movq 0x3aa0(%rip), %rcx      # 0x8198
movl -0x8(%rbp), %edx
shlq $0x5, %rdx
addq %rdx, %rcx
movl 0x18(%rcx), %ecx
cmpq %rcx, %rax
je 0x4775
jmp 0x470c
movq 0x28cd(%rip), %rax      # 0x6fe0
movq (%rax), %rdi
movq 0x2a6b(%rip), %rdx      # 0x7188
movq 0x3a74(%rip), %rax      # 0x8198
movl -0x8(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rcx
leaq 0xf28(%rip), %rsi       # 0x5660
movb $0x0, %al
callq 0x11b0
movq 0x289a(%rip), %rax      # 0x6fe0
movq (%rax), %rdi
leaq 0x8ec(%rip), %rsi       # 0x503c
leaq 0xe97(%rip), %rdx       # 0x55ee
leaq 0x8f3(%rip), %rcx       # 0x5051
movl $0x1ff, %r8d            # imm = 0x1FF
movb $0x0, %al
callq 0x11b0
movl $0x1, %edi
callq 0x1180
jmp 0x4777
movl -0xc(%rbp), %edi
callq 0x12a0
leaq 0x2a0a(%rip), %rdi      # 0x7190
callq 0x11e0
cmpl $0x0, %eax
je 0x47e0
jmp 0x4792
movq 0x2847(%rip), %rax      # 0x6fe0
movq (%rax), %rdi
leaq 0xeeb(%rip), %rsi       # 0x568e
movb $0x0, %al
callq 0x11b0
movq 0x282f(%rip), %rax      # 0x6fe0
movq (%rax), %rdi
leaq 0x881(%rip), %rsi       # 0x503c
leaq 0xe2c(%rip), %rdx       # 0x55ee
leaq 0x888(%rip), %rcx       # 0x5051
movl $0x205, %r8d            # imm = 0x205
movb $0x0, %al
callq 0x11b0
movl $0x1, %edi
callq 0x1180
jmp 0x47e2
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x4385
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl 0x3990(%rip), %eax      # 0x8190
jae 0x48c0
movq 0x398b(%rip), %rax      # 0x8198
movl -0x8(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $0x0, 0x18(%rax)
je 0x4883
movl -0x4(%rbp), %edi
movq 0x3971(%rip), %rax      # 0x8198
movl -0x8(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
movq 0x395c(%rip), %rax      # 0x8198
movl -0x8(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movl %eax, %edx
callq 0x1080
movq 0x3941(%rip), %rcx      # 0x8198
movl -0x8(%rbp), %edx
shlq $0x5, %rdx
addq %rdx, %rcx
movl 0x18(%rcx), %ecx
cmpq %rcx, %rax
je 0x4881
movq 0x2770(%rip), %rax      # 0x6fe0
movq (%rax), %rdi
leaq 0xe4f(%rip), %rsi       # 0x56c9
movb $0x0, %al
callq 0x11b0
jmp 0x48b0
movq 0x390e(%rip), %rax      # 0x8198
movl -0x8(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
cmpb $0x0, 0x10(%rax)
je 0x48ae
movl -0x4(%rbp), %edi
leaq -0x1020(%rbp), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x11c0
jmp 0x48b0
jmp 0x48b2
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x47f7
addq $0x1030, %rsp           # imm = 0x1030
popq %rbp
retq