#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef char **MYSQL_ROW;
typedef int /*<<< orphan*/ MYSQL_RES;
typedef int /*<<< orphan*/ MYSQL;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char **mysql_fetch_row(int /*<<< orphan*/ *);
int /*<<< orphan*/ *mysql_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ *mysql_real_connect(int /*<<< orphan*/ *, char const *,
                                       char const *, char const *, char const *,
                                       unsigned int, char const *,
                                       int /*<<< orphan*/);
scalar_t__ mysql_real_query(int /*<<< orphan*/ *, char *, unsigned long);
int /*<<< orphan*/ *mysql_store_result(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
int main() {
  MYSQL *mysql = NULL;
  const char *host = "localhost";
  const char *user = "root";
  const char *passwd = "root1";
  const char *db = "fgap_config";
  unsigned int port = 3306;
  const char *unix_socket = "/var/run/mysqld/mysqld.sock";
  mysql = mysql_init(mysql);
  if (mysql == NULL) {
    perror("mysql_init error ");
    exit(EXIT_FAILURE);
  }
  mysql =
      mysql_real_connect(mysql, host, user, passwd, db, port, unix_socket, 0);
  if (!mysql) {
    perror("mysql_real_connect error");
    exit(EXIT_FAILURE);
  } else {
    printf("mysql_real_connect success\n");
  }
  char sql[] = "select * from anti_virus";
  if (mysql_real_query(mysql, sql, (unsigned long)strlen(sql))) {
  } else {
    MYSQL_RES *rs = mysql_store_result(mysql);
    MYSQL_ROW row = NULL;
    printf("%-2s %-18s %-5s\n", "ID", "NAME", "VALUE");
    while ((row = mysql_fetch_row(rs))) {
      printf("%-2s %-18s %-5s\n", row[0], row[1], row[2]);
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe4f(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe4e(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe48(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe43(%rip),%rax
mov    %rax,-0x30(%rbp)
movl   $0xcea,-0x34(%rbp)
lea    0xe3d(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <mysql_init@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    121a <main+0x8a>
lea    0xe36(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x34(%rbp),%r9d
mov    -0x40(%rbp),%rax
xor    %r10d,%r10d
mov    %rax,(%rsp)
movl   $0x0,0x8(%rsp)
call   1060 <mysql_real_connect@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1273 <main+0xe3>
lea    0xdef(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0xe28(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xe25(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xe22(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe20(%rip),%al
mov    %al,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    %rax,%rdx
call   1080 <mysql_real_query@plt>
cmp    $0x0,%rax
je     12e3 <main+0x153>
jmp    1361 <main+0x1d1>
mov    -0x10(%rbp),%rdi
call   10b0 <mysql_store_result@plt>
mov    %rax,-0x68(%rbp)
movq   $0x0,-0x70(%rbp)
lea    0xd85(%rip),%rdi
lea    0xd8f(%rip),%rsi
lea    0xd8b(%rip),%rdx
lea    0xd89(%rip),%rcx
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x68(%rbp),%rdi
call   1030 <mysql_fetch_row@plt>
mov    %rax,-0x70(%rbp)
cmp    $0x0,%rax
je     135c <main+0x1cc>
mov    -0x70(%rbp),%rax
mov    (%rax),%rsi
mov    -0x70(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x70(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    131b <main+0x18b>
jmp    1361 <main+0x1d1>
mov    0x2c70(%rip),%rax
mov    (%rax),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
xor    %edi,%edi
call   1080 <mysql_init@plt>
test   %rax,%rax
je     12b3 <main+0x113>
lea    0xe63(%rip),%rbx
lea    0xe3b(%rip),%rsi
lea    0xe3e(%rip),%rdx
lea    0xe3c(%rip),%rcx
lea    0xe3b(%rip),%r8
mov    %rax,%rdi
mov    $0xcea,%r9d
push   $0x0
push   %rbx
call   1070 <mysql_real_connect@plt>
add    $0x10,%rsp
test   %rax,%rax
je     12bc <main+0x11c>
mov    %rax,%rbx
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
movups 0xeab(%rip),%xmm0
movups %xmm0,0x9(%rsp)
movaps 0xe96(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1090 <mysql_real_query@plt>
test   %rax,%rax
jne    12a2 <main+0x102>
mov    %rbx,%rdi
call   10c0 <mysql_store_result@plt>
mov    %rax,%rbx
lea    0xe1a(%rip),%rdi
lea    0xe24(%rip),%rsi
lea    0xe20(%rip),%rdx
lea    0xe1e(%rip),%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <mysql_fetch_row@plt>
test   %rax,%rax
je     12a2 <main+0x102>
lea    0xdea(%rip),%r14
xchg   %ax,%ax
mov    (%rax),%rsi
mov    0x8(%rax),%rdx
mov    0x10(%rax),%rcx
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <mysql_fetch_row@plt>
test   %rax,%rax
jne    1280 <main+0xe0>
mov    0x2d2f(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd83(%rip),%rdi
jmp    12c3 <main+0x123>
lea    0xd8c(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"root\00"
@.str.2 = [6 x i8] c"root1\00"
@.str.3 = [12 x i8] c"fgap_config\00"
@.str.4 = [28 x i8] c"/var/run/mysqld/mysqld.sock\00"
@.str.5 = [18 x i8] c"mysql_init error \00"
@EXIT_FAILURE = global i32 0
@.str.6 = [25 x i8] c"mysql_real_connect error\00"
@.str.7 = [28 x i8] c"mysql_real_connect success\0A\00"
@__const.main.sql = [25 x i8] c"select * from anti_virus\00"
@.str.8 = [17 x i8] c"%-2s %-18s %-5s\0A\00"
@.str.9 = [3 x i8] c"ID\00"
@.str.10 = [5 x i8] c"NAME\00"
@.str.11 = [6 x i8] c"VALUE\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [25 x i8]
%10 = alloca i32*
%11 = alloca i8**
store i32 0, i32* %1
store i32* null, i32** %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8** %6
store i32 3306, i32* %7
store i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8** %8
%12 = load i32*, i32** %2
%13 = call i32* @mysql_init(i32* %12)
store i32* %13, i32** %2
%14 = load i32*, i32** %2
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %0
%21 = load i32*, i32** %2
%22 = load i8*, i8** %3
%23 = load i8*, i8** %4
%24 = load i8*, i8** %5
%25 = load i8*, i8** %6
%26 = load i32, i32* %7
%27 = load i8*, i8** %8
%28 = call i32* @mysql_real_connect(i32* %21, i8* %22, i8* %23, i8* %24, i8* %25, i32 %26, i8* %27, i32 0)
store i32* %28, i32** %2
%29 = load i32*, i32** %2
%30 = icmp ne i32* %29, null
br i1 %30, label %35, label %31
31: ; preds = %20
%32 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %20
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %37
37: ; preds = %35
%38 = bitcast [25 x i8]* %9 to i8*
%39 = load i32*, i32** %2
%40 = getelementptr inbounds [25 x i8], [25 x i8]* %9, i64 0, i64 0
%41 = getelementptr inbounds [25 x i8], [25 x i8]* %9, i64 0, i64 0
%42 = call i64 @strlen(i8* %41)
%43 = call i64 @mysql_real_query(i32* %39, i8* %40, i64 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %37
br label %66
46: ; preds = %37
%47 = load i32*, i32** %2
%48 = call i32* @mysql_store_result(i32* %47)
store i32* %48, i32** %10
store i8** null, i8*** %11
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
br label %50
50: ; preds = %54, %46
%51 = load i32*, i32** %10
%52 = call i8** @mysql_fetch_row(i32* %51)
store i8** %52, i8*** %11
%53 = icmp ne i8** %52, null
br i1 %53, label %54, label %65
54: ; preds = %50
%55 = load i8**, i8*** %11
%56 = getelementptr inbounds i8*, i8** %55, i64 0
%57 = load i8*, i8** %56
%58 = load i8**, i8*** %11
%59 = getelementptr inbounds i8*, i8** %58, i64 1
%60 = load i8*, i8** %59
%61 = load i8**, i8*** %11
%62 = getelementptr inbounds i8*, i8** %61, i64 2
%63 = load i8*, i8** %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* %57, i8* %60, i8* %63)
br label %50
65: ; preds = %50
br label %66
66: ; preds = %65, %45
%67 = load i32, i32* @EXIT_SUCCESS
ret i32 %67
}

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"root\00"
@.str.2 = [6 x i8] c"root1\00"
@.str.3 = [12 x i8] c"fgap_config\00"
@.str.4 = [28 x i8] c"/var/run/mysqld/mysqld.sock\00"
@.str.5 = [18 x i8] c"mysql_init error \00"
@EXIT_FAILURE = global i32 0
@.str.6 = [25 x i8] c"mysql_real_connect error\00"
@__const.main.sql = [25 x i8] c"select * from anti_virus\00"
@.str.8 = [17 x i8] c"%-2s %-18s %-5s\0A\00"
@.str.9 = [3 x i8] c"ID\00"
@.str.10 = [5 x i8] c"NAME\00"
@.str.11 = [6 x i8] c"VALUE\00"
@EXIT_SUCCESS = global i32 0
@str = [27 x i8] c"mysql_real_connect success\00"
define i32 @main() {
%1 = alloca [25 x i8]
%2 = tail call i32* @mysql_init(i32* null)
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %0
%9 = tail call i32* @mysql_real_connect(i32* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 3306, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 0)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %8
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%17 = getelementptr inbounds [25 x i8], [25 x i8]* %1, i64 0, i64 0
%18 = call i64 @strlen(i8* %17)
%19 = call i64 @mysql_real_query(i32* %9, i8* %17, i64 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %36
21: ; preds = %15
%22 = call i32* @mysql_store_result(i32* %9)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
%24 = call i8** @mysql_fetch_row(i32* %22)
%25 = icmp eq i8** %24, null
br i1 %25, label %36, label %26
26: ; preds = %21, %26
%27 = phi i8** [ %34, %26 ], [ %24, %21 ]
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8*, i8** %27, i64 1
%30 = load i8*, i8** %29
%31 = getelementptr inbounds i8*, i8** %27, i64 2
%32 = load i8*, i8** %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* %28, i8* %30, i8* %32)
%34 = call i8** @mysql_fetch_row(i32* %22)
%35 = icmp eq i8** %34, null
br i1 %35, label %36, label %26
36: ; preds = %26, %21, %15
%37 = load i32, i32* @EXIT_SUCCESS
ret i32 %37
}