// File: /workspace/github_c_makefile_star2_O0/Matthias-Wandel[P]imgcomp/src/main.c
// Function: DoDirectory
int DoDirectory(char * Directory)
{
    int a;
    Raspistill_restarted = 0;

    if (!FollowDir){
        // Offline mode - just a one shot, no polling.
        return DoDirectoryFunc(Directory, FollowDir);
    }

    int wd, fd;
    fd = inotify_init();
    if (fd < 0) perror("inotify_init");

    // raspistill first writes under a temporary file name, ending with "~" then renames.
    // IN_MOVED_TO triggers when the file is renamed to the final file name.
    // But when using ffmpeg for the RTSP camera hack, ffmpeg writes the files under
    // the original name, so IN_CLOSE_WRITE is needed for that.
    wd = inotify_add_watch( fd, Directory, IN_CLOSE_WRITE | IN_MOVED_TO);
    if (wd < 0){
        fprintf(Log, "add watch failed\n");
        return 0;
    }

    for (;;){
        a = DoDirectoryFunc(Directory, FollowDir);
        DoMotionRun(a);

        int b = manage_camera_prog(NumProcessed);
        if (b) Raspistill_restarted = 1;
        if (LogToFile[0] != '\0') LogFileMaintain(0);

        // Wait for more files to appear.
        struct pollfd pfd = { fd, POLLIN, 0 };
        int ret = poll(&pfd, 1, 2000);
        if (ret < 0) {
            fprintf(Log, "select failed: %s\n", strerror(errno));
            sleep(1);
            continue;
        }
        if (ret == 0){
            // Timeout waiting for a new file.
            fprintf(Log, "wait file poll() timeout\n");
            continue;
        }

        // Read and ignore the event to clear it out.
        const int EVENT_BUF_LEN = 200;
        char buffer[EVENT_BUF_LEN];
        read( fd, buffer, EVENT_BUF_LEN );
    }

    return a;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
leaq 0x119f1(%rip), %rax     # 0x15024
movl $0x0, (%rax)
leaq 0x113a0(%rip), %rax     # 0x149e0
cmpl $0x0, (%rax)
jne 0x365f
movq -0x10(%rbp), %rdi
leaq 0x11390(%rip), %rax     # 0x149e0
movl (%rax), %esi
callq 0x37e0
movl %eax, -0x4(%rbp)
jmp 0x37d0
callq 0x32e0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x3679
leaq 0xa9a4(%rip), %rdi      # 0xe018
callq 0x3430
movl -0x1c(%rbp), %edi
movq -0x10(%rbp), %rsi
movl $0x88, %edx
callq 0x3350
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0x36b7
leaq 0x1197e(%rip), %rax     # 0x15018
movq (%rax), %rdi
leaq 0xa981(%rip), %rsi      # 0xe025
movb $0x0, %al
callq 0x3290
movl $0x0, -0x4(%rbp)
jmp 0x37d0
jmp 0x36b9
movq -0x10(%rbp), %rdi
leaq 0x1131c(%rip), %rax     # 0x149e0
movl (%rax), %esi
callq 0x37e0
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %edi
callq 0xb4f0
movl 0x10c88(%rip), %edi     # 0x14364
callq 0xb830
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x36f7
leaq 0x11933(%rip), %rax     # 0x15024
movl $0x1, (%rax)
leaq 0x11782(%rip), %rax     # 0x14e80
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x370d
xorl %edi, %edi
callq 0xc6d0
movl -0x1c(%rbp), %eax
movl %eax, -0x28(%rbp)
movw $0x1, -0x24(%rbp)
movw $0x0, -0x22(%rbp)
leaq -0x28(%rbp), %rdi
movl $0x1, %esi
movl $0x7d0, %edx            # imm = 0x7D0
callq 0x33b0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x3779
leaq 0x118d6(%rip), %rax     # 0x15018
movq (%rax), %rax
movq %rax, -0x40(%rbp)
callq 0x3070
movl (%rax), %edi
callq 0x34b0
movq -0x40(%rbp), %rdi
movq %rax, %rdx
leaq 0xa8d4(%rip), %rsi      # 0xe037
movb $0x0, %al
callq 0x3290
movl $0x1, %edi
callq 0x34c0
jmp 0x36b9
cmpl $0x0, -0x2c(%rbp)
jne 0x379c
leaq 0x11892(%rip), %rax     # 0x15018
movq (%rax), %rdi
leaq 0xa8ba(%rip), %rsi      # 0xe04a
movb $0x0, %al
callq 0x3290
jmp 0x36b9
movl $0xc8, -0x30(%rbp)
movq %rsp, %rax
movq %rax, -0x38(%rbp)
movq %rsp, %rsi
addq $-0xd0, %rsi
movq %rsi, %rsp
movl -0x1c(%rbp), %edi
movl $0xc8, %edx
callq 0x3200
movq -0x38(%rbp), %rax
movq %rax, %rsp
jmp 0x36b9
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax,%rax)