// File: /workspace/github_c_makefile_star2_O0/sonicse[P]dbf2mysql/dbf2mysql.c
// Function: main
int main(int argc, char **argv) {
    int i;
    MYSQL *SQLsock, mysql;
    extern int optind;
    extern char *optarg;
    char *query;
    dbhead *dbh;
    char *charset;

    primary[0] = '\0';

    while ((i = getopt(argc, argv, "xqfFrne:lucvi:h:p:d:t:s:o:U:P:C:")) != EOF) {
        switch (i) {
            case 'P':
                pass = (char *) strdup(optarg);
                break;
            case 'U':
                user = (char *) strdup(optarg);
                break;
            case 'x':
                express = 1;
                break;
            case 'f':
                fieldlow = 1;
                break;
            case 'F':
                var_chars = 0;
                break;
            case 'r':
                trim = 1;
                break;
            case 'n':
                null_fields = 1;
                break;
            case 'v':
                verbose++;
                break;
            case 'c':
                create++;
                break;
            case 'l':
                lower = 1;
                break;
            case 'u':
                if (lower) {
                    usage();
                    printf("Can't use -u and -l at the same time!\n");
                    exit(1);
                }
                upper = 1;
                break;
            case 'e':
                convert = (char *) strdup(optarg);
                break;
            case 'h':
                host = (char *) strdup(optarg);
                break;
            case 'q':
                quick = 1;
                break;
            case 'p':
                strncpy(primary, optarg, 11);
                break;
            case 'd':
                dbase = (char *) strdup(optarg);
                break;
            case 't':
                table = (char *) strdup(optarg);
                break;
            case 'i':
                indexes = (char *) strdup(optarg);
                break;
            case 's':
                subarg = (char *) strdup(optarg);
                break;
            case 'o':
                flist = (char *) strdup(optarg);
                break;
            case 'C':
                charset = (char *) strdup(optarg);
                break;
            case ':':
                usage();
                printf("missing argument!\n");
                exit(1);
            case '?':
                usage();
                printf("unknown argument: %s\n", argv[0]);
                exit(1);
            default:
                break;
        }
    }

    argc -= optind;
    argv = &argv[optind];

    if (argc != 1) {
        usage();
        exit(1);
    }

    if (verbose > 2) {
        printf("Opening dbf-file %s\n", argv[0]);
    }

    if ((dbh = dbf_open(argv[0], O_RDONLY)) == (dbhead *) - 1) {
        fprintf(stderr, "Couldn't open xbase-file %s\n", argv[0]);
        exit(1);
    }

    if (verbose) {
        printf("dbf-file: %s - %s, MySQL-dbase: %s, MySQL-table: %s\n",
                argv[0],
                dbh->db_description,
                dbase,
                table);
        printf("Number of records: %ld\n", dbh->db_records);
    }
    if (verbose > 1) {
        printf("Name\t\t Length\tDisplay\t Type\n");
        printf("-------------------------------------\n");
        for (i = 0; i < dbh->db_nfields; i++) {
            printf("%-12s\t%7d\t%5d\t%3c\n",
                    dbh->db_fields[i].db_name,
                    dbh->db_fields[i].db_flen,
                    dbh->db_fields[i].db_dec,
                    dbh->db_fields[i].db_type);
        }
    }

    if (verbose > 2) {
        printf("Making connection to MySQL-server\n");
    }

    // Init mysql
    if (!(mysql_init(&mysql))) {
        fprintf(stderr, "Can't initialize. Insufficient memory.");
        dbf_close(&dbh);
        exit(1);
    }

    if (!(SQLsock = mysql_real_connect(&mysql, host, user, pass, NULL, 0, NULL, 0))) {
        fprintf(stderr, "Couldn't get a connection with the ");
        fprintf(stderr, "designated host!\n");
        fprintf(stderr, "Detailed report: %s\n", mysql_error(&mysql));
        dbf_close(&dbh);
        exit(1);
    }

    if (verbose > 2) {
        printf("Selecting database '%s'\n", dbase);
    }

    if ((mysql_select_db(SQLsock, dbase)) == -1) {
        fprintf(stderr, "Couldn't select database %s.\n", dbase);
        fprintf(stderr, "Detailed report: %s\n", mysql_error(SQLsock));
        mysql_close(SQLsock);
        dbf_close(&dbh);
        exit(1);
    }

    if (charset && !mysql_set_character_set(&mysql, charset)) {
        printf("New client character set: %s\n",
                mysql_character_set_name(&mysql));
    }

    /* Substitute field names */
    do_onlyfields(flist, dbh);
    do_substitute(subarg, dbh);

    if (!create) {
        if (!check_table(SQLsock, table)) {
            printf("Table does not exist!\n");
            exit(1);
        }
    } else {
        if (verbose > 2) {
            printf("Dropping original table (if one exists)\n");
        }

        if (!(query = (char *) malloc(12 + strlen(table)))) {
            printf("Memory-allocation error in main (drop)!\n");
            mysql_close(SQLsock);
            dbf_close(&dbh);
            exit(1);
        }

        sprintf(query, "DROP TABLE `%s`", table);
        mysql_query(SQLsock, query);
        free(query);

        /* Build a CREATE-clause
         */
        do_create(SQLsock, table, dbh, charset);
    }

    /* Build an INSERT-clause
     */
    if (create < 2)
        do_inserts(SQLsock, table, dbh);

    if (verbose > 2) {
        printf("Closing up....\n");
    }

    mysql_close(SQLsock);
    dbf_close(&dbh);
    exit(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4f0, %rsp            # imm = 0x4F0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, 0x7778(%rip)      # 0xb308
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x4c6d(%rip), %rdx      # 0x880b
callq 0x2080
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0x3e11
movl -0x14(%rbp), %eax
addl $-0x3a, %eax
movl %eax, %ecx
movq %rcx, -0x4c8(%rbp)
subl $0x3e, %eax
ja 0x3e0a
movq -0x4c8(%rbp), %rax
leaq 0x448f(%rip), %rcx      # 0x8064
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x73e3(%rip), %rax      # 0xafc8
movq (%rax), %rdi
callq 0x2350
movq %rax, 0x76e4(%rip)      # 0xb2d8
jmp 0x3e0c
movq 0x73c8(%rip), %rax      # 0xafc8
movq (%rax), %rdi
callq 0x2350
movq %rax, 0x76d1(%rip)      # 0xb2e0
jmp 0x3e0c
movl $0x1, 0x769e(%rip)      # 0xb2bc
jmp 0x3e0c
movl $0x1, 0x768b(%rip)      # 0xb2b8
jmp 0x3e0c
movl $0x0, 0x75a4(%rip)      # 0xb1e0
jmp 0x3e0c
movl $0x1, 0x7679(%rip)      # 0xb2c4
jmp 0x3e0c
movl $0x1, 0x7666(%rip)      # 0xb2c0
jmp 0x3e0c
movl 0x7643(%rip), %eax      # 0xb2a8
addl $0x1, %eax
movl %eax, 0x763a(%rip)      # 0xb2a8
jmp 0x3e0c
movl 0x763b(%rip), %eax      # 0xb2b4
addl $0x1, %eax
movl %eax, 0x7632(%rip)      # 0xb2b4
jmp 0x3e0c
movl $0x1, 0x761f(%rip)      # 0xb2b0
jmp 0x3e0c
cmpl $0x0, 0x7613(%rip)      # 0xb2b0
je 0x3cbc
callq 0x2520
leaq 0x4b81(%rip), %rdi      # 0x882c
movb $0x0, %al
callq 0x2050
movl $0x1, %edi
callq 0x2230
movl $0x1, 0x75e6(%rip)      # 0xb2ac
jmp 0x3e0c
movq 0x72f6(%rip), %rax      # 0xafc8
movq (%rax), %rdi
callq 0x2350
movq %rax, 0x761f(%rip)      # 0xb300
jmp 0x3e0c
movq 0x72db(%rip), %rax      # 0xafc8
movq (%rax), %rdi
callq 0x2350
movq %rax, 0x75d4(%rip)      # 0xb2d0
jmp 0x3e0c
movl $0x1, 0x75bd(%rip)      # 0xb2c8
jmp 0x3e0c
movq 0x72b1(%rip), %rax      # 0xafc8
movq (%rax), %rsi
leaq 0x75e7(%rip), %rdi      # 0xb308
movl $0xb, %edx
callq 0x2100
jmp 0x3e0c
movq 0x7291(%rip), %rax      # 0xafc8
movq (%rax), %rdi
callq 0x2350
movq %rax, 0x74a2(%rip)      # 0xb1e8
jmp 0x3e0c
movq 0x7276(%rip), %rax      # 0xafc8
movq (%rax), %rdi
callq 0x2350
movq %rax, 0x748f(%rip)      # 0xb1f0
jmp 0x3e0c
movq 0x725b(%rip), %rax      # 0xafc8
movq (%rax), %rdi
callq 0x2350
movq %rax, 0x757c(%rip)      # 0xb2f8
jmp 0x3e0c
movq 0x7240(%rip), %rax      # 0xafc8
movq (%rax), %rdi
callq 0x2350
movq %rax, 0x7551(%rip)      # 0xb2e8
jmp 0x3e0c
movq 0x7228(%rip), %rax      # 0xafc8
movq (%rax), %rdi
callq 0x2350
movq %rax, 0x7541(%rip)      # 0xb2f0
jmp 0x3e0c
movq 0x7210(%rip), %rax      # 0xafc8
movq (%rax), %rdi
callq 0x2350
movq %rax, -0x4c0(%rbp)
jmp 0x3e0c
callq 0x2520
leaq 0x4a7e(%rip), %rdi      # 0x8853
movb $0x0, %al
callq 0x2050
movl $0x1, %edi
callq 0x2230
callq 0x2520
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x4a6d(%rip), %rdi      # 0x8866
movb $0x0, %al
callq 0x2050
movl $0x1, %edi
callq 0x2230
jmp 0x3e0c
jmp 0x3b90
movq 0x71c8(%rip), %rax      # 0xafe0
movl (%rax), %ecx
movl -0x8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
movq 0x71b3(%rip), %rcx      # 0xafe0
movslq (%rcx), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
cmpl $0x1, -0x8(%rbp)
je 0x3e50
callq 0x2520
movl $0x1, %edi
callq 0x2230
cmpl $0x2, 0x7451(%rip)      # 0xb2a8
jle 0x3e6e
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x4a15(%rip), %rdi      # 0x887c
movb $0x0, %al
callq 0x2050
movq -0x10(%rbp), %rax
movq (%rax), %rdi
xorl %esi, %esi
callq 0x43c0
movq %rax, -0x4b8(%rbp)
movq $-0x1, %rcx
cmpq %rcx, %rax
jne 0x3eb8
movq 0x7142(%rip), %rax      # 0xafd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x49ea(%rip), %rsi      # 0x8891
movb $0x0, %al
callq 0x2290
movl $0x1, %edi
callq 0x2230
cmpl $0x0, 0x73e9(%rip)      # 0xb2a8
je 0x3f08
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x4b8(%rbp), %rax
movq 0x48(%rax), %rdx
movq 0x730e(%rip), %rcx      # 0xb1e8
movq 0x730f(%rip), %r8       # 0xb1f0
leaq 0x49c6(%rip), %rdi      # 0x88ae
movb $0x0, %al
callq 0x2050
movq -0x4b8(%rbp), %rax
movq 0x20(%rax), %rsi
leaq 0x49e2(%rip), %rdi      # 0x88e3
movb $0x0, %al
callq 0x2050
cmpl $0x1, 0x7399(%rip)      # 0xb2a8
jle 0x3fd1
leaq 0x49df(%rip), %rdi      # 0x88fb
movb $0x0, %al
callq 0x2050
leaq 0x49ee(%rip), %rdi      # 0x8918
movb $0x0, %al
callq 0x2050
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x4b8(%rbp), %rcx
movzbl 0x32(%rcx), %ecx
cmpl %ecx, %eax
jge 0x3fcf
movq -0x4b8(%rbp), %rax
movq 0x40(%rax), %rsi
movslq -0x14(%rbp), %rax
imulq $0xf, %rax, %rax
addq %rax, %rsi
movq -0x4b8(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x14(%rbp), %rcx
imulq $0xf, %rcx, %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %edx
movq -0x4b8(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x14(%rbp), %rcx
imulq $0xf, %rcx, %rcx
addq %rcx, %rax
movzbl 0xd(%rax), %ecx
movq -0x4b8(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x14(%rbp), %rdi
imulq $0xf, %rdi, %rdi
addq %rdi, %rax
movzbl 0xb(%rax), %r8d
leaq 0x4985(%rip), %rdi      # 0x893f
movb $0x0, %al
callq 0x2050
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x3f38
jmp 0x3fd1
cmpl $0x2, 0x72d0(%rip)      # 0xb2a8
jle 0x3fe8
leaq 0x4971(%rip), %rdi      # 0x8952
movb $0x0, %al
callq 0x2050
leaq -0x4a8(%rbp), %rdi
callq 0x20d0
cmpq $0x0, %rax
jne 0x4028
movq 0x6fd7(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x496a(%rip), %rsi      # 0x8975
movb $0x0, %al
callq 0x2290
leaq -0x4b8(%rbp), %rdi
callq 0x5030
movl $0x1, %edi
callq 0x2230
movq 0x72a1(%rip), %rsi      # 0xb2d0
movq 0x72aa(%rip), %rdx      # 0xb2e0
movq 0x729b(%rip), %rcx      # 0xb2d8
leaq -0x4a8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %r8d
xorl %r9d, %r9d
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x20f0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x40e7
movq 0x6f65(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x491f(%rip), %rsi      # 0x899c
movb $0x0, %al
callq 0x2290
movq 0x6f4d(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x492b(%rip), %rsi      # 0x89c0
movb $0x0, %al
callq 0x2290
movq 0x6f35(%rip), %rax      # 0xafd8
movq (%rax), %rax
movq %rax, -0x4d0(%rbp)
leaq -0x4a8(%rbp), %rdi
callq 0x20b0
movq -0x4d0(%rbp), %rdi
movq %rax, %rdx
leaq 0x44b0(%rip), %rsi      # 0x857a
movb $0x0, %al
callq 0x2290
leaq -0x4b8(%rbp), %rdi
callq 0x5030
movl $0x1, %edi
callq 0x2230
cmpl $0x2, 0x71ba(%rip)      # 0xb2a8
jle 0x4105
movq 0x70f1(%rip), %rsi      # 0xb1e8
leaq 0x48d4(%rip), %rdi      # 0x89d2
movb $0x0, %al
callq 0x2050
movq -0x20(%rbp), %rdi
movq 0x70d8(%rip), %rsi      # 0xb1e8
callq 0x2170
cmpl $-0x1, %eax
jne 0x418a
movq 0x6eb7(%rip), %rax      # 0xafd8
movq (%rax), %rdi
movq 0x70bd(%rip), %rdx      # 0xb1e8
leaq 0x48b9(%rip), %rsi      # 0x89eb
movb $0x0, %al
callq 0x2290
movq 0x6e98(%rip), %rax      # 0xafd8
movq (%rax), %rax
movq %rax, -0x4d8(%rbp)
movq -0x20(%rbp), %rdi
callq 0x20b0
movq -0x4d8(%rbp), %rdi
movq %rax, %rdx
leaq 0x4416(%rip), %rsi      # 0x857a
movb $0x0, %al
callq 0x2290
movq -0x20(%rbp), %rdi
callq 0x2270
leaq -0x4b8(%rbp), %rdi
callq 0x5030
movl $0x1, %edi
callq 0x2230
cmpq $0x0, -0x4c0(%rbp)
je 0x41c9
movq -0x4c0(%rbp), %rsi
leaq -0x4a8(%rbp), %rdi
callq 0x2250
cmpl $0x0, %eax
jne 0x41c9
leaq -0x4a8(%rbp), %rdi
callq 0x22c0
movq %rax, %rsi
leaq 0x4847(%rip), %rdi      # 0x8a09
movb $0x0, %al
callq 0x2050
movq 0x7120(%rip), %rdi      # 0xb2f0
movq -0x4b8(%rbp), %rsi
callq 0x2590
movq 0x7105(%rip), %rdi      # 0xb2e8
movq -0x4b8(%rbp), %rsi
callq 0x2720
cmpl $0x0, 0x70be(%rip)      # 0xb2b4
jne 0x422a
movq -0x20(%rbp), %rdi
movq 0x6fed(%rip), %rsi      # 0xb1f0
callq 0x2490
cmpl $0x0, %eax
jne 0x4225
leaq 0x4813(%rip), %rdi      # 0x8a27
movb $0x0, %al
callq 0x2050
movl $0x1, %edi
callq 0x2230
jmp 0x42e9
cmpl $0x2, 0x7077(%rip)      # 0xb2a8
jle 0x4241
leaq 0x4804(%rip), %rdi      # 0x8a3e
movb $0x0, %al
callq 0x2050
movq 0x6fa8(%rip), %rdi      # 0xb1f0
callq 0x20c0
movq %rax, %rdi
addq $0xc, %rdi
callq 0x2260
movq %rax, -0x4b0(%rbp)
cmpq $0x0, %rax
jne 0x4293
leaq 0x47fa(%rip), %rdi      # 0x8a67
movb $0x0, %al
callq 0x2050
movq -0x20(%rbp), %rdi
callq 0x2270
leaq -0x4b8(%rbp), %rdi
callq 0x5030
movl $0x1, %edi
callq 0x2230
movq -0x4b0(%rbp), %rdi
movq 0x6f4f(%rip), %rdx      # 0xb1f0
leaq 0x47e8(%rip), %rsi      # 0x8a90
movb $0x0, %al
callq 0x2060
movq -0x20(%rbp), %rdi
movq -0x4b0(%rbp), %rsi
callq 0x2120
movq -0x4b0(%rbp), %rdi
callq 0x2210
movq -0x20(%rbp), %rdi
movq 0x6f1a(%rip), %rsi      # 0xb1f0
movq -0x4b8(%rbp), %rdx
movq -0x4c0(%rbp), %rcx
callq 0x28f0
cmpl $0x2, 0x6fc4(%rip)      # 0xb2b4
jge 0x4309
movq -0x20(%rbp), %rdi
movq 0x6ef3(%rip), %rsi      # 0xb1f0
movq -0x4b8(%rbp), %rdx
callq 0x2e90
cmpl $0x2, 0x6f98(%rip)      # 0xb2a8
jle 0x4320
leaq 0x4787(%rip), %rdi      # 0x8aa0
movb $0x0, %al
callq 0x2050
movq -0x20(%rbp), %rdi
callq 0x2270
leaq -0x4b8(%rbp), %rdi
callq 0x5030
xorl %edi, %edi
callq 0x2230
nopl (%rax)