// File: /workspace/github_c_makefile_star2_O2/lb3361[P]dosfs/dosfs.c
// Function: doswrite
FRESULT doswrite(int argc, const char **argv)
{
  int i;
  char *s;
  char *path = 0;
  BYTE mode = FA_WRITE | FA_CREATE_NEW;
  FRESULT res;
  FIL fil;
  char buffer[4096];
  UINT nread, nwritten;
  int dflag = 0;

  for (i=1; i<argc; i++) {
    if (! strcmp(argv[i],"-a"))
      mode = FA_WRITE | FA_OPEN_APPEND;
    else if (! strcmp(argv[i],"-q"))
      mode = FA_WRITE | FA_CREATE_ALWAYS;
    else if (! strcmp(argv[i],"-i")) {
      if (++i >= argc)
        goto usage;
      if (! freopen(argv[i], "rb", stdin))
        fatal("Cannot open '%s' for reading.\n", argv[i]);
    } else if (! strcmp(argv[i],"-d"))
      dflag = 1;
    else if (argv[i][0] == '-')
      goto usage;
    else if (! path)
      path = fix_path(argv[i]);
    else
      goto usage;
  }
  if (!path) {
  usage:
    doswritehelp();
    exit(EXIT_FAILURE);
  }
#ifdef WIN32
  fflush(stdin);
  _setmode(_fileno(stdin), O_BINARY);
#endif
  if (dflag && (s = strrchr(path, '/'))) {
    *s = 0;
    if ((res = rmkdir(path, 1)) != FR_OK)
      return res;
    *s = '/';
  }
  res = f_open(&fil, path, mode);
  if (res != FR_OK)
    return res;
  for(;;) {
    nread = fread(buffer, 1, sizeof(buffer), stdin);
    if (nread == 0)
      break;
    res = f_write(&fil, buffer, nread, &nwritten);
    if (res != FR_OK)
      break;
    if (nwritten < nread)
      break;
  }
  f_close(&fil);
  if (ferror(stdin))
    fatal("I/O error reading data from stdin\n");
  if (nread && res != FR_OK)
    return res;
  if (nread && nwritten < nread)
    fatal("Filesystem is full\n");
  return FR_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1278, %rsp           # imm = 0x1278
movq %rsi, %r14
movl %edi, %ebp
xorl %ebx, %ebx
movb $0x6, 0xb(%rsp)
pushq $0x1
popq %r13
xorl %r15d, %r15d
cmpl %ebp, %r13d
jge 0x34e9
movslq %r13d, %rax
movq (%r14,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x3485
cmpb $0x61, 0x1(%rdi)
jne 0x3454
cmpb $0x0, 0x2(%rdi)
je 0x349b
cmpb $0x71, 0x1(%rdi)
jne 0x3460
cmpb $0x0, 0x2(%rdi)
je 0x34a2
cmpb $0x69, 0x1(%rdi)
jne 0x346c
cmpb $0x0, 0x2(%rdi)
je 0x34a9
cmpb $0x64, 0x1(%rdi)
jne 0x35ef
cmpb $0x0, 0x2(%rdi)
pushq $0x1
popq %r15
je 0x3496
jmp 0x35ef
testq %rbx, %rbx
jne 0x35ef
callq 0x2b76
movq %rax, %rbx
incl %r13d
jmp 0x3433
movb $0x32, 0xb(%rsp)
jmp 0x3496
movb $0xa, 0xb(%rsp)
jmp 0x3496
incl %r13d
cmpl %ebp, %r13d
jge 0x35ef
movslq %r13d, %r12
movq (%r14,%r12,8), %rdi
movq 0xdb15(%rip), %rax      # 0x10fd8
movq (%rax), %rdx
leaq 0x8270(%rip), %rsi      # 0xb73d
callq 0x2120
testq %rax, %rax
jne 0x3496
movq (%r14,%r12,8), %rsi
leaq 0x825e(%rip), %rdi      # 0xb740
xorl %eax, %eax
callq 0x234c
testq %rbx, %rbx
je 0x35ef
testl %r15d, %r15d
je 0x3520
pushq $0x2f
popq %rsi
movq %rbx, %rdi
callq 0x20f0
testq %rax, %rax
je 0x3520
movq %rax, %r14
movb $0x0, (%rax)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x2c4e
testl %eax, %eax
jne 0x3536
movb $0x2f, (%r14)
movzbl 0xb(%rsp), %edx
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x4cea
testl %eax, %eax
je 0x354c
movl %eax, %ebp
movl %ebp, %eax
addq $0x1278, %rsp           # imm = 0x1278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x270(%rsp), %r14
pushq $0x1
popq %r15
leaq 0x10(%rsp), %r12
leaq 0xc(%rsp), %r13
xorl %ebp, %ebp
movq 0xda6d(%rip), %rax      # 0x10fd8
movq (%rax), %rcx
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rdi
movq %r15, %rsi
callq 0x20b0
movq %rax, %rbx
testl %ebx, %ebx
je 0x35a3
movq %r12, %rdi
movq %r14, %rsi
movl %ebx, %edx
movq %r13, %rcx
callq 0x60d9
testl %eax, %eax
jne 0x35a1
cmpl %ebx, 0xc(%rsp)
jae 0x3564
jmp 0x35a3
movl %eax, %ebp
leaq 0x10(%rsp), %rdi
callq 0x6983
movq 0xda24(%rip), %rax      # 0x10fd8
movq (%rax), %rdi
callq 0x20a0
testl %eax, %eax
jne 0x35fc
testl %ebx, %ebx
setne %al
testl %ebp, %ebp
setne %cl
testb %cl, %al
jne 0x3538
xorl %ebp, %ebp
testl %ebx, %ebx
je 0x3538
cmpl %ebx, 0xc(%rsp)
jae 0x3538
leaq 0x8195(%rip), %rdi      # 0xb782
jmp 0x3603
callq 0x33c9
pushq $0x1
popq %rdi
callq 0x2220
leaq 0x815c(%rip), %rdi      # 0xb75f
xorl %eax, %eax
callq 0x234c