#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ mysql_close(int /*<<< orphan*/ *);
char *mysql_error(int /*<<< orphan*/ *);
int /*<<< orphan*/ *mysql_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_real_connect(int /*<<< orphan*/ *, char *, char *,
                                      char *, char *, int, int /*<<< orphan*/ *,
                                      int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void *mysql_client_reconnect_thread() {
  int i;
  char *query = "SELECT 1";
  MYSQL *mysql = NULL;
  for (i = 0; i < 640000; i++) {
    mysql = mysql_init(NULL);
    if (!mysql_real_connect(mysql, "127.0.0.1", "root", "", "test", 6033, NULL,
                            0)) {
      fprintf(stderr, "Failed to connect to database: Error: %s\n",
              mysql_error(mysql));
      return NULL;
    }
    mysql_close(mysql);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<mysql_client_reconnect_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xea1(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x9c400,-0xc(%rbp)
jge    121f <mysql_client_reconnect_thread+0xcf>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <mysql_init@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe72(%rip),%rsi
lea    0xe75(%rip),%rdx
lea    0xea1(%rip),%rcx
lea    0xe6c(%rip),%r8
mov    $0x1791,%r9d
xor    %eax,%eax
xor    %eax,%eax
movq   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
call   1040 <mysql_real_connect@plt>
cmp    $0x0,%eax
jne    1208 <mysql_client_reconnect_thread+0xb8>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <mysql_error@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe27(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1227 <mysql_client_reconnect_thread+0xd7>
mov    -0x20(%rbp),%rdi
call   1050 <mysql_close@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1172 <mysql_client_reconnect_thread+0x22>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mysql_client_reconnect_thread>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x9c400,%ebp
lea    0xe99(%rip),%r14
lea    0xe9c(%rip),%r15
lea    0xec8(%rip),%r12
lea    0xe93(%rip),%r13
nopl   0x0(%rax)
xor    %edi,%edi
call   1060 <mysql_init@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
mov    $0x1791,%r9d
push   $0x0
push   $0x0
call   1040 <mysql_real_connect@plt>
add    $0x10,%rsp
test   %eax,%eax
je     11bf <mysql_client_reconnect_thread+0x6f>
mov    %rbx,%rdi
call   1050 <mysql_close@plt>
add    $0xffffffff,%ebp
jne    1180 <mysql_client_reconnect_thread+0x30>
jmp    11e1 <mysql_client_reconnect_thread+0x91>
mov    0x2e1a(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1070 <mysql_error@plt>
lea    0xe3d(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"SELECT 1\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [5 x i8] c"root\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [5 x i8] c"test\00"
@stderr = global i32 0
@.str.5 = [42 x i8] c"Failed to connect to database: Error: %s\0A\00"
define i8* @mysql_client_reconnect_thread() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %3
store i32* null, i32** %4
store i32 0, i32* %2
br label %5
5: ; preds = %21, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 640000
br i1 %7, label %8, label %24
8: ; preds = %5
%9 = call i32* @mysql_init(i32* null)
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = call i32 @mysql_real_connect(i32* %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 6033, i32* null, i32 0)
%12 = icmp ne i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i32*, i32** %4
%16 = call i8* @mysql_error(i32* %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i8* %16)
store i8* null, i8** %1
br label %25
18: ; preds = %8
%19 = load i32*, i32** %4
%20 = call i32 @mysql_close(i32* %19)
br label %21
21: ; preds = %18
%22 = load i32, i32* %2
%23 = add nsw i32 %22, 1
store i32 %23, i32* %2
br label %5
24: ; preds = %5
store i8* null, i8** %1
br label %25
25: ; preds = %24, %13
%26 = load i8*, i8** %1
ret i8* %26
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [5 x i8] c"root\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [5 x i8] c"test\00"
@stderr = global i32 0
@.str.5 = [42 x i8] c"Failed to connect to database: Error: %s\0A\00"
define noalias i8* @mysql_client_reconnect_thread() {
br label %1
1: ; preds = %0, %10
%2 = phi i32 [ 0, %0 ], [ %12, %10 ]
%3 = tail call i32* @mysql_init(i32* null)
%4 = tail call i32 @mysql_real_connect(i32* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 6033, i32* null, i32 0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i8* @mysql_error(i32* %3)
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i8* %8)
br label %14
10: ; preds = %1
%11 = tail call i32 @mysql_close(i32* %3)
%12 = add nuw nsw i32 %2, 1
%13 = icmp eq i32 %12, 640000
br i1 %13, label %14, label %1
14: ; preds = %10, %6
ret i8* null
}