// File: /workspace/github_c_makefile_star2_O0/Matthias-Wandel[P]imgcomp/src/start_camera_prog.c
// Function: relaunch_camera_prog
int relaunch_camera_prog(void)
{
    // Kill raspistill or libcamera if it's already running.
    if (camera_prog_pid){
        kill(camera_prog_pid,SIGKILL);
        // If we launched the camera program (raspistill or libcamera), 
		// need to call wait() so that we dont' accumulate an army of child zombie processes
        int exit_code = 123;
        int a;
        time_t then, now = time(NULL);
        a = wait(&exit_code);
        fprintf(Log,"Child exit code %d, wait returned %d",exit_code, a);
        then = time(NULL);
        fprintf(Log," At %02d:%02d (%d s)\n",(int)(then%3600)/60, (int)(then%60), (int)(then-now));
    } else {
        // kill libcamera or raspistill if it was already launched when we started.
		// In that case, we don't have a PID for it.
		char KillCmd[100];
		for (int a=0;a<80;a++){
			// Search for first space to get capture command name.
			if (camera_prog_cmd[a] == ' '){ 
				snprintf(KillCmd, 99, "killall -9 %.*s",a,camera_prog_cmd);
				(void)system(KillCmd);
				break;
			}
		}
    }

    fprintf(Log,"Launching camera program\n");

    int DashOOption = (strstr(camera_prog_cmd, " -o ") != NULL);

    static char cmd_appended[300];
    strncpy(cmd_appended, camera_prog_cmd, 200);

    if (strncmp(cmd_appended, "raspistill", 10) == 0) { // check if the aquire cmd is actually a raspistill cmd
        if (ExposureManagementOn) { // Exposure managemnt by imgcomp
            strcat(cmd_appended, GetRaspistillExpParms());
            if (DashOOption){
                fprintf(stderr, "Must not specify -o option with -exm option\n");
                exit(-1);
            }
        }

        if (!DashOOption){
            // No output specified with raspistill command  Add the option,
            // with a different prefix each time so numbers don't overlap.
            int l = strlen(cmd_appended);
            sprintf(cmd_appended+l," -o %s/out%c%%05d.jpg",DoDirName, OutNameSeq++);
            if (OutNameSeq >= 'z') OutNameSeq = 'a';
            //fprintf(Log,"Run program: %s\n",cmd_appended);
        }
    }
    else {
        fprintf(stderr, "aquire_cmd was not raspistill, not setting output or exposure settings\n");
    }

    camera_prog_pid = do_launch_program(cmd_appended);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
cmpl $0x0, 0xb4fe(%rip)      # 0x165b0
je 0xb16f
movl 0xb4f2(%rip), %edi      # 0x165b0
movl $0x9, %esi
callq 0x32d0
movl $0x7b, -0x4(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x3300
movq %rax, -0x18(%rbp)
leaq -0x4(%rbp), %rdi
callq 0x34d0
movl %eax, -0x8(%rbp)
leaq 0x9f29(%rip), %rax      # 0x15018
movq (%rax), %rdi
movl -0x4(%rbp), %edx
movl -0x8(%rbp), %ecx
leaq 0x5e19(%rip), %rsi      # 0x10f18
movb $0x0, %al
callq 0x3290
xorl %eax, %eax
movl %eax, %edi
callq 0x3300
movq %rax, -0x10(%rbp)
leaq 0x9efe(%rip), %rax      # 0x15018
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl $0xe10, %ecx            # imm = 0xE10
cqto
idivq %rcx
movl %edx, %eax
movl $0x3c, %ecx
cltd
idivl %ecx
movl %eax, -0x90(%rbp)
movq -0x10(%rbp), %rax
movl $0x3c, %ecx
cqto
idivq %rcx
movq %rdx, %rax
movl -0x90(%rbp), %edx
movl %eax, %ecx
movq -0x10(%rbp), %rax
subq -0x18(%rbp), %rax
movl %eax, %r8d
leaq 0x5dd7(%rip), %rsi      # 0x10f3d
movb $0x0, %al
callq 0x3290
jmp 0xb1dd
movl $0x0, -0x84(%rbp)
cmpl $0x50, -0x84(%rbp)
jge 0xb1db
movslq -0x84(%rbp), %rcx
leaq 0x9ea0(%rip), %rax      # 0x15030
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jne 0xb1c8
leaq -0x80(%rbp), %rdi
movl -0x84(%rbp), %ecx
movl $0x63, %esi
leaq 0x5da4(%rip), %rdx      # 0x10f53
leaq 0x9e7a(%rip), %r8       # 0x15030
movb $0x0, %al
callq 0x3190
leaq -0x80(%rbp), %rdi
callq 0x3150
jmp 0xb1db
jmp 0xb1ca
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0xb179
jmp 0xb1dd
leaq 0x9e34(%rip), %rax      # 0x15018
movq (%rax), %rdi
leaq 0x5d75(%rip), %rsi      # 0x10f63
movb $0x0, %al
callq 0x3290
leaq 0x9e34(%rip), %rdi      # 0x15030
leaq 0x5d7a(%rip), %rsi      # 0x10f7d
callq 0x34f0
cmpq $0x0, %rax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x88(%rbp)
leaq 0xb39f(%rip), %rdi      # 0x165c0
leaq 0x9e08(%rip), %rsi      # 0x15030
movl $0xc8, %edx
callq 0x3090
leaq 0xb387(%rip), %rdi      # 0x165c0
leaq 0x5d42(%rip), %rsi      # 0x10f82
movl $0xa, %edx
callq 0x30a0
cmpl $0x0, %eax
jne 0xb30e
leaq 0x9796(%rip), %rax      # 0x149f0
cmpl $0x0, (%rax)
je 0xb2a2
movb $0x0, %al
callq 0xce50
movq %rax, %rsi
leaq 0xb350(%rip), %rdi      # 0x165c0
callq 0x3460
cmpl $0x0, -0x88(%rbp)
je 0xb2a0
movq 0x8d6b(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x5cfe(%rip), %rsi      # 0x10f8d
movb $0x0, %al
callq 0x3290
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3480
jmp 0xb2a2
cmpl $0x0, -0x88(%rbp)
jne 0xb30c
leaq 0xb30e(%rip), %rdi      # 0x165c0
callq 0x3130
movl %eax, -0x8c(%rbp)
movslq -0x8c(%rbp), %rax
leaq 0xb2f5(%rip), %rdi      # 0x165c0
addq %rax, %rdi
movb 0x904c(%rip), %al       # 0x14320
movb %al, %cl
addb $0x1, %cl
movb %cl, 0x9041(%rip)       # 0x14320
movsbl %al, %ecx
leaq 0x5cd1(%rip), %rsi      # 0x10fba
leaq 0x9720(%rip), %rdx      # 0x14a10
movb $0x0, %al
callq 0x3470
movsbl 0x9022(%rip), %eax      # 0x14320
cmpl $0x7a, %eax
jl 0xb30a
movb $0x61, 0x9016(%rip)     # 0x14320
jmp 0xb30c
jmp 0xb326
movq 0x8cdb(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x5cb1(%rip), %rsi      # 0x10fd0
movb $0x0, %al
callq 0x3290
leaq 0xb293(%rip), %rdi      # 0x165c0
callq 0xb350
movl %eax, 0xb278(%rip)      # 0x165b0
xorl %eax, %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)