// File: /workspace/github_c_makefile_star2_O0/bloomsource[P]dns_update/dns_update.c
// Function: main
int main( int argc, char* argv[] )
{
    int rc;
    char json[1024];
    char buf[1024];
    char ip[16];
    int port;
    int json_len;
    struct pollfd pfd;
    char* p;
    cJSON *json_root, *json_retcode;
    
    if( argc < 4 )
    {
        usage();
        return 1;
    }
    
    
    strcpy( log_file, "dns_update.log" );
    
    snprintf( server, sizeof(server), "%s", argv[1] );
    p = strchr( server, ':' );
    if( !p )
    {
        usage();
        return 1;
    }
    if( strlen( p+1 ) == 0 )
    {
        usage();
        return 1;
    }
    
    p[0] = 0;
    
    cmd_port = atoi( p+1 );
    snprintf( auth_key, sizeof(auth_key), "%s", argv[2] );
    
    
    fd = udp_create();
    if( fd == -1 )
    {
        printf( "create udp socket failed! err:%s\n", ERR );
        write_log( "[ERR] create udp socket failed! err:%s", ERR );
        return 1;
    }
    
    if( resolve_host_ip( server, ip ) )
    {
        printf( "resolve server ip failed!\n" );
        write_log( "[ERR] resolve server ip failed!" );
        return 1;
    }
    
    if( argc > 4 )
    {
        sprintf( buf, ", \"ip\":\"%s\" ", argv[4] );
    }
    
    sprintf( json, "{ \"cmd\":\"update_domain\", \"domain\":\"%s\" %s }", argv[3], argc > 4 ? buf : " " );
    
    json_len = strlen( json );
    pack_update_pkg( auth_key, buf, json, json_len );
    
    rc = udp_send( fd, ip, cmd_port, buf, json_len + sizeof(upd_pack_hdr) );
    if( rc != json_len + sizeof(upd_pack_hdr) )
    {
        printf( "send udp pack failed! err:%s\n", ERR );
        write_log( "[ERR] send udp pack failed! err:%s", ERR );
        return 1;
    }
    
    pfd.fd = fd;
    pfd.events = POLLIN;
    
    rc = poll( &pfd, 1, 1000 );
    if( rc <= 0 )
    {
        printf( "recv udp response timeout!\n" );
        write_log( "[ERR] recv udp response timeout." );
        return 1;
    }
    
    rc = udp_recv( fd, buf, sizeof(buf), ip, &port );
    if( rc <= 0 )
    {
        printf( "recv udp response failed! err:%s\n", ERR );
        write_log( "[ERR] recv udp response failed! err:%s", ERR );
        return 1;
    }
    buf[rc] = 0;
    
    if( unpack_update_pkg( auth_key, TIME_DIFF, buf, rc ) )
    {
        printf( "recv invalid response!\n" );
        write_log( "[ERR] recv invalid response!" );
        return 1;
    }
    
        
    json_root = cJSON_Parse( buf + sizeof(upd_pack_hdr) );
    if( !json_root )
    {
        printf( "parse response json failed!\n" );
        write_log( "[ERR] parse response json failed! resp:[%s]", buf );
        return 1;
    }
    
    json_retcode = cJSON_GetObjectItem( json_root, "retcode" );
    if( !json_retcode )
    {
        printf( "invlaid json response.\n" );
        write_log( "[ERR] invalid json response, resp:[%s]", buf );
        return 1;
    }
    
    if( json_retcode->valueint )
    {
        printf( "update domain failed, retcode:%d\n", (int)json_retcode->valueint );
        write_log( "[ERR] update domain fialed, resp:[%s]", buf );
        return 1;
    }
    
    printf( "update domain %s ok!\n", argv[3] );
    write_log( "update domain %s ok!", argv[3] );
    close( fd );
    cJSON_Delete( json_root );
    
    
    
    
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x870, %rsp            # imm = 0x870
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x4, -0x8(%rbp)
jge 0x2440
callq 0x23f0
movl $0x1, -0x4(%rbp)
jmp 0x2952
leaq 0x12199(%rip), %rdi     # 0x145e0
leaq 0xabe9(%rip), %rsi      # 0xd037
callq 0x2060
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
leaq 0x121ee(%rip), %rdi     # 0x14650
movl $0x64, %esi
leaq 0xad59(%rip), %rdx      # 0xd1c7
movb $0x0, %al
callq 0x2120
leaq 0x121d4(%rip), %rdi     # 0x14650
movl $0x3a, %esi
callq 0x2100
movq %rax, -0x848(%rbp)
cmpq $0x0, -0x848(%rbp)
jne 0x24a8
callq 0x23f0
movl $0x1, -0x4(%rbp)
jmp 0x2952
movq -0x848(%rbp), %rdi
addq $0x1, %rdi
callq 0x20e0
cmpq $0x0, %rax
jne 0x24cf
callq 0x23f0
movl $0x1, -0x4(%rbp)
jmp 0x2952
movq -0x848(%rbp), %rax
movb $0x0, (%rax)
movq -0x848(%rbp), %rdi
addq $0x1, %rdi
callq 0x2280
movl %eax, %ecx
leaq 0x121c2(%rip), %rax     # 0x146b4
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
leaq 0x121bd(%rip), %rdi     # 0x146c0
movl $0x64, %esi
leaq 0xacb8(%rip), %rdx      # 0xd1c7
movb $0x0, %al
callq 0x2120
movb $0x0, %al
callq 0x94c0
movl %eax, 0x12091(%rip)     # 0x145b4
cmpl $-0x1, 0x1208a(%rip)    # 0x145b4
jne 0x2572
callq 0x2040
movl (%rax), %edi
callq 0x22c0
movq %rax, %rsi
leaq 0xab04(%rip), %rdi      # 0xd046
movb $0x0, %al
callq 0x2110
callq 0x2040
movl (%rax), %edi
callq 0x22c0
movq %rax, %rsi
leaq 0xab09(%rip), %rdi      # 0xd068
movb $0x0, %al
callq 0x9780
movl $0x1, -0x4(%rbp)
jmp 0x2952
leaq -0x830(%rbp), %rsi
leaq 0x120d0(%rip), %rdi     # 0x14650
callq 0x96d0
cmpl $0x0, %eax
je 0x25b2
leaq 0xaafe(%rip), %rdi      # 0xd08f
movb $0x0, %al
callq 0x2110
leaq 0xab0b(%rip), %rdi      # 0xd0aa
movb $0x0, %al
callq 0x9780
movl $0x1, -0x4(%rbp)
jmp 0x2952
cmpl $0x4, -0x8(%rbp)
jle 0x25d5
leaq -0x820(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0xaafc(%rip), %rsi      # 0xd0ca
movb $0x0, %al
callq 0x2290
leaq -0x420(%rbp), %rax
movq %rax, -0x868(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x860(%rbp)
cmpl $0x4, -0x8(%rbp)
jle 0x2608
leaq -0x820(%rbp), %rax
movq %rax, -0x870(%rbp)
jmp 0x2618
leaq 0xaf7b(%rip), %rax      # 0xd58a
movq %rax, -0x870(%rbp)
jmp 0x2618
movq -0x860(%rbp), %rdx
movq -0x868(%rbp), %rdi
movq -0x870(%rbp), %rcx
leaq 0xaaa3(%rip), %rsi      # 0xd0d7
movb $0x0, %al
callq 0x2290
leaq -0x420(%rbp), %rdi
callq 0x20e0
movl %eax, -0x838(%rbp)
leaq -0x820(%rbp), %rsi
leaq -0x420(%rbp), %rdx
movl -0x838(%rbp), %ecx
leaq 0x12058(%rip), %rdi     # 0x146c0
callq 0x9f20
movl 0x11f41(%rip), %edi     # 0x145b4
leaq -0x830(%rbp), %rsi
leaq 0x12033(%rip), %rax     # 0x146b4
movl (%rax), %edx
leaq -0x820(%rbp), %rcx
movslq -0x838(%rbp), %rax
addq $0xc, %rax
movl %eax, %r8d
callq 0x95e0
movl %eax, -0x14(%rbp)
movslq -0x14(%rbp), %rax
movslq -0x838(%rbp), %rcx
addq $0xc, %rcx
cmpq %rcx, %rax
je 0x26fa
callq 0x2040
movl (%rax), %edi
callq 0x22c0
movq %rax, %rsi
leaq 0xaa39(%rip), %rdi      # 0xd103
movb $0x0, %al
callq 0x2110
callq 0x2040
movl (%rax), %edi
callq 0x22c0
movq %rax, %rsi
leaq 0xaa3a(%rip), %rdi      # 0xd121
movb $0x0, %al
callq 0x9780
movl $0x1, -0x4(%rbp)
jmp 0x2952
movl 0x11eb4(%rip), %eax     # 0x145b4
movl %eax, -0x840(%rbp)
movw $0x1, -0x83c(%rbp)
leaq -0x840(%rbp), %rdi
movl $0x1, %esi
movl $0x3e8, %edx            # imm = 0x3E8
callq 0x2230
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jg 0x2756
leaq 0xaa0f(%rip), %rdi      # 0xd144
movb $0x0, %al
callq 0x2110
leaq 0xaa1d(%rip), %rdi      # 0xd160
movb $0x0, %al
callq 0x9780
movl $0x1, -0x4(%rbp)
jmp 0x2952
movl 0x11e58(%rip), %edi     # 0x145b4
leaq -0x820(%rbp), %rsi
leaq -0x830(%rbp), %rcx
movl $0x400, %edx            # imm = 0x400
leaq -0x834(%rbp), %r8
callq 0x9640
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jg 0x27ca
callq 0x2040
movl (%rax), %edi
callq 0x22c0
movq %rax, %rsi
leaq 0xa9e7(%rip), %rdi      # 0xd181
movb $0x0, %al
callq 0x2110
callq 0x2040
movl (%rax), %edi
callq 0x22c0
movq %rax, %rsi
leaq 0xa9ec(%rip), %rdi      # 0xd1a3
movb $0x0, %al
callq 0x9780
movl $0x1, -0x4(%rbp)
jmp 0x2952
movslq -0x14(%rbp), %rax
movb $0x0, -0x820(%rbp,%rax)
leaq -0x820(%rbp), %rdx
movl -0x14(%rbp), %ecx
leaq 0x11ed9(%rip), %rdi     # 0x146c0
movl $0xa, %esi
callq 0xa120
cmpl $0x0, %eax
je 0x281e
leaq 0xa9cd(%rip), %rdi      # 0xd1ca
movb $0x0, %al
callq 0x2110
leaq 0xa9d7(%rip), %rdi      # 0xd1e2
movb $0x0, %al
callq 0x9780
movl $0x1, -0x4(%rbp)
jmp 0x2952
leaq -0x820(%rbp), %rdi
addq $0xc, %rdi
callq 0x5800
movq %rax, -0x850(%rbp)
cmpq $0x0, -0x850(%rbp)
jne 0x286e
leaq 0xa9b9(%rip), %rdi      # 0xd1ff
movb $0x0, %al
callq 0x2110
leaq -0x820(%rbp), %rsi
leaq 0xa9c1(%rip), %rdi      # 0xd21c
movb $0x0, %al
callq 0x9780
movl $0x1, -0x4(%rbp)
jmp 0x2952
movq -0x850(%rbp), %rdi
leaq 0xa9cc(%rip), %rsi      # 0xd248
callq 0x5f00
movq %rax, -0x858(%rbp)
cmpq $0x0, -0x858(%rbp)
jne 0x28c1
leaq 0xa9b7(%rip), %rdi      # 0xd250
movb $0x0, %al
callq 0x2110
leaq -0x820(%rbp), %rsi
leaq 0xa9ba(%rip), %rdi      # 0xd268
movb $0x0, %al
callq 0x9780
movl $0x1, -0x4(%rbp)
jmp 0x2952
movq -0x858(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x2908
movq -0x858(%rbp), %rax
movq 0x28(%rax), %rax
movl %eax, %esi
leaq 0xa9ac(%rip), %rdi      # 0xd28f
movb $0x0, %al
callq 0x2110
leaq -0x820(%rbp), %rsi
leaq 0xa9b9(%rip), %rdi      # 0xd2b1
movb $0x0, %al
callq 0x9780
movl $0x1, -0x4(%rbp)
jmp 0x2952
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
leaq 0xa9c0(%rip), %rdi      # 0xd2d7
movb $0x0, %al
callq 0x2110
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
leaq 0xa9c0(%rip), %rdi      # 0xd2ed
movb $0x0, %al
callq 0x9780
movl 0x11c7a(%rip), %edi     # 0x145b4
callq 0x2160
movq -0x850(%rbp), %rdi
callq 0x5160
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x870, %rsp            # imm = 0x870
popq %rbp
retq
nop