// File: /workspace/github_c_makefile_star2_O0/Matthias-Wandel[P]imgcomp/src/main.c
// Function: DoDirectoryVideos
int DoDirectoryVideos(char * DirName)
{
    int a,ret;
    int infileindex;
    int alt = 0;

    Raspistill_restarted = 0;
    infileindex = strstr(VidDecomposeCmd, "<infile>")-VidDecomposeCmd;

    if (infileindex <= 0){
        fprintf(stderr, "Must specify '<infile>' as part of videodecomposecmd\n");
        exit(-1);
    }

    for (;;){
        DirEntry_t * FileNames;
        int NumEntries;
        char VidFileName[200];
        char FFCmd[300];
        int Saw_motion;
        time_t now;
        int VideoActive = 0;

        NumProcessed = 0;
        alt += 1;

        FileNames = GetSortedDir(DirName, &NumEntries);
        if (FileNames == NULL){
            fprintf(stderr, "Could not read dir %s\n",DirName);
            return 0;
        }

        now = time(NULL);
        if (NumEntries != 1){
            fprintf(Log,"%d files to process",NumEntries);
            fprintf(Log, "(%02d:%02d)...\n",(int)(now%3600/60), (int)(now%60));
        }
        for (a=0;a<NumEntries;a++){
            int age;

            age = (int)(now-FileNames[a].MTime);
            if (age < 1){
                VideoActive = 1; // Video files getting updated.
                if (alt & 1 || NumEntries > 1){
                    // Print waiting only every other time to cut down on log clutter.
                    fprintf(Log, "Vid '%s' aged %d %dk (Wait)\n",FileNames[a].FileName, age, FileNames[a].FileSize>>10);
                }
                continue;
            }else{
                fprintf(Log,"Vid '%s': %dk Extract keyframes (%02d:%02d)...\n", FileNames[a].FileName, FileNames[a].FileSize>>10,
                    (int)(now%3600)/60, (int)(now%60));
            }

            strcpy(VidFileName, CatPath(DirName, FileNames[a].FileName));
            strncpy(FFCmd, VidDecomposeCmd, infileindex);
            FFCmd[infileindex] = 0;
            strcpy(FFCmd+infileindex, VidFileName);
            strcat(FFCmd, VidDecomposeCmd+infileindex+8);

            // Use timestamp of video file to sequence output file names (so we'll have the respective times for those)
            unsigned seq = (unsigned)FileNames[a].MTime - 1000000000;
            sprintf(FFCmd+strlen(FFCmd), " -start_number %u %s/sf%%d.jpg",seq, TempDirName);

            errno = 0;
            ret = system(FFCmd);
            if (ret || errno){
                // A command can however fail without errno getting set or system returning an error.
                if (errno) perror("system");
                fprintf(Log, "Error on command %s\n",FFCmd);
                continue;
            }

            // Now should have some files in temp dir.
            Saw_motion = DoDirectoryFunc(TempDirName, 1);
            if (Saw_motion){
                char * DstName;
                char * Ext;
                fprintf(Log,"Vid has motion %d\n", Saw_motion);
                // Make filename, but don't copy the file.
                DstName = BackupImageFile(VidFileName, Saw_motion,1);

                Ext = strstr(DstName, ".h264");
                if (Ext) strcpy(Ext, ".mp4"); // Change xtension to .mp4

                if (DstName){
                    sprintf(FFCmd,"MP4Box -add %s \"%s\"",VidFileName, DstName);
                    errno = 0;
                    ret = system(FFCmd);
                    if (ret || errno){
                        if (errno) perror("system");
                        fprintf(Log, "Error on command %s\n",FFCmd);
                        continue;
                    }
                }
            }

            if (FollowDir){
                //fprintf(Log, "Delete video %s\n",VidFileName);
                unlink(VidFileName);
            }
        }
        FreeDir(FileNames, NumEntries); // Free up the whole directory structure.

        if (FollowDir){
            int b = manage_camera_prog(VideoActive);
            if (b) Raspistill_restarted = 1;
            if (LogToFile[0] != '\0') LogFileMaintain(0);
            sleep(1);
        }else{
            break;
        }

    }
    return a;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movq %rdi, -0x10(%rbp)
movl $0x0, -0x20(%rbp)
leaq 0x112d7(%rip), %rax     # 0x15024
movl $0x0, (%rax)
leaq 0x11576(%rip), %rdi     # 0x152d0
leaq 0xa303(%rip), %rsi      # 0xe064
callq 0x34f0
leaq 0x11563(%rip), %rcx     # 0x152d0
subq %rcx, %rax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jg 0x3d9b
movq 0x10270(%rip), %rax     # 0x13ff0
movq (%rax), %rdi
leaq 0xa2e3(%rip), %rsi      # 0xe06d
movb $0x0, %al
callq 0x3290
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3480
jmp 0x3d9d
movl $0x0, -0x244(%rbp)
movl $0x0, 0x105b3(%rip)     # 0x14364
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0xbdf0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x3dfa
movq 0x10217(%rip), %rax     # 0x13ff0
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0xa2bc(%rip), %rsi      # 0xe0a3
movb $0x0, %al
callq 0x3290
movl $0x0, -0x4(%rbp)
jmp 0x42c0
xorl %eax, %eax
movl %eax, %edi
callq 0x3300
movq %rax, -0x240(%rbp)
cmpl $0x1, -0x2c(%rbp)
je 0x3e83
leaq 0x11201(%rip), %rax     # 0x15018
movq (%rax), %rdi
movl -0x2c(%rbp), %edx
leaq 0xa296(%rip), %rsi      # 0xe0ba
movb $0x0, %al
callq 0x3290
leaq 0x111e6(%rip), %rax     # 0x15018
movq (%rax), %rdi
movq -0x240(%rbp), %rax
movl $0xe10, %ecx            # imm = 0xE10
cqto
idivq %rcx
movq %rdx, %rax
movl $0x3c, %ecx
cqto
idivq %rcx
movl %eax, -0x268(%rbp)
movq -0x240(%rbp), %rax
movl $0x3c, %ecx
cqto
idivq %rcx
movq %rdx, %rax
movl -0x268(%rbp), %edx
movl %eax, %ecx
leaq 0xa28f(%rip), %rsi      # 0xe10b
movb $0x0, %al
callq 0x3290
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x4252
movq -0x240(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rcx
subq 0x8(%rcx), %rax
movl %eax, -0x248(%rbp)
cmpl $0x1, -0x248(%rbp)
jge 0x3f26
movl $0x1, -0x244(%rbp)
movl -0x20(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x3eda
cmpl $0x1, -0x2c(%rbp)
jle 0x3f21
leaq 0x11137(%rip), %rax     # 0x15018
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
movslq -0x14(%rbp), %rax
imulq $0x50, %rax, %rax
addq %rax, %rdx
addq $0x18, %rdx
movl -0x248(%rbp), %ecx
movq -0x28(%rbp), %rax
movslq -0x14(%rbp), %rsi
imulq $0x50, %rsi, %rsi
addq %rsi, %rax
movl (%rax), %r8d
shrl $0xa, %r8d
leaq 0xa1b4(%rip), %rsi      # 0xe0ce
movb $0x0, %al
callq 0x3290
jmp 0x4244
leaq 0x110eb(%rip), %rax     # 0x15018
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
addq $0x18, %rax
movq %rax, -0x270(%rbp)
movq -0x28(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %ecx
shrl $0xa, %ecx
movq -0x240(%rbp), %rax
movl $0xe10, %esi            # imm = 0xE10
cqto
idivq %rsi
movl %edx, %eax
movl $0x3c, %esi
cltd
idivl %esi
movl %eax, %r8d
movq -0x240(%rbp), %rax
movl $0x3c, %esi
cqto
idivq %rsi
movq %rdx, %rax
movq -0x270(%rbp), %rdx
movl %eax, %r9d
leaq 0xa14a(%rip), %rsi      # 0xe0eb
movb $0x0, %al
callq 0x3290
leaq -0x100(%rbp), %rax
movq %rax, -0x280(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movslq -0x14(%rbp), %rax
imulq $0x50, %rax, %rax
addq %rax, %rsi
addq $0x18, %rsi
callq 0xbaa0
movq -0x280(%rbp), %rdi
movq %rax, %rsi
callq 0x30b0
leaq -0x230(%rbp), %rdi
movslq -0x1c(%rbp), %rdx
leaq 0x112dd(%rip), %rsi     # 0x152d0
callq 0x3090
movslq -0x1c(%rbp), %rax
movb $0x0, -0x230(%rbp,%rax)
leaq -0x230(%rbp), %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
leaq -0x100(%rbp), %rsi
callq 0x30b0
leaq -0x230(%rbp), %rdi
movslq -0x1c(%rbp), %rax
leaq 0x112a0(%rip), %rsi     # 0x152d0
addq %rax, %rsi
addq $0x8, %rsi
callq 0x3460
movq -0x28(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
subl $0x3b9aca00, %eax       # imm = 0x3B9ACA00
movl %eax, -0x24c(%rbp)
leaq -0x230(%rbp), %rax
movq %rax, -0x278(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x3130
movq -0x278(%rbp), %rdi
addq %rax, %rdi
movl -0x24c(%rbp), %edx
leaq 0xa090(%rip), %rsi      # 0xe11b
leaq 0x1130e(%rip), %rcx     # 0x153a0
movb $0x0, %al
callq 0x3470
callq 0x3070
movl $0x0, (%rax)
leaq -0x230(%rbp), %rdi
callq 0x3150
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x40c3
callq 0x3070
cmpl $0x0, (%rax)
je 0x40fd
callq 0x3070
cmpl $0x0, (%rax)
je 0x40d9
leaq 0xa066(%rip), %rdi      # 0xe13a
callq 0x3430
leaq 0x10f38(%rip), %rax     # 0x15018
movq (%rax), %rdi
leaq -0x230(%rbp), %rdx
leaq 0xa050(%rip), %rsi      # 0xe141
movb $0x0, %al
callq 0x3290
jmp 0x4244
leaq 0x1129c(%rip), %rdi     # 0x153a0
movl $0x1, %esi
callq 0x37e0
movl %eax, -0x234(%rbp)
cmpl $0x0, -0x234(%rbp)
je 0x422a
leaq 0x10ef0(%rip), %rax     # 0x15018
movq (%rax), %rdi
movl -0x234(%rbp), %edx
leaq 0xa01e(%rip), %rsi      # 0xe156
movb $0x0, %al
callq 0x3290
leaq -0x100(%rbp), %rdi
movl -0x234(%rbp), %esi
movl $0x1, %edx
callq 0xc020
movq %rax, -0x258(%rbp)
movq -0x258(%rbp), %rdi
leaq 0x9ffe(%rip), %rsi      # 0xe169
callq 0x34f0
movq %rax, -0x260(%rbp)
cmpq $0x0, -0x260(%rbp)
je 0x4194
movq -0x260(%rbp), %rdi
leaq 0x9fe0(%rip), %rsi      # 0xe16f
callq 0x30b0
cmpq $0x0, -0x258(%rbp)
je 0x4228
leaq -0x230(%rbp), %rdi
leaq -0x100(%rbp), %rdx
movq -0x258(%rbp), %rcx
leaq 0x9fb6(%rip), %rsi      # 0xe174
movb $0x0, %al
callq 0x3470
callq 0x3070
movl $0x0, (%rax)
leaq -0x230(%rbp), %rdi
callq 0x3150
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x41ef
callq 0x3070
cmpl $0x0, (%rax)
je 0x4226
callq 0x3070
cmpl $0x0, (%rax)
je 0x4205
leaq 0x9f3a(%rip), %rdi      # 0xe13a
callq 0x3430
leaq 0x10e0c(%rip), %rax     # 0x15018
movq (%rax), %rdi
leaq -0x230(%rbp), %rdx
leaq 0x9f24(%rip), %rsi      # 0xe141
movb $0x0, %al
callq 0x3290
jmp 0x4244
jmp 0x4228
jmp 0x422a
leaq 0x107af(%rip), %rax     # 0x149e0
cmpl $0x0, (%rax)
je 0x4242
leaq -0x100(%rbp), %rdi
callq 0x3080
jmp 0x4244
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x3e8a
movq -0x28(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0xc000
leaq 0x1077b(%rip), %rax     # 0x149e0
cmpl $0x0, (%rax)
je 0x42b3
movl -0x244(%rbp), %edi
callq 0xb830
movl %eax, -0x264(%rbp)
cmpl $0x0, -0x264(%rbp)
je 0x4291
leaq 0x10d99(%rip), %rax     # 0x15024
movl $0x1, (%rax)
leaq 0x10be8(%rip), %rax     # 0x14e80
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x42a7
xorl %edi, %edi
callq 0xc6d0
movl $0x1, %edi
callq 0x34c0
jmp 0x42b5
jmp 0x42ba
jmp 0x3d9d
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
nopl (%rax)