// File: /workspace/github_c_makefile_star2_O0/sonicse[P]dbf2mysql/dbf2mysql.c
// Function: do_create
void do_create(MYSQL *SQLsock, char *table, dbhead *dbh, char *charset) {
    /* Patched by GLC to support date and boolean fields */
    /* Patched by WKV to support Visual FoxPro fields */
    char *query, *s;
    char t[20];
    int i, first_done;

    if (verbose > 2) {
        printf("Building CREATE-clause\n");
    }

    if (!(query = (char *) malloc((express * 100) +
            (dbh->db_nfields * 60) + 29 + strlen(table)))) {
        fprintf(stderr, "Memory allocation error in function do_create\n");
        mysql_close(SQLsock);
        dbf_close(&dbh);
        exit(1);
    }

    sprintf(query, "CREATE TABLE `%s` (", table);
    if (express) {
        strcat(query,
                "_rec int(10) unsigned DEFAULT '0' NOT NULL auto_increment PRIMARY KEY,\n");
        strcat(query, "_timestamp timestamp(14),\n");
    }
    first_done = 0;
    for (i = 0; i < dbh->db_nfields; i++) {
        if (!strlen(dbh->db_fields[i].db_name)) {
            continue;
            /* skip field if length of name == 0 */
        }
        if (first_done) {
            strcat(query, ",\n\t");
        }
        first_done = 1;
        if (fieldlow)
            strtolower(dbh->db_fields[i].db_name);

        strcat(query, "`\0");
        strcat(query, dbh->db_fields[i].db_name);
        strcat(query, "`\0");
        switch (dbh->db_fields[i].db_type) {
            case 'C':
                if (var_chars)
                    strcat(query, " varchar");
                else
                    strcat(query, " char");
                sprintf(t, "(%d)", dbh->db_fields[i].db_flen);
                strcat(query, t);
                break;

            case 'N':
                if (dbh->db_fields[i].db_dec != 0) {
                    strcat(query, " real"); /* decimal the better choice? */
                } else {
                    strcat(query, " int");
                }
                break;

            case 'L':
                /* strcat(query, " char (1)"); */
                strcat(query, " enum('F','T')");
                break;

            case 'D':
                strcat(query, " date");
                break;

            case 'M':
                strcat(query, " text");
                break;

            case 'F':
                strcat(query, " double");
                break;

            case 'B': /* ?Depends on DB vs FoxPro? Former is memo, latter is Binary */
                sprintf(t, " decimal(15,%d)", dbh->db_fields[i].db_dec);
                strcat(query, t);
                break;

            case 'G':
                strcat(query, " blob");
                break;

            case 'P':
                strcat(query, " blob");
                break;

            case 'Y':
                strcat(query, " decimal(21,4)");
                break;

            case 'T':
                strcat(query, " datetime");
                break;

            case 'I':
                strcat(query, " int");
                break;

        }
        if (strcmp(dbh->db_fields[i].db_name, primary) == 0) {
            strcat(query, " not null primary key");
        } else if (!null_fields)
            strcat(query, " not null");
    }

    if (indexes) /* add INDEX statements */ {
        for (s = strtok(indexes, ","); s != NULL; s = strtok(NULL, ",")) {
            strcat(query, ",INDEX(");
            strcat(query, s);
            strcat(query, ")");
        }
    }

    strcat(query, ")\n");

    if (charset) {
        strcat(query, " DEFAULT CHARSET=");
        strcat(query, charset);
        strcat(query, "\n");
    }

    if (verbose > 2) {
        printf("Sending create-clause\n");
        printf("%s\n", query);
        printf("fields in dbh %d, allocated mem for query %zu, query size %zu\n",
                dbh->db_nfields, (dbh->db_nfields * 60) + 29 + strlen(table), strlen(query));
    }

    if (mysql_query(SQLsock, query) != 0) {
        fprintf(stderr, "Error creating table!\n");
        fprintf(stderr, "Detailed report: %s\n", mysql_error(SQLsock));
        dbf_close(&dbh);
        free(query);
        mysql_close(SQLsock);
        exit(1);
    }

    free(query);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
cmpl $0x2, 0x8996(%rip)      # 0xb2a8
jle 0x2922
leaq 0x5a8a(%rip), %rdi      # 0x83a5
movb $0x0, %al
callq 0x2050
imull $0x64, 0x8993(%rip), %eax # 0xb2bc
movq -0x18(%rbp), %rcx
movzbl 0x32(%rcx), %ecx
imull $0x3c, %ecx, %ecx
addl %ecx, %eax
addl $0x1d, %eax
cltq
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20c0
movq -0x60(%rbp), %rdi
addq %rax, %rdi
callq 0x2260
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x2992
movq 0x8673(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x5a4e(%rip), %rsi      # 0x83bd
movb $0x0, %al
callq 0x2290
movq -0x8(%rbp), %rdi
callq 0x2270
leaq -0x18(%rbp), %rdi
callq 0x5030
movl $0x1, %edi
callq 0x2230
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x5a4b(%rip), %rsi      # 0x83ec
movb $0x0, %al
callq 0x2060
cmpl $0x0, 0x890d(%rip)      # 0xb2bc
je 0x29d1
movq -0x28(%rbp), %rdi
leaq 0x5a44(%rip), %rsi      # 0x8400
callq 0x2340
movq -0x28(%rbp), %rdi
leaq 0x5a7c(%rip), %rsi      # 0x8448
callq 0x2340
movl $0x0, -0x58(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq -0x18(%rbp), %rcx
movzbl 0x32(%rcx), %ecx
cmpl %ecx, %eax
jge 0x2cc1
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
movslq -0x54(%rbp), %rax
imulq $0xf, %rax, %rax
addq %rax, %rdi
callq 0x20c0
cmpq $0x0, %rax
jne 0x2a15
jmp 0x2cb3
cmpl $0x0, -0x58(%rbp)
je 0x2a2b
movq -0x28(%rbp), %rdi
leaq 0x5a3d(%rip), %rsi      # 0x8463
callq 0x2340
movl $0x1, -0x58(%rbp)
cmpl $0x0, 0x887f(%rip)      # 0xb2b8
je 0x2a53
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
movslq -0x54(%rbp), %rax
imulq $0xf, %rax, %rax
addq %rax, %rdi
callq 0x7140
movq -0x28(%rbp), %rdi
leaq 0x5702(%rip), %rsi      # 0x8160
movq %rsi, -0x70(%rbp)
callq 0x2340
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rsi
movslq -0x54(%rbp), %rax
leaq (%rax,%rax,4), %rax
leaq (%rax,%rax,2), %rax
addq %rax, %rsi
callq 0x2340
movq -0x70(%rbp), %rsi
movq -0x28(%rbp), %rdi
callq 0x2340
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x54(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
leaq (%rcx,%rcx,2), %rcx
movzbl 0xb(%rax,%rcx), %eax
addl $-0x42, %eax
movl %eax, %ecx
movq %rcx, -0x68(%rbp)
subl $0x17, %eax
ja 0x2c60
movq -0x68(%rbp), %rax
leaq 0x553a(%rip), %rcx      # 0x8004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, 0x8706(%rip)      # 0xb1e0
je 0x2aee
movq -0x28(%rbp), %rdi
leaq 0x5980(%rip), %rsi      # 0x8467
callq 0x2340
jmp 0x2afe
movq -0x28(%rbp), %rdi
leaq 0x5977(%rip), %rsi      # 0x8470
callq 0x2340
leaq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x54(%rbp), %rcx
imulq $0xf, %rcx, %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %edx
leaq 0x60bc(%rip), %rsi      # 0x8bdc
movb $0x0, %al
callq 0x2060
movq -0x28(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2340
jmp 0x2c60
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x54(%rbp), %rcx
imulq $0xf, %rcx, %rcx
addq %rcx, %rax
movzbl 0xd(%rax), %eax
cmpl $0x0, %eax
je 0x2b67
movq -0x28(%rbp), %rdi
leaq 0x5916(%rip), %rsi      # 0x8476
callq 0x2340
jmp 0x2b77
movq -0x28(%rbp), %rdi
leaq 0x590a(%rip), %rsi      # 0x847c
callq 0x2340
jmp 0x2c60
movq -0x28(%rbp), %rdi
leaq 0x58fa(%rip), %rsi      # 0x8481
callq 0x2340
jmp 0x2c60
movq -0x28(%rbp), %rdi
leaq 0x58f4(%rip), %rsi      # 0x8490
callq 0x2340
jmp 0x2c60
movq -0x28(%rbp), %rdi
leaq 0x58e5(%rip), %rsi      # 0x8496
callq 0x2340
jmp 0x2c60
movq -0x28(%rbp), %rdi
leaq 0x58d6(%rip), %rsi      # 0x849c
callq 0x2340
jmp 0x2c60
leaq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x54(%rbp), %rcx
imulq $0xf, %rcx, %rcx
addq %rcx, %rax
movzbl 0xd(%rax), %edx
leaq 0x58b2(%rip), %rsi      # 0x84a4
movb $0x0, %al
callq 0x2060
movq -0x28(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2340
jmp 0x2c60
movq -0x28(%rbp), %rdi
leaq 0x58a1(%rip), %rsi      # 0x84b4
callq 0x2340
jmp 0x2c60
movq -0x28(%rbp), %rdi
leaq 0x588f(%rip), %rsi      # 0x84b4
callq 0x2340
jmp 0x2c60
movq -0x28(%rbp), %rdi
leaq 0x5883(%rip), %rsi      # 0x84ba
callq 0x2340
jmp 0x2c60
movq -0x28(%rbp), %rdi
leaq 0x5880(%rip), %rsi      # 0x84c9
callq 0x2340
jmp 0x2c60
movq -0x28(%rbp), %rdi
leaq 0x5821(%rip), %rsi      # 0x847c
callq 0x2340
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
movslq -0x54(%rbp), %rax
imulq $0xf, %rax, %rax
addq %rax, %rdi
leaq 0x868e(%rip), %rsi      # 0xb308
callq 0x2280
cmpl $0x0, %eax
jne 0x2c96
movq -0x28(%rbp), %rdi
leaq 0x5844(%rip), %rsi      # 0x84d3
callq 0x2340
jmp 0x2cb1
cmpl $0x0, 0x8623(%rip)      # 0xb2c0
jne 0x2caf
movq -0x28(%rbp), %rdi
leaq 0x583f(%rip), %rsi      # 0x84e9
callq 0x2340
jmp 0x2cb1
jmp 0x2cb3
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x29df
cmpq $0x0, 0x862f(%rip)      # 0xb2f8
je 0x2d2e
movq 0x8626(%rip), %rdi      # 0xb2f8
leaq 0x59a4(%rip), %rsi      # 0x867d
callq 0x22e0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x2d2c
movq -0x28(%rbp), %rdi
leaq 0x57ff(%rip), %rsi      # 0x84f3
callq 0x2340
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x2340
movq -0x28(%rbp), %rdi
leaq 0x577d(%rip), %rsi      # 0x848e
callq 0x2340
xorl %eax, %eax
movl %eax, %edi
leaq 0x595c(%rip), %rsi      # 0x867d
callq 0x22e0
movq %rax, -0x30(%rbp)
jmp 0x2ce2
jmp 0x2d2e
movq -0x28(%rbp), %rdi
leaq 0x5d2b(%rip), %rsi      # 0x8a64
callq 0x2340
cmpq $0x0, -0x20(%rbp)
je 0x2d72
movq -0x28(%rbp), %rdi
leaq 0x57ab(%rip), %rsi      # 0x84fb
callq 0x2340
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x2340
movq -0x28(%rbp), %rdi
leaq 0x54e6(%rip), %rsi      # 0x8253
callq 0x2340
cmpl $0x2, 0x852f(%rip)      # 0xb2a8
jle 0x2df8
leaq 0x578b(%rip), %rdi      # 0x850d
movb $0x0, %al
callq 0x2050
movq -0x28(%rbp), %rsi
leaq 0x598a(%rip), %rdi      # 0x871e
movb $0x0, %al
callq 0x2050
movq -0x18(%rbp), %rax
movzbl 0x32(%rax), %eax
movl %eax, -0x7c(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x32(%rax), %eax
imull $0x3c, %eax, %eax
addl $0x1d, %eax
cltq
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20c0
movq %rax, %rcx
movq -0x88(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x28(%rbp), %rdi
callq 0x20c0
movl -0x7c(%rbp), %esi
movq -0x78(%rbp), %rdx
movq %rax, %rcx
leaq 0x5733(%rip), %rdi      # 0x8524
movb $0x0, %al
callq 0x2050
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x2120
cmpl $0x0, %eax
je 0x2e79
movq 0x81c7(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x5748(%rip), %rsi      # 0x8563
movb $0x0, %al
callq 0x2290
movq 0x81af(%rip), %rax      # 0xafd8
movq (%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
callq 0x20b0
movq -0x90(%rbp), %rdi
movq %rax, %rdx
leaq 0x572d(%rip), %rsi      # 0x857a
movb $0x0, %al
callq 0x2290
leaq -0x18(%rbp), %rdi
callq 0x5030
movq -0x28(%rbp), %rdi
callq 0x2210
movq -0x8(%rbp), %rdi
callq 0x2270
movl $0x1, %edi
callq 0x2230
movq -0x28(%rbp), %rdi
callq 0x2210
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)