// File: /workspace/github_c_makefile_star2_O1/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 $0x1288, %rsp           # imm = 0x1288
cmpl $0x2, %edi
jl 0x3a01
movq %rsi, %r14
movl %edi, %ebp
movq $0x0, 0x18(%rsp)
movl $0x1, %ebx
movb $0x6, %r12b
leaq 0x8e24(%rip), %r15      # 0xc749
movq $0x0, 0x10(%rsp)
movslq %ebx, %rax
movq (%r14,%rax,8), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x2170
testl %eax, %eax
je 0x39a3
movq %r13, %rdi
leaq 0x8dfe(%rip), %rsi      # 0xc74c
callq 0x2170
testl %eax, %eax
je 0x39a8
movq %r13, %rdi
leaq 0x8dee(%rip), %rsi      # 0xc74f
callq 0x2170
testl %eax, %eax
je 0x39ad
movq %r13, %rdi
leaq 0x8e00(%rip), %rsi      # 0xc774
callq 0x2170
testl %eax, %eax
je 0x39de
cmpb $0x2d, (%r13)
je 0x3b0c
cmpq $0x0, 0x10(%rsp)
jne 0x3b0c
movq %r13, %rdi
callq 0x3020
movq %rax, 0x10(%rsp)
jmp 0x39e8
movb $0x32, %r12b
jmp 0x39e8
movb $0xa, %r12b
jmp 0x39e8
incl %ebx
cmpl %ebp, %ebx
jge 0x3b0c
movslq %ebx, %r13
movq (%r14,%r13,8), %rdi
movq 0xd613(%rip), %rax      # 0x10fd8
movq (%rax), %rdx
leaq 0x8d83(%rip), %rsi      # 0xc752
callq 0x2130
testq %rax, %rax
jne 0x39e8
jmp 0x3b11
movl $0x1, %eax
movq %rax, 0x18(%rsp)
incl %ebx
cmpl %ebp, %ebx
jl 0x392e
cmpl $0x0, 0x18(%rsp)
sete %al
movq 0x10(%rsp), %rcx
jmp 0x3a08
movb $0x1, %al
movb $0x6, %r12b
xorl %ecx, %ecx
testq %rcx, %rcx
je 0x3b0c
movq %rcx, %rbx
testb %al, %al
jne 0x3a45
movq %rbx, %rdi
movl $0x2f, %esi
callq 0x2100
testq %rax, %rax
je 0x3a45
movq %rax, %r14
movb $0x0, (%rax)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x30fa
testl %eax, %eax
jne 0x3a5a
movb $0x2f, (%r14)
movzbl %r12b, %edx
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x531a
testl %eax, %eax
je 0x3a70
movl %eax, %ebp
movl %ebp, %eax
addq $0x1288, %rsp           # imm = 0x1288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xd561(%rip), %r13      # 0x10fd8
leaq 0x280(%rsp), %r14
leaq 0x20(%rsp), %r15
leaq 0xc(%rsp), %r12
xorl %ebp, %ebp
movq (%r13), %rcx
movl $0x1, %esi
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rdi
callq 0x20c0
movq %rax, %rbx
testl %ebx, %ebx
je 0x3ac6
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
movq %r12, %rcx
callq 0x683e
testl %eax, %eax
jne 0x3ac4
cmpl %ebx, 0xc(%rsp)
jae 0x3a8b
jmp 0x3ac6
movl %eax, %ebp
leaq 0x20(%rsp), %rdi
callq 0x719a
movq (%r13), %rdi
callq 0x20b0
testl %eax, %eax
jne 0x3b23
testl %ebx, %ebx
setne %al
testl %ebp, %ebp
setne %cl
testb %cl, %al
jne 0x3a5c
xorl %ebp, %ebp
testl %ebx, %ebx
je 0x3a5c
cmpl %ebx, 0xc(%rsp)
jae 0x3a5c
leaq 0x8c90(%rip), %rdi      # 0xc79a
jmp 0x3b2a
callq 0x28e0
movq (%r14,%r13,8), %rsi
leaq 0x8c39(%rip), %rdi      # 0xc755
xorl %eax, %eax
callq 0x2aec
leaq 0x8c4d(%rip), %rdi      # 0xc777
xorl %eax, %eax
callq 0x2aec