#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 */

/* Variables and functions */
int /*<<< orphan*/ free(unsigned char *);
char *malloc(int);
unsigned char *medusaReceiveRaw(int, int *);
int /*<<< orphan*/ memcpy(char *, unsigned char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char *);
scalar_t__ strstr(char *, char *);
int /*<<< orphan*/ writeError(int, char *, char *, ...);
int MySQLSessionInit(int hSocket, char **szSessionSalt) {
  unsigned char *bufReceive;
  char *szServerVersion;
  int nReceiveBufferSize = 0;
  int newerauth = 0;
  bufReceive = medusaReceiveRaw(hSocket, &nReceiveBufferSize);
  if (bufReceive == NULL) {
    writeError(3, "%s failed: medusaReceive returned no data.", "mysql.mod");
    return -1;
  }
  if (bufReceive[4] == 0xff) {
    if (strstr((char *)bufReceive + 7,
               "is not allowed to connect to this MySQL server")) {
      writeError(4,
                 "%s: Server responded that host is not allowed to connect to "
                 "MySQL service.",
                 "mysql.mod");
      if (bufReceive != NULL) {
        free(bufReceive);
        bufReceive = NULL;
      };
      return -1;
    } else {
      writeError(3, "%s: Failed to retrieve server version: %s", "mysql.mod",
                 bufReceive + 7);
      if (bufReceive != NULL) {
        free(bufReceive);
        bufReceive = NULL;
      };
      return -1;
    }
  }
  if (bufReceive[4] < 10) {
    writeError(3,
               "%s: Server responded requesting protocol version (%d). Version "
               "10 support required.",
               "mysql.mod", bufReceive[4]);
    if (bufReceive != NULL) {
      free(bufReceive);
      bufReceive = NULL;
    };
    return -1;
  } else if (bufReceive[4] > 10) {
    writeError(4,
               "%s: Server responded requesting protocol version (%d). Support "
               "for versions >10 is unknown.",
               "mysql.mod", bufReceive[4]);
  }
  szServerVersion = (char *)bufReceive + 5;
  if (!(strstr(szServerVersion, "3.") || strstr(szServerVersion, "4.") ||
        strstr(szServerVersion, "5."))) {
    writeError(3,
               "%s: Server responded requesting version (%d). Only versions "
               "3.x, 4.x, and 5.x are currently supported.",
               "mysql.mod", szServerVersion);
    if (bufReceive != NULL) {
      free(bufReceive);
      bufReceive = NULL;
    };
    return -1;
  }
  if ((strstr(szServerVersion, "4.1") || strstr(szServerVersion, "5."))) {
    newerauth = 1;
    writeError(10, "%s: Server version %s is using newer auth method.",
               "mysql.mod", szServerVersion);
  }
  if (newerauth) {
    *szSessionSalt = malloc(22);
    memset(*szSessionSalt, 0, 22);
    memcpy(*szSessionSalt, bufReceive + strlen(szServerVersion) + 10, 9);
    memcpy(*szSessionSalt + 8, bufReceive + strlen(szServerVersion) + 37, 12);
    if (strlen(*szSessionSalt) != 20) {
      writeError(3, "%s: Failed to retrieve valid session salt.", "mysql.mod");
      if (bufReceive != NULL) {
        free(bufReceive);
        bufReceive = NULL;
      };
      return -1;
    } else {
      writeError(10, "%s: Retrieved session salt: %s", "mysql.mod",
                 *szSessionSalt);
    }
  } else {
    *szSessionSalt = malloc(10);
    memset(*szSessionSalt, 0, 10);
    memcpy(*szSessionSalt, bufReceive + strlen(szServerVersion) + 10, 9);
    if (strlen(*szSessionSalt) != 8) {
      writeError(3, "%s: Failed to retrieve valid session salt.", "mysql.mod");
      if (bufReceive != NULL) {
        free(bufReceive);
        bufReceive = NULL;
      };
      return -1;
    } else {
      writeError(10, "%s: Retrieved session salt: %s.", "mysql.mod",
                 *szSessionSalt);
    }
  }
  if (bufReceive != NULL) {
    free(bufReceive);
    bufReceive = NULL;
  };
  return 0;
}


x86 assembly (clang, -O0):
<MySQLSessionInit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1030 <medusaReceiveRaw@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11de <MySQLSessionInit+0x5e>
mov    $0x3,%edi
lea    0xe3c(%rip),%rsi
lea    0xe60(%rip),%rdx
mov    $0x0,%al
call   1070 <writeError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1645 <MySQLSessionInit+0x4c5>
mov    -0x18(%rbp),%rax
movzbl 0x4(%rax),%eax
cmp    $0xff,%eax
jne    129b <MySQLSessionInit+0x11b>
mov    -0x18(%rbp),%rdi
add    $0x7,%rdi
lea    0xe35(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     1251 <MySQLSessionInit+0xd1>
mov    $0x4,%edi
lea    0xe49(%rip),%rsi
lea    0xe09(%rip),%rdx
mov    $0x0,%al
call   1070 <writeError@plt>
cmpq   $0x0,-0x18(%rbp)
je     1245 <MySQLSessionInit+0xc5>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x4(%rbp)
jmp    1645 <MySQLSessionInit+0x4c5>
mov    -0x18(%rbp),%rcx
add    $0x7,%rcx
mov    $0x3,%edi
lea    0xe4a(%rip),%rsi
lea    0xdbf(%rip),%rdx
mov    $0x0,%al
call   1070 <writeError@plt>
cmpq   $0x0,-0x18(%rbp)
je     128f <MySQLSessionInit+0x10f>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x4(%rbp)
jmp    1645 <MySQLSessionInit+0x4c5>
mov    -0x18(%rbp),%rax
movzbl 0x4(%rax),%eax
cmp    $0xa,%eax
jge    12f6 <MySQLSessionInit+0x176>
mov    -0x18(%rbp),%rax
movzbl 0x4(%rax),%ecx
mov    $0x3,%edi
lea    0xe19(%rip),%rsi
lea    0xd64(%rip),%rdx
mov    $0x0,%al
call   1070 <writeError@plt>
cmpq   $0x0,-0x18(%rbp)
je     12ea <MySQLSessionInit+0x16a>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x4(%rbp)
jmp    1645 <MySQLSessionInit+0x4c5>
mov    -0x18(%rbp),%rax
movzbl 0x4(%rax),%eax
cmp    $0xa,%eax
jle    1329 <MySQLSessionInit+0x1a9>
mov    -0x18(%rbp),%rax
movzbl 0x4(%rax),%ecx
mov    $0x4,%edi
lea    0xe12(%rip),%rsi
lea    0xd09(%rip),%rdx
mov    $0x0,%al
call   1070 <writeError@plt>
jmp    132e <MySQLSessionInit+0x1ae>
mov    -0x18(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
jne    13ce <MySQLSessionInit+0x24e>
mov    -0x20(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
jne    13ce <MySQLSessionInit+0x24e>
mov    -0x20(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
jne    13ce <MySQLSessionInit+0x24e>
mov    -0x20(%rbp),%rcx
mov    $0x3,%edi
lea    0xdfa(%rip),%rsi
lea    0xc8c(%rip),%rdx
mov    $0x0,%al
call   1070 <writeError@plt>
cmpq   $0x0,-0x18(%rbp)
je     13c2 <MySQLSessionInit+0x242>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x4(%rbp)
jmp    1645 <MySQLSessionInit+0x4c5>
mov    -0x20(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
jne    1402 <MySQLSessionInit+0x282>
mov    -0x20(%rbp),%rdi
lea    0xd9c(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     1427 <MySQLSessionInit+0x2a7>
movl   $0x1,-0x28(%rbp)
mov    -0x20(%rbp),%rcx
mov    $0xa,%edi
lea    0xde4(%rip),%rsi
lea    0xc0b(%rip),%rdx
mov    $0x0,%al
call   1070 <writeError@plt>
cmpl   $0x0,-0x28(%rbp)
je     1547 <MySQLSessionInit+0x3c7>
mov    $0x16,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
xor    %esi,%esi
mov    $0x16,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdi
cltq
add    %rax,%rsi
add    $0xa,%rsi
mov    $0x9,%edx
call   1080 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdi
cltq
add    %rax,%rsi
add    $0x25,%rsi
mov    $0xc,%edx
call   1080 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
cmp    $0x14,%eax
je     1521 <MySQLSessionInit+0x3a1>
mov    $0x3,%edi
lea    0xd44(%rip),%rsi
lea    0xb39(%rip),%rdx
mov    $0x0,%al
call   1070 <writeError@plt>
cmpq   $0x0,-0x18(%rbp)
je     1515 <MySQLSessionInit+0x395>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x4(%rbp)
jmp    1645 <MySQLSessionInit+0x4c5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    $0xa,%edi
lea    0xd26(%rip),%rsi
lea    0xaf0(%rip),%rdx
mov    $0x0,%al
call   1070 <writeError@plt>
jmp    1622 <MySQLSessionInit+0x4a2>
mov    $0xa,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x58(%rbp),%rsi
mov    -0x50(%rbp),%rdi
cltq
add    %rax,%rsi
add    $0xa,%rsi
mov    $0x9,%edx
call   1080 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
cmp    $0x8,%eax
je     15fc <MySQLSessionInit+0x47c>
mov    $0x3,%edi
lea    0xc69(%rip),%rsi
lea    0xa5e(%rip),%rdx
mov    $0x0,%al
call   1070 <writeError@plt>
cmpq   $0x0,-0x18(%rbp)
je     15f0 <MySQLSessionInit+0x470>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x4(%rbp)
jmp    1645 <MySQLSessionInit+0x4c5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    $0xa,%edi
lea    0xc6a(%rip),%rsi
lea    0xa15(%rip),%rdx
mov    $0x0,%al
call   1070 <writeError@plt>
jmp    1622 <MySQLSessionInit+0x4a2>
cmpq   $0x0,-0x18(%rbp)
je     163e <MySQLSessionInit+0x4be>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MySQLSessionInit>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rsi
call   1030 <medusaReceiveRaw@plt>
test   %rax,%rax
je     11d9 <MySQLSessionInit+0x59>
mov    %rax,%r12
movzbl 0x4(%rax),%ecx
cmp    $0xff,%ecx
je     11f8 <MySQLSessionInit+0x78>
cmp    $0x9,%cl
ja     122f <MySQLSessionInit+0xaf>
lea    0xf18(%rip),%rsi
lea    0xe63(%rip),%rdx
mov    $0x3,%edi
xor    %eax,%eax
call   1070 <writeError@plt>
jmp    140d <MySQLSessionInit+0x28d>
lea    0xe20(%rip),%rsi
lea    0xe44(%rip),%rdx
mov    $0x3,%edi
xor    %eax,%eax
call   1070 <writeError@plt>
jmp    1415 <MySQLSessionInit+0x295>
mov    %r12,%rbx
add    $0x7,%rbx
lea    0xe2f(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
je     137d <MySQLSessionInit+0x1fd>
lea    0xe46(%rip),%rsi
lea    0xe06(%rip),%rdx
mov    $0x4,%edi
jmp    1406 <MySQLSessionInit+0x286>
cmp    $0xa,%cl
je     124e <MySQLSessionInit+0xce>
lea    0xef2(%rip),%rsi
lea    0xde9(%rip),%rdx
mov    $0x4,%edi
xor    %eax,%eax
call   1070 <writeError@plt>
lea    0x5(%r12),%r15
lea    0xf2f(%rip),%rsi
mov    %r15,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
jne    1293 <MySQLSessionInit+0x113>
lea    0xf1e(%rip),%rsi
mov    %r15,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
jne    1293 <MySQLSessionInit+0x113>
lea    0xf0d(%rip),%rsi
mov    %r15,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
je     1429 <MySQLSessionInit+0x2a9>
lea    0xf5f(%rip),%rsi
mov    %r15,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
jne    12bf <MySQLSessionInit+0x13f>
lea    0xee1(%rip),%rsi
mov    %r15,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
je     139c <MySQLSessionInit+0x21c>
lea    0xf37(%rip),%rsi
lea    0xd5e(%rip),%rdx
mov    $0xa,%edi
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <writeError@plt>
mov    $0x16,%edi
call   1090 <malloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x16,%edx
call   1060 <memset@plt>
mov    (%r14),%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
lea    (%r12,%rax,1),%rsi
add    $0xa,%rsi
mov    %rbx,%rdi
mov    $0x9,%edx
call   1080 <memcpy@plt>
mov    (%r14),%rbx
add    $0x8,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
lea    (%r12,%rax,1),%rsi
add    $0x25,%rsi
mov    %rbx,%rdi
mov    $0xc,%edx
call   1080 <memcpy@plt>
mov    (%r14),%rdi
call   1050 <strlen@plt>
cmp    $0x14,%eax
jne    13f3 <MySQLSessionInit+0x273>
lea    0xf02(%rip),%rsi
mov    (%r14),%rcx
lea    0xcc9(%rip),%rdx
xor    %ebp,%ebp
mov    $0xa,%edi
xor    %eax,%eax
call   1070 <writeError@plt>
mov    %r12,%rdi
call   1040 <free@plt>
jmp    141a <MySQLSessionInit+0x29a>
lea    0xd2b(%rip),%rsi
lea    0xca0(%rip),%rdx
mov    $0x3,%edi
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <writeError@plt>
jmp    140d <MySQLSessionInit+0x28d>
mov    $0xa,%edi
call   1090 <malloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
mov    (%r14),%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
lea    (%r12,%rax,1),%rsi
add    $0xa,%rsi
mov    %rbx,%rdi
mov    $0x9,%edx
call   1080 <memcpy@plt>
mov    (%r14),%rdi
call   1050 <strlen@plt>
cmp    $0x8,%eax
jne    13f3 <MySQLSessionInit+0x273>
lea    0xe8b(%rip),%rsi
jmp    1358 <MySQLSessionInit+0x1d8>
lea    0xe35(%rip),%rsi
lea    0xc2a(%rip),%rdx
mov    $0x3,%edi
xor    %eax,%eax
call   1070 <writeError@plt>
mov    %r12,%rdi
call   1040 <free@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd62(%rip),%rsi
lea    0xbf4(%rip),%rdx
mov    $0x3,%edi
mov    %r15,%rcx
jmp    1393 <MySQLSessionInit+0x213>

LLVM IR (-O0):
@.str = [43 x i8] c"%s failed: medusaReceive returned no data.\00"
@.str.1 = [10 x i8] c"mysql.mod\00"
@.str.2 = [47 x i8] c"is not allowed to connect to this MySQL server\00"
@.str.3 = [75 x i8] c"%s: Server responded that host is not allowed to connect to MySQL service.\00"
@.str.4 = [42 x i8] c"%s: Failed to retrieve server version: %s\00"
@.str.5 = [84 x i8] c"%s: Server responded requesting protocol version (%d). Version 10 support required.\00"
@.str.6 = [92 x i8] c"%s: Server responded requesting protocol version (%d). Support for versions >10 is unknown.\00"
@.str.7 = [3 x i8] c"3.\00"
@.str.8 = [3 x i8] c"4.\00"
@.str.9 = [3 x i8] c"5.\00"
@.str.10 = [103 x i8] c"%s: Server responded requesting version (%d). Only versions 3.x, 4.x, and 5.x are currently supported.\00"
@.str.11 = [4 x i8] c"4.1\00"
@.str.12 = [50 x i8] c"%s: Server version %s is using newer auth method.\00"
@.str.13 = [43 x i8] c"%s: Failed to retrieve valid session salt.\00"
@.str.14 = [31 x i8] c"%s: Retrieved session salt: %s\00"
@.str.15 = [32 x i8] c"%s: Retrieved session salt: %s.\00"
define i32 @MySQLSessionInit(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %9
%10 = load i32, i32* %4
%11 = call i8* @medusaReceiveRaw(i32 %10, i32* %8)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i32, i8*, i8*, ...) @writeError(i32 3, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %194
16: ; preds = %2
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 4
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = icmp eq i32 %20, 255
br i1 %21, label %22, label %45
22: ; preds = %16
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 7
%25 = call i64 @strstr(i8* %24, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %22
%28 = call i32 (i32, i8*, i8*, ...) @writeError(i32 4, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%29 = load i8*, i8** %6
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i8*, i8** %6
%33 = call i32 @free(i8* %32)
store i8* null, i8** %6
br label %34
34: ; preds = %31, %27
store i32 -1, i32* %3
br label %194
35: ; preds = %22
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i64 7
%38 = call i32 (i32, i8*, i8*, ...) @writeError(i32 3, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = load i8*, i8** %6
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = load i8*, i8** %6
%43 = call i32 @free(i8* %42)
store i8* null, i8** %6
br label %44
44: ; preds = %41, %35
store i32 -1, i32* %3
br label %194
45: ; preds = %16
%46 = load i8*, i8** %6
%47 = getelementptr inbounds i8, i8* %46, i64 4
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = icmp slt i32 %49, 10
br i1 %50, label %51, label %63
51: ; preds = %45
%52 = load i8*, i8** %6
%53 = getelementptr inbounds i8, i8* %52, i64 4
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = call i32 (i32, i8*, i8*, ...) @writeError(i32 3, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %55)
%57 = load i8*, i8** %6
%58 = icmp ne i8* %57, null
br i1 %58, label %59, label %62
59: ; preds = %51
%60 = load i8*, i8** %6
%61 = call i32 @free(i8* %60)
store i8* null, i8** %6
br label %62
62: ; preds = %59, %51
store i32 -1, i32* %3
br label %194
63: ; preds = %45
%64 = load i8*, i8** %6
%65 = getelementptr inbounds i8, i8* %64, i64 4
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = icmp sgt i32 %67, 10
br i1 %68, label %69, label %75
69: ; preds = %63
%70 = load i8*, i8** %6
%71 = getelementptr inbounds i8, i8* %70, i64 4
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = call i32 (i32, i8*, i8*, ...) @writeError(i32 4, i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %73)
br label %75
75: ; preds = %69, %63
br label %76
76: ; preds = %75
%77 = load i8*, i8** %6
%78 = getelementptr inbounds i8, i8* %77, i64 5
store i8* %78, i8** %7
%79 = load i8*, i8** %7
%80 = call i64 @strstr(i8* %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%81 = icmp ne i64 %80, 0
br i1 %81, label %99, label %82
82: ; preds = %76
%83 = load i8*, i8** %7
%84 = call i64 @strstr(i8* %83, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%85 = icmp ne i64 %84, 0
br i1 %85, label %99, label %86
86: ; preds = %82
%87 = load i8*, i8** %7
%88 = call i64 @strstr(i8* %87, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%89 = icmp ne i64 %88, 0
br i1 %89, label %99, label %90
90: ; preds = %86
%91 = load i8*, i8** %7
%92 = call i32 (i32, i8*, i8*, ...) @writeError(i32 3, i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %91)
%93 = load i8*, i8** %6
%94 = icmp ne i8* %93, null
br i1 %94, label %95, label %98
95: ; preds = %90
%96 = load i8*, i8** %6
%97 = call i32 @free(i8* %96)
store i8* null, i8** %6
br label %98
98: ; preds = %95, %90
store i32 -1, i32* %3
br label %194
99: ; preds = %86, %82, %76
%100 = load i8*, i8** %7
%101 = call i64 @strstr(i8* %100, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%102 = icmp ne i64 %101, 0
br i1 %102, label %107, label %103
103: ; preds = %99
%104 = load i8*, i8** %7
%105 = call i64 @strstr(i8* %104, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%106 = icmp ne i64 %105, 0
br i1 %106, label %107, label %110
107: ; preds = %103, %99
store i32 1, i32* %9
%108 = load i8*, i8** %7
%109 = call i32 (i32, i8*, i8*, ...) @writeError(i32 10, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %108)
br label %110
110: ; preds = %107, %103
%111 = load i32, i32* %9
%112 = icmp ne i32 %111, 0
br i1 %112, label %113, label %155
113: ; preds = %110
%114 = call i8* @malloc(i32 22)
%115 = load i8**, i8*** %5
store i8* %114, i8** %115
%116 = load i8**, i8*** %5
%117 = load i8*, i8** %116
%118 = call i32 @memset(i8* %117, i32 0, i32 22)
%119 = load i8**, i8*** %5
%120 = load i8*, i8** %119
%121 = load i8*, i8** %6
%122 = load i8*, i8** %7
%123 = call i32 @strlen(i8* %122)
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds i8, i8* %121, i64 %124
%126 = getelementptr inbounds i8, i8* %125, i64 10
%127 = call i32 @memcpy(i8* %120, i8* %126, i32 9)
%128 = load i8**, i8*** %5
%129 = load i8*, i8** %128
%130 = getelementptr inbounds i8, i8* %129, i64 8
%131 = load i8*, i8** %6
%132 = load i8*, i8** %7
%133 = call i32 @strlen(i8* %132)
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds i8, i8* %131, i64 %134
%136 = getelementptr inbounds i8, i8* %135, i64 37
%137 = call i32 @memcpy(i8* %130, i8* %136, i32 12)
%138 = load i8**, i8*** %5
%139 = load i8*, i8** %138
%140 = call i32 @strlen(i8* %139)
%141 = icmp ne i32 %140, 20
br i1 %141, label %142, label %150
142: ; preds = %113
%143 = call i32 (i32, i8*, i8*, ...) @writeError(i32 3, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%144 = load i8*, i8** %6
%145 = icmp ne i8* %144, null
br i1 %145, label %146, label %149
146: ; preds = %142
%147 = load i8*, i8** %6
%148 = call i32 @free(i8* %147)
store i8* null, i8** %6
br label %149
149: ; preds = %146, %142
store i32 -1, i32* %3
br label %194
150: ; preds = %113
%151 = load i8**, i8*** %5
%152 = load i8*, i8** %151
%153 = call i32 (i32, i8*, i8*, ...) @writeError(i32 10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %152)
br label %154
154: ; preds = %150
br label %187
155: ; preds = %110
%156 = call i8* @malloc(i32 10)
%157 = load i8**, i8*** %5
store i8* %156, i8** %157
%158 = load i8**, i8*** %5
%159 = load i8*, i8** %158
%160 = call i32 @memset(i8* %159, i32 0, i32 10)
%161 = load i8**, i8*** %5
%162 = load i8*, i8** %161
%163 = load i8*, i8** %6
%164 = load i8*, i8** %7
%165 = call i32 @strlen(i8* %164)
%166 = sext i32 %165 to i64
%167 = getelementptr inbounds i8, i8* %163, i64 %166
%168 = getelementptr inbounds i8, i8* %167, i64 10
%169 = call i32 @memcpy(i8* %162, i8* %168, i32 9)
%170 = load i8**, i8*** %5
%171 = load i8*, i8** %170
%172 = call i32 @strlen(i8* %171)
%173 = icmp ne i32 %172, 8
br i1 %173, label %174, label %182
174: ; preds = %155
%175 = call i32 (i32, i8*, i8*, ...) @writeError(i32 3, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%176 = load i8*, i8** %6
%177 = icmp ne i8* %176, null
br i1 %177, label %178, label %181
178: ; preds = %174
%179 = load i8*, i8** %6
%180 = call i32 @free(i8* %179)
store i8* null, i8** %6
br label %181
181: ; preds = %178, %174
store i32 -1, i32* %3
br label %194
182: ; preds = %155
%183 = load i8**, i8*** %5
%184 = load i8*, i8** %183
%185 = call i32 (i32, i8*, i8*, ...) @writeError(i32 10, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %184)
br label %186
186: ; preds = %182
br label %187
187: ; preds = %186, %154
%188 = load i8*, i8** %6
%189 = icmp ne i8* %188, null
br i1 %189, label %190, label %193
190: ; preds = %187
%191 = load i8*, i8** %6
%192 = call i32 @free(i8* %191)
store i8* null, i8** %6
br label %193
193: ; preds = %190, %187
store i32 0, i32* %3
br label %194
194: ; preds = %193, %181, %149, %98, %62, %44, %34, %14
%195 = load i32, i32* %3
ret i32 %195
}

LLVM IR (-O2):
@.str = [43 x i8] c"%s failed: medusaReceive returned no data.\00"
@.str.1 = [10 x i8] c"mysql.mod\00"
@.str.2 = [47 x i8] c"is not allowed to connect to this MySQL server\00"
@.str.3 = [75 x i8] c"%s: Server responded that host is not allowed to connect to MySQL service.\00"
@.str.4 = [42 x i8] c"%s: Failed to retrieve server version: %s\00"
@.str.5 = [84 x i8] c"%s: Server responded requesting protocol version (%d). Version 10 support required.\00"
@.str.6 = [92 x i8] c"%s: Server responded requesting protocol version (%d). Support for versions >10 is unknown.\00"
@.str.7 = [3 x i8] c"3.\00"
@.str.8 = [3 x i8] c"4.\00"
@.str.9 = [3 x i8] c"5.\00"
@.str.10 = [103 x i8] c"%s: Server responded requesting version (%d). Only versions 3.x, 4.x, and 5.x are currently supported.\00"
@.str.11 = [4 x i8] c"4.1\00"
@.str.12 = [50 x i8] c"%s: Server version %s is using newer auth method.\00"
@.str.13 = [43 x i8] c"%s: Failed to retrieve valid session salt.\00"
@.str.14 = [31 x i8] c"%s: Retrieved session salt: %s\00"
@.str.15 = [32 x i8] c"%s: Retrieved session salt: %s.\00"
define i32 @MySQLSessionInit(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = call i8* @medusaReceiveRaw(i32 %0, i32* %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = call i32 (i32, i8*, i8*, ...) @writeError(i32 3, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %95
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %5, i64 4
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = icmp eq i8 %11, -1
br i1 %13, label %14, label %24
14: ; preds = %9
%15 = getelementptr inbounds i8, i8* %5, i64 7
%16 = call i64 @strstr(i8* %15, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = call i32 (i32, i8*, i8*, ...) @writeError(i32 4, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @free(i8* %5)
br label %95
21: ; preds = %14
%22 = call i32 (i32, i8*, i8*, ...) @writeError(i32 3, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%23 = call i32 @free(i8* %5)
br label %95
24: ; preds = %9
%25 = icmp ult i8 %11, 10
br i1 %25, label %26, label %29
26: ; preds = %24
%27 = call i32 (i32, i8*, i8*, ...) @writeError(i32 3, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%28 = call i32 @free(i8* %5)
br label %95
29: ; preds = %24
%30 = icmp eq i8 %11, 10
br i1 %30, label %33, label %31
31: ; preds = %29
%32 = call i32 (i32, i8*, i8*, ...) @writeError(i32 4, i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %33
33: ; preds = %29, %31
%34 = getelementptr inbounds i8, i8* %5, i64 5
%35 = call i64 @strstr(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %33
%38 = call i64 @strstr(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %37
%41 = call i64 @strstr(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 (i32, i8*, i8*, ...) @writeError(i32 3, i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%45 = call i32 @free(i8* %5)
br label %95
46: ; preds = %40, %37, %33
%47 = call i64 @strstr(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = call i64 @strstr(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %75, label %52
52: ; preds = %49, %46
%53 = call i32 (i32, i8*, i8*, ...) @writeError(i32 10, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%54 = call dereferenceable_or_null(22) i8* @malloc(i32 22)
store i8* %54, i8** %1
%55 = call i32 @memset(i8* %54, i32 0, i32 22)
%56 = load i8*, i8** %1
%57 = call i32 @strlen(i8* %34)
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %5, i64 %58
%60 = getelementptr inbounds i8, i8* %59, i64 10
%61 = call i32 @memcpy(i8* %56, i8* %60, i32 9)
%62 = load i8*, i8** %1
%63 = getelementptr inbounds i8, i8* %62, i64 8
%64 = call i32 @strlen(i8* %34)
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %5, i64 %65
%67 = getelementptr inbounds i8, i8* %66, i64 37
%68 = call i32 @memcpy(i8* %63, i8* %67, i32 12)
%69 = load i8*, i8** %1
%70 = call i32 @strlen(i8* %69)
%71 = icmp eq i32 %70, 20
br i1 %71, label %90, label %72
72: ; preds = %52
%73 = call i32 (i32, i8*, i8*, ...) @writeError(i32 3, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%74 = call i32 @free(i8* %5)
br label %95
75: ; preds = %49
%76 = call dereferenceable_or_null(10) i8* @malloc(i32 10)
store i8* %76, i8** %1
%77 = call i32 @memset(i8* %76, i32 0, i32 10)
%78 = load i8*, i8** %1
%79 = call i32 @strlen(i8* %34)
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %5, i64 %80
%82 = getelementptr inbounds i8, i8* %81, i64 10
%83 = call i32 @memcpy(i8* %78, i8* %82, i32 9)
%84 = load i8*, i8** %1
%85 = call i32 @strlen(i8* %84)
%86 = icmp eq i32 %85, 8
br i1 %86, label %90, label %87
87: ; preds = %75
%88 = call i32 (i32, i8*, i8*, ...) @writeError(i32 3, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%89 = call i32 @free(i8* %5)
br label %95
90: ; preds = %75, %52
%91 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0), %52 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), %75 ]
%92 = load i8*, i8** %1
%93 = call i32 (i32, i8*, i8*, ...) @writeError(i32 10, i8* %91, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %92)
%94 = call i32 @free(i8* %5)
br label %95
95: ; preds = %90, %87, %72, %43, %26, %21, %18, %7
%96 = phi i32 [ -1, %7 ], [ -1, %18 ], [ -1, %21 ], [ -1, %26 ], [ -1, %43 ], [ -1, %72 ], [ -1, %87 ], [ 0, %90 ]
ret i32 %96
}