// File: /workspace/github_c_makefile_star2_O3/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
cmpl $0x2, %edi
jl 0x3a97
movq %rsi, %r14
movl %edi, %ebp
movl $0x1, %r15d
movb $0x6, 0xb(%rsp)
xorl %r13d, %r13d
xorl %ebx, %ebx
movslq %r15d, %rax
movq (%r14,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x392b
cmpb $0x61, 0x1(%rdi)
jne 0x38f8
cmpb $0x0, 0x2(%rdi)
je 0x3946
cmpb $0x71, 0x1(%rdi)
jne 0x3904
cmpb $0x0, 0x2(%rdi)
je 0x394d
cmpb $0x69, 0x1(%rdi)
jne 0x3910
cmpb $0x0, 0x2(%rdi)
je 0x3954
cmpb $0x64, 0x1(%rdi)
jne 0x3a97
movl $0x1, %r13d
cmpb $0x0, 0x2(%rdi)
je 0x393c
jmp 0x3a97
testq %rbx, %rbx
jne 0x3a97
callq 0x304e
movq %rax, %rbx
incl %r15d
cmpl %ebp, %r15d
jl 0x38e0
jmp 0x3994
movb $0x32, 0xb(%rsp)
jmp 0x393c
movb $0xa, 0xb(%rsp)
jmp 0x393c
incl %r15d
cmpl %ebp, %r15d
jge 0x3a97
movslq %r15d, %r12
movq (%r14,%r12,8), %rdi
movq 0xd66a(%rip), %rax      # 0x10fd8
movq (%rax), %rdx
leaq 0x8dc5(%rip), %rsi      # 0xc73d
callq 0x2120
testq %rax, %rax
jne 0x393c
movq (%r14,%r12,8), %rsi
leaq 0x8db3(%rip), %rdi      # 0xc740
xorl %eax, %eax
callq 0x2b2c
testq %rbx, %rbx
je 0x3a97
testl %r13d, %r13d
movq 0xd631(%rip), %r13      # 0x10fd8
je 0x39d6
movq %rbx, %rdi
movl $0x2f, %esi
callq 0x20f0
testq %rax, %rax
je 0x39d6
movq %rax, %r14
movb $0x0, (%rax)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x3128
testl %eax, %eax
jne 0x39ec
movb $0x2f, (%r14)
movzbl 0xb(%rsp), %edx
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x5115
testl %eax, %eax
je 0x3a02
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
leaq 0x10(%rsp), %r15
leaq 0xc(%rsp), %r12
xorl %ebp, %ebp
movq (%r13), %rcx
movl $0x1, %esi
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rdi
callq 0x20b0
movq %rax, %rbx
testl %ebx, %ebx
je 0x3a51
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
movq %r12, %rcx
callq 0x663a
testl %eax, %eax
jne 0x3a4f
cmpl %ebx, 0xc(%rsp)
jae 0x3a16
jmp 0x3a51
movl %eax, %ebp
leaq 0x10(%rsp), %rdi
callq 0x6f40
movq (%r13), %rdi
callq 0x20a0
testl %eax, %eax
jne 0x3a9c
testl %ebx, %ebx
setne %al
testl %ebp, %ebp
setne %cl
testb %cl, %al
jne 0x39ee
xorl %ebp, %ebp
testl %ebx, %ebx
je 0x39ee
cmpl %ebx, 0xc(%rsp)
jae 0x39ee
leaq 0x8ced(%rip), %rdi      # 0xc782
jmp 0x3aa3
callq 0x28fc
leaq 0x8cbc(%rip), %rdi      # 0xc75f
xorl %eax, %eax
callq 0x2b2c