#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 *sql = "delete from students where id=1004;";
  ret = mysql_query(&db, sql);
  if (ret == 0) {
    printf("delete ok\n");
  } else {
    perror("delete fail\n");
    return -1;
  }
  mysql_close(&db);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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)
cmpl   $0x0,-0x14(%rbp)
jne    1219 <main+0xb9>
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
jmp    1231 <main+0xd1>
lea    0xe45(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <main+0xe1>
lea    -0x8(%rbp),%rdi
call   1060 <mysql_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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    0xeb4(%rip),%rax
lea    0xe98(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
lea    0xe57(%rip),%rsi
mov    %rbx,%rdi
call   1040 <mysql_query@plt>
test   %eax,%eax
jne    11ef <main+0x8f>
lea    0xe80(%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    0xe4a(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%eax
jmp    11e9 <main+0x89>

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 = [36 x i8] c"delete from students where id=1004;\00"
@.str.7 = [11 x i8] c"delete ok\0A\00"
@.str.8 = [13 x i8] c"delete fail\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i32 @mysql_init(i32* %2)
%7 = 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* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %14
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %14
14: ; preds = %12, %10
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i8** %5
%15 = load i8*, i8** %5
%16 = call i32 @mysql_query(i32* %2, i8* %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %23
21: ; preds = %14
%22 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %1
br label %25
23: ; preds = %19
%24 = call i32 @mysql_close(i32* %2)
store i32 0, i32* %1
br label %25
25: ; preds = %23, %21
%26 = load i32, i32* %1
ret i32 %26
}

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 = [36 x i8] c"delete from students where id=1004;\00"
@.str.8 = [13 x i8] c"delete fail\0A\00"
@str = [11 x i8] c"connect ok\00"
@str.9 = [10 x i8] c"delete ok\00"
@str.10 = [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.10, 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 ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.9, i64 0, i64 0))
%12 = call i32 @mysql_close(i32* %1)
br label %15
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
br label %15
15: ; preds = %10, %13
%16 = phi i32 [ 0, %10 ], [ -1, %13 ]
ret i32 %16
}