// File: /workspace/github_c_makefile_star2_O0/NTU-ROSE[P]Hikvision_Video_Downloader/./Hikvision_Video_Downloader.cpp
// Function: main
int main(int argc, char** argv) {
    //---------------------------------------
    // 初始化
    NET_DVR_Init(); //设置连接时间与重连时间 
    NET_DVR_SetConnectTime(2000, 1); 
    NET_DVR_SetReconnect(10000, true);
    
    LONG lUserID;
    NET_DVR_DEVICEINFO_V30 struDeviceInfo;
    lUserID = NET_DVR_Login_V30(argv[1], 8000, argv[2], argv[3], &struDeviceInfo); 
    if (lUserID < 0)
    {
    printf("Login error, %d\n", NET_DVR_GetLastError()); NET_DVR_Cleanup();
    return 0;
    }
     
    NET_DVR_PLAYCOND struDownloadCond={0};
    struDownloadCond.dwChannel= atoi(argv[4]); //通道号
    struDownloadCond.struStartTime.dwYear = atoi(argv[5]);
    struDownloadCond.struStartTime.dwMonth = atoi(argv[6]);
    struDownloadCond.struStartTime.dwDay = atoi(argv[7]);
    struDownloadCond.struStartTime.dwHour = atoi(argv[8]);
    struDownloadCond.struStartTime.dwMinute = atoi(argv[9]); 
    struDownloadCond.struStartTime.dwSecond =atoi(argv[10]);
    
    struDownloadCond.struStopTime.dwYear = atoi(argv[5]);
    struDownloadCond.struStopTime.dwMonth = atoi(argv[6]);
    struDownloadCond.struStopTime.dwDay = atoi(argv[7]);
    struDownloadCond.struStopTime.dwHour = atoi(argv[11]);
    struDownloadCond.struStopTime.dwMinute = atoi(argv[12]);
    struDownloadCond.struStopTime.dwSecond = atoi(argv[13]);
    //---------------------------------------
    //按时间下载
    int hPlayback;
    hPlayback = NET_DVR_GetFileByTime_V40(lUserID, argv[14],&struDownloadCond);
    if(hPlayback < 0)
    {
    printf("NET_DVR_GetFileByTime_V40 fail,last error %d\n",NET_DVR_GetLastError());
    NET_DVR_Logout(lUserID);
    NET_DVR_Cleanup();
    return 0;
    }
    
    if(!NET_DVR_PlayBackControl_V40(hPlayback, NET_DVR_PLAYSTART, NULL, 0, NULL,NULL))
    {
        printf("Play back control failed [%d]\n",NET_DVR_GetLastError());
        NET_DVR_Logout(lUserID); 
        NET_DVR_Cleanup(); 
        return 0 ;
    }
    
    int nPos = 0;
    for(nPos = 0; nPos < 100&&nPos>=0; nPos = NET_DVR_GetDownloadPos(hPlayback)) 
    {
        printf("Be downloading... %d %%\n",nPos); //下载进度
        usleep(5000); //millisecond 
    }
    
    
    if(!NET_DVR_StopGetFile(hPlayback)) {
        printf("failed to stop get file [%d]\n",NET_DVR_GetLastError());
        NET_DVR_Logout(lUserID);
        NET_DVR_Cleanup();
        return 0;
    }
    
    if(nPos<0||nPos>100) {
        printf("download err [%d]\n",NET_DVR_GetLastError()); NET_DVR_Logout(lUserID);
        NET_DVR_Cleanup();
        return 0;
    }
    
    printf("Be downloading... %d %%\n",nPos);
    
    //注销用户 
    NET_DVR_Logout(lUserID); 
    //释放 SDK 资源 
    NET_DVR_Cleanup(); 
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x1060
movl $0x7d0, %edi            # imm = 0x7D0
movl $0x1, %esi
callq 0x1120
movl $0x2710, %edi           # imm = 0x2710
movl $0x1, %esi
callq 0x1090
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movl $0x1f40, %esi           # imm = 0x1F40
leaq -0x64(%rbp), %r8
callq 0x1040
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x1311
callq 0x10e0
movl %eax, %esi
leaq 0xd0b(%rip), %rdi       # 0x2004
movb $0x0, %al
callq 0x1030
callq 0x10c0
movl $0x0, -0x4(%rbp)
jmp 0x15d1
leaq -0xd8(%rbp), %rdi
xorl %esi, %esi
movl $0x74, %edx
callq 0x1050
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x1110
movl %eax, -0xd8(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x1110
movl %eax, -0xd4(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x1110
movl %eax, -0xd0(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x1110
movl %eax, -0xcc(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x1110
movl %eax, -0xc8(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x1110
movl %eax, -0xc4(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x1110
movl %eax, -0xc0(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x1110
movl %eax, -0xbc(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x1110
movl %eax, -0xb8(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x1110
movl %eax, -0xb4(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x1110
movl %eax, -0xb0(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x1110
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x1110
movl %eax, -0xa8(%rbp)
movl -0x14(%rbp), %edi
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rsi
leaq -0xd8(%rbp), %rdx
callq 0x1080
movl %eax, -0xdc(%rbp)
cmpl $0x0, -0xdc(%rbp)
jge 0x146f
callq 0x10e0
movl %eax, %esi
leaq 0xbc6(%rip), %rdi       # 0x2015
movb $0x0, %al
callq 0x1030
movl -0x14(%rbp), %edi
callq 0x1130
callq 0x10c0
movl $0x0, -0x4(%rbp)
jmp 0x15d1
movl -0xdc(%rbp), %edi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %r9d
xorl %ecx, %ecx
movq %r9, %rdx
movq %r9, %r8
callq 0x10a0
cmpl $0x0, %eax
jne 0x14bf
callq 0x10e0
movl %eax, %esi
leaq 0xba4(%rip), %rdi       # 0x2043
movb $0x0, %al
callq 0x1030
movl -0x14(%rbp), %edi
callq 0x1130
callq 0x10c0
movl $0x0, -0x4(%rbp)
jmp 0x15d1
movl $0x0, -0xe0(%rbp)
movl $0x0, -0xe0(%rbp)
xorl %eax, %eax
cmpl $0x64, -0xe0(%rbp)
movb %al, -0xe1(%rbp)
jge 0x14f4
cmpl $0x0, -0xe0(%rbp)
setge %al
movb %al, -0xe1(%rbp)
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0x1500
jmp 0x1531
movl -0xe0(%rbp), %esi
leaq 0xb55(%rip), %rdi       # 0x2062
movb $0x0, %al
callq 0x1030
movl $0x1388, %edi           # imm = 0x1388
callq 0x10f0
movl -0xdc(%rbp), %edi
callq 0x10b0
movl %eax, -0xe0(%rbp)
jmp 0x14d3
movl -0xdc(%rbp), %edi
callq 0x10d0
cmpl $0x0, %eax
jne 0x156c
callq 0x10e0
movl %eax, %esi
leaq 0xb2c(%rip), %rdi       # 0x207b
movb $0x0, %al
callq 0x1030
movl -0x14(%rbp), %edi
callq 0x1130
callq 0x10c0
movl $0x0, -0x4(%rbp)
jmp 0x15d1
cmpl $0x0, -0xe0(%rbp)
jl 0x157e
cmpl $0x64, -0xe0(%rbp)
jle 0x15a9
callq 0x10e0
movl %eax, %esi
leaq 0xb0d(%rip), %rdi       # 0x2099
movb $0x0, %al
callq 0x1030
movl -0x14(%rbp), %edi
callq 0x1130
callq 0x10c0
movl $0x0, -0x4(%rbp)
jmp 0x15d1
movl -0xe0(%rbp), %esi
leaq 0xaac(%rip), %rdi       # 0x2062
movb $0x0, %al
callq 0x1030
movl -0x14(%rbp), %edi
callq 0x1130
callq 0x10c0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq