/* WARNING: Removing unreachable block (ram,0x00405a38) */
/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

undefined4 FUN_0040581c(void)

{
  FILE *pFVar1;
  char *pcVar2;
  undefined4 uVar3;
  undefined4 *puVar4;
  char *pcVar5;
  int iVar6;
  int iVar7;
  timeval local_128;
  timeval local_120;
  char acStack_118 [256];
  
  pFVar1 = (FILE *)FUN_00405280(&DAT_0040fec0);
  if (pFVar1 == (FILE *)0x0) {
    FUN_00405180("Unable to open device for reading !!\n");
  }
  else {
    FUN_00405430(pFVar1);
    fclose(pFVar1);
  }
  while (puVar4 = DAT_00422a50, DAT_00422a50 != (undefined4 *)0x0) {
    pcVar5 = (char *)DAT_00422a50[1];
    DAT_00422a50 = (undefined4 *)*DAT_00422a50;
    if (pcVar5 != (char *)0x0) {
      pcVar2 = strchr(pcVar5,0x3d);
      if (pcVar2 != (char *)0x0) {
        *pcVar2 = '\0';
        pcVar2 = pcVar2 + 1;
      }
      FUN_00405180("set %s = [%s]\n",pcVar5,pcVar2);
      FUN_004052ec(pcVar5,pcVar2);
      free((void *)puVar4[1]);
    }
    free(puVar4);
  }
  pFVar1 = (FILE *)FUN_00405280(&DAT_004107a4);
  if (pFVar1 == (FILE *)0x0) {
    fputs("Unable to open device for writting !!\n",_stderr);
    uVar3 = 0xffffffff;
  }
  else {
    gettimeofday(&local_128,(__timezone_ptr_t)0x0);
    FUN_004055e0(pFVar1);
    fclose(pFVar1);
    gettimeofday(&local_120,(__timezone_ptr_t)0x0);
    uVar3 = 0;
    if (DAT_00422a4c != 0) {
      iVar7 = local_120.tv_usec - local_128.tv_usec;
      if (iVar7 < 0) {
        local_120.tv_sec = local_120.tv_sec + -1;
        iVar7 = iVar7 + 1000000;
      }
      iVar6 = local_120.tv_sec - local_128.tv_sec;
      FUN_00405180("flash burn from %d:%d - %d:%d\n",local_128.tv_sec,local_128.tv_usec,
                   local_120.tv_sec,local_120.tv_usec);
      FUN_00405180("cost %d sec(s), %d usec(s)\n",iVar6,iVar7);
      iVar7 = iVar7 / 1000 + iVar6 * 1000;
      FUN_00405180("cost %d millisecond(s)\n",iVar7);
      sprintf(acStack_118,"flashspeed=%u",iVar7)   //possible issue identified - semgrep
      FUN_00405180("setenv %s\n",acStack_118);
      puVar4 = (undefined4 *)malloc(8)   //possible issue identified - semgrep
      if (puVar4 != (undefined4 *)0x0) {
        pcVar5 = strdup(acStack_118)   //possible issue identified - semgrep
        puVar4[1] = pcVar5;
        *puVar4 = DAT_00422a50;
        DAT_00422a50 = puVar4;
        DAT_00422a4c = 0;
        FUN_0040581c();
      }
      uVar3 = 0;
    }
  }
  return uVar3;
}