#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 int /*<<< orphan*/ MYSQL;

/* Variables and functions */
int /*<<< orphan*/ mysql_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_init(int /*<<< orphan*/ *);
int mysql_query(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *mysql_real_connect(int /*<<< orphan*/ *, char *, char *,
                                       char *, char *, int,
                                       int /*<<< orphan*/ *,
                                       int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main() {
  MYSQL db;
  MYSQL *pdb;
  int ret;
  mysql_init(&db);
  pdb = mysql_real_connect(&db, "127.0.0.1", "root", "123", "class306", 3306,
                           NULL, 0);
  if (pdb == NULL) {
    printf("connect fail\n");
  } else {
    printf("connect ok\n");
  }
  char *buff = "set names utf8;";
  ret = mysql_query(&db, buff);
  char *sql =
      "insert into "
      "students(id,name,sex,age,tel)values(NULL,'李四','男',20,'12345678901');";
  ret = mysql_query(&db, sql);
  if (ret == 0) {
    printf("insert ok\n");
  } else {
    perror("insert fail\n");
    return -1;
  }
  mysql_close(&db);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1070 <mysql_init@plt>
lea    -0x8(%rbp),%rdi
lea    0xe7d(%rip),%rsi
lea    0xe80(%rip),%rdx
lea    0xe7e(%rip),%rcx
lea    0xe7b(%rip),%r8
mov    $0xcea,%r9d
xor    %eax,%eax
xor    %eax,%eax
movq   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
call   1050 <mysql_real_connect@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d7 <main+0x77>
lea    0xe4f(%rip),%rdi
call   1040 <printf@plt>
jmp    11e3 <main+0x83>
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
lea    0xe4c(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    -0x8(%rbp),%rdi
call   1030 <mysql_query@plt>
mov    %eax,-0x14(%rbp)
lea    0xe41(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    -0x8(%rbp),%rdi
call   1030 <mysql_query@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1234 <main+0xd4>
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
jmp    124c <main+0xec>
lea    0xe6d(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125c <main+0xfc>
lea    -0x8(%rbp),%rdi
call   1060 <mysql_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <mysql_init@plt>
lea    0xe87(%rip),%rsi
lea    0xe8a(%rip),%rdx
lea    0xe88(%rip),%rcx
lea    0xe85(%rip),%r8
mov    %rbx,%rdi
mov    $0xcea,%r9d
push   $0x0
push   $0x0
call   1050 <mysql_real_connect@plt>
add    $0x10,%rsp
test   %rax,%rax
lea    0xef7(%rip),%rax
lea    0xedb(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
lea    0xe57(%rip),%rsi
mov    %rbx,%rdi
call   1040 <mysql_query@plt>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1040 <mysql_query@plt>
test   %eax,%eax
jne    11fe <main+0x9e>
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rdi
call   1060 <mysql_close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe7e(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%eax
jmp    11f8 <main+0x98>

LLVM IR (-O0):
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [5 x i8] c"root\00"
@.str.2 = [4 x i8] c"123\00"
@.str.3 = [9 x i8] c"class306\00"
@.str.4 = [14 x i8] c"connect fail\0A\00"
@.str.5 = [12 x i8] c"connect ok\0A\00"
@.str.6 = [16 x i8] c"set names utf8;\00"
@.str.7 = [87 x i8] c"insert into students(id,name,sex,age,tel)values(NULL,'\E6\9D\8E\E5\9B\9B','\E7\94\B7',20,'12345678901');\00"
@.str.8 = [11 x i8] c"insert ok\0A\00"
@.str.9 = [13 x i8] c"insert fail\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i32 0, i32* %1
%7 = call i32 @mysql_init(i32* %2)
%8 = 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 ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 3306, i32* null, i32 0)
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %15
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %15
15: ; preds = %13, %11
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8** %5
%16 = load i8*, i8** %5
%17 = call i32 @mysql_query(i32* %2, i8* %16)
store i32 %17, i32* %4
store i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.7, i64 0, i64 0), i8** %6
%18 = load i8*, i8** %6
%19 = call i32 @mysql_query(i32* %2, i8* %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %26
24: ; preds = %15
%25 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
store i32 -1, i32* %1
br label %28
26: ; preds = %22
%27 = call i32 @mysql_close(i32* %2)
store i32 0, i32* %1
br label %28
28: ; preds = %26, %24
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [5 x i8] c"root\00"
@.str.2 = [4 x i8] c"123\00"
@.str.3 = [9 x i8] c"class306\00"
@.str.6 = [16 x i8] c"set names utf8;\00"
@.str.7 = [87 x i8] c"insert into students(id,name,sex,age,tel)values(NULL,'\E6\9D\8E\E5\9B\9B','\E7\94\B7',20,'12345678901');\00"
@.str.9 = [13 x i8] c"insert fail\0A\00"
@str = [11 x i8] c"connect ok\00"
@str.10 = [10 x i8] c"insert ok\00"
@str.11 = [13 x i8] c"connect fail\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @mysql_init(i32* %1)
%4 = call i32* @mysql_real_connect(i32* %1, 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 ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 3306, i32* null, i32 0)
%5 = icmp eq i32* %4, null
%6 = select i1 %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str.11, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0)
%7 = call i32 @puts(i8* dereferenceable(1) %6)
%8 = call i32 @mysql_query(i32* %1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%9 = call i32 @mysql_query(i32* %1, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.7, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.10, i64 0, i64 0))
%13 = call i32 @mysql_close(i32* %1)
br label %16
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
br label %16
16: ; preds = %11, %14
%17 = phi i32 [ 0, %11 ], [ -1, %14 ]
ret i32 %17
}