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

/* Variables and functions */
int BUFSIZ;
int basex_status(int);
int /*<<< orphan*/ free(char *);
char *md5(char const *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int read(int, char **, int);
int send_db(int, char *, int);
int strlen(char const *);
int /*<<< orphan*/ warnx(char *, ...);
int write(int, char const *, int);
int basex_authenticate(int sfd, const char *user, const char *passwd) {
  char ts[BUFSIZ];
  char *md5_pwd;
  int ts_len, rc, i;
  memset(ts, 0, BUFSIZ);
  rc = read(sfd, &ts, BUFSIZ);
  if (rc == -1) {
    warnx("Reading timestamp failed.");
    return -1;
  }
  ts_len = strlen(ts);
  int user_len = strlen(user) + 1;
  rc = write(sfd, user, user_len);
  if (rc == -1 || rc != user_len) {
    warnx("Sending username failed. %d != %d", rc, user_len);
    return -1;
  }
  md5_pwd = md5(passwd);
  if (md5_pwd == NULL) {
    warnx("md5 computation for password failed.");
    return -1;
  }
  int md5_pwd_len = strlen(md5_pwd);
  int pwdts_len = md5_pwd_len + ts_len + 1;
  char pwdts[pwdts_len];
  memset(pwdts, 0, sizeof(pwdts));
  for (i = 0; i < md5_pwd_len; i++)
    pwdts[i] = md5_pwd[i];
  int j = md5_pwd_len;
  for (i = 0; i < ts_len; i++, j++)
    pwdts[j] = ts[i];
  pwdts[pwdts_len - 1] = '\0';
  char *md5_pwdts = md5(pwdts);
  if (md5_pwdts == NULL) {
    warnx("md5 computation for password + timestamp failed.");
    return -1;
  }
  int md5_pwdts_len = strlen(md5_pwdts);
  rc = send_db(sfd, md5_pwdts, md5_pwdts_len + 1);
  if (rc == -1) {
    warnx("Sending credentials failed.");
    return -1;
  }
  free(md5_pwd);
  free(md5_pwdts);
  rc = basex_status(sfd);
  if (rc == -1) {
    warnx("Reading authentification status failed.");
    return -1;
  }
  if (rc != 0) {
    warnx("Authentification failed");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<basex_authenticate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x78(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x78(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
call   1080 <read@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    1225 <basex_authenticate+0x95>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1060 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    149c <basex_authenticate+0x30c>
mov    -0x78(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
je     1268 <basex_authenticate+0xd8>
mov    -0x38(%rbp),%eax
cmp    -0x44(%rbp),%eax
je     128f <basex_authenticate+0xff>
mov    -0x38(%rbp),%esi
mov    -0x44(%rbp),%edx
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1060 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    149c <basex_authenticate+0x30c>
mov    -0x18(%rbp),%rdi
call   10b0 <md5@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12c8 <basex_authenticate+0x138>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1060 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    149c <basex_authenticate+0x30c>
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edx
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
mov    %edx,%eax
lea    0x1(%rax,%rcx,1),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x80(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x58(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x48(%rbp),%eax
jge    1344 <basex_authenticate+0x1b4>
mov    -0x80(%rbp),%rax
mov    -0x30(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
movslq -0x3c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1314 <basex_authenticate+0x184>
mov    -0x48(%rbp),%eax
mov    %eax,-0x5c(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    138a <basex_authenticate+0x1fa>
mov    -0x80(%rbp),%rax
mov    -0x78(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
movslq -0x5c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1351 <basex_authenticate+0x1c1>
mov    -0x80(%rbp),%rdi
mov    -0x4c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,(%rdi,%rax,1)
call   10b0 <md5@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    13cf <basex_authenticate+0x23f>
lea    0xcac(%rip),%rdi
mov    $0x0,%al
call   1060 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    149c <basex_authenticate+0x30c>
mov    -0x68(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    -0x6c(%rbp),%edx
add    $0x1,%edx
call   1090 <send_db@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    141b <basex_authenticate+0x28b>
lea    0xc91(%rip),%rdi
mov    $0x0,%al
call   1060 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    149c <basex_authenticate+0x30c>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%edi
call   10a0 <basex_status@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    1463 <basex_authenticate+0x2d3>
lea    0xc65(%rip),%rdi
mov    $0x0,%al
call   1060 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    149c <basex_authenticate+0x30c>
cmpl   $0x0,-0x38(%rbp)
je     148e <basex_authenticate+0x2fe>
lea    0xc62(%rip),%rdi
mov    $0x0,%al
call   1060 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    149c <basex_authenticate+0x30c>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basex_authenticate>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r13
mov    %edi,%r14d
mov    0x2e22(%rip),%rbx
mov    (%rbx),%edx
mov    %rsp,%r15
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    (%rbx),%edx
mov    %r14d,%edi
mov    %r15,%rsi
call   1080 <read@plt>
cmp    $0xffffffff,%eax
je     1388 <basex_authenticate+0x1e8>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
add    $0x1,%ebx
mov    %r14d,%edi
mov    %r13,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1391 <basex_authenticate+0x1f1>
cmp    %ebx,%eax
jne    1391 <basex_authenticate+0x1f1>
mov    %r12,%rdi
call   10c0 <md5@plt>
test   %rax,%rax
je     13a5 <basex_authenticate+0x205>
mov    %rax,%r13
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    -0x30(%rbp),%rax
lea    (%r12,%rax,1),%edx
add    $0x1,%edx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %r12,%r10
test   %r10d,%r10d
jle    1310 <basex_authenticate+0x170>
mov    %r10d,%r9d
cmp    $0x8,%r10d
jb     129f <basex_authenticate+0xff>
lea    (%r9,%r13,1),%rcx
cmp    %rcx,%rbx
jae    13c0 <basex_authenticate+0x220>
lea    (%rbx,%r9,1),%rcx
cmp    %rcx,%r13
jae    13c0 <basex_authenticate+0x220>
xor    %ecx,%ecx
mov    %rcx,%rdx
not    %rdx
add    %r9,%rdx
mov    %r9,%rsi
and    $0x3,%rsi
je     12d3 <basex_authenticate+0x133>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x0(%r13,%rcx,1),%eax
mov    %al,(%rbx,%rcx,1)
add    $0x1,%rcx
add    $0xffffffffffffffff,%rsi
jne    12c0 <basex_authenticate+0x120>
cmp    $0x3,%rdx
jb     1310 <basex_authenticate+0x170>
nopl   0x0(%rax)
movzbl 0x0(%r13,%rcx,1),%eax
mov    %al,(%rbx,%rcx,1)
movzbl 0x1(%r13,%rcx,1),%eax
mov    %al,0x1(%rbx,%rcx,1)
movzbl 0x2(%r13,%rcx,1),%eax
mov    %al,0x2(%rbx,%rcx,1)
movzbl 0x3(%r13,%rcx,1),%eax
mov    %al,0x3(%rbx,%rcx,1)
add    $0x4,%rcx
cmp    %rcx,%r9
jne    12e0 <basex_authenticate+0x140>
mov    -0x30(%rbp),%rax
lea    (%r10,%rax,1),%r12d
test   %eax,%eax
jle    132c <basex_authenticate+0x18c>
movslq %r10d,%rdi
add    %rbx,%rdi
mov    %eax,%edx
mov    %r15,%rsi
call   1090 <memcpy@plt>
movslq %r12d,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
call   10c0 <md5@plt>
test   %rax,%rax
je     13ae <basex_authenticate+0x20e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r14d,%edi
mov    %rbx,%rsi
call   10a0 <send_db@plt>
cmp    $0xffffffff,%eax
je     13b7 <basex_authenticate+0x217>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
call   10b0 <basex_status@plt>
test   %eax,%eax
je     13e0 <basex_authenticate+0x240>
cmp    $0xffffffff,%eax
jne    13cd <basex_authenticate+0x22d>
lea    0xd28(%rip),%rdi
jmp    13d4 <basex_authenticate+0x234>
lea    0xc71(%rip),%rdi
jmp    13d4 <basex_authenticate+0x234>
lea    0xc82(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <warnx@plt>
jmp    13db <basex_authenticate+0x23b>
lea    0xc90(%rip),%rdi
jmp    13d4 <basex_authenticate+0x234>
lea    0xcac(%rip),%rdi
jmp    13d4 <basex_authenticate+0x234>
lea    0xcd4(%rip),%rdi
jmp    13d4 <basex_authenticate+0x234>
cmp    $0x20,%r10d
jae    13ef <basex_authenticate+0x24f>
xor    %ecx,%ecx
jmp    14ce <basex_authenticate+0x32e>
lea    0xd02(%rip),%rdi
xor    %eax,%eax
call   1060 <warnx@plt>
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r9d,%ecx
and    $0xffffffe0,%ecx
lea    -0x20(%rcx),%rdx
mov    %rdx,%rsi
shr    $0x5,%rsi
add    $0x1,%rsi
mov    %esi,%r8d
and    $0x3,%r8d
cmp    $0x60,%rdx
jae    1415 <basex_authenticate+0x275>
xor    %edi,%edi
jmp    1481 <basex_authenticate+0x2e1>
and    $0xfffffffffffffffc,%rsi
xor    %edi,%edi
nopl   0x0(%rax,%rax,1)
movups 0x0(%r13,%rdi,1),%xmm0
movups 0x10(%r13,%rdi,1),%xmm1
movaps %xmm0,(%rbx,%rdi,1)
movaps %xmm1,0x10(%rbx,%rdi,1)
movups 0x20(%r13,%rdi,1),%xmm0
movups 0x30(%r13,%rdi,1),%xmm1
movaps %xmm0,0x20(%rbx,%rdi,1)
movaps %xmm1,0x30(%rbx,%rdi,1)
movups 0x40(%r13,%rdi,1),%xmm0
movups 0x50(%r13,%rdi,1),%xmm1
movaps %xmm0,0x40(%rbx,%rdi,1)
movaps %xmm1,0x50(%rbx,%rdi,1)
movups 0x60(%r13,%rdi,1),%xmm0
movups 0x70(%r13,%rdi,1),%xmm1
movaps %xmm0,0x60(%rbx,%rdi,1)
movaps %xmm1,0x70(%rbx,%rdi,1)
sub    $0xffffffffffffff80,%rdi
add    $0xfffffffffffffffc,%rsi
jne    1420 <basex_authenticate+0x280>
test   %r8,%r8
je     14bb <basex_authenticate+0x31b>
lea    (%rbx,%rdi,1),%rsi
add    $0x10,%rsi
add    %r13,%rdi
add    $0x10,%rdi
shl    $0x5,%r8
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
movups -0x10(%rdi,%rdx,1),%xmm0
movups (%rdi,%rdx,1),%xmm1
movaps %xmm0,-0x10(%rsi,%rdx,1)
movaps %xmm1,(%rsi,%rdx,1)
add    $0x20,%rdx
cmp    %rdx,%r8
jne    14a0 <basex_authenticate+0x300>
cmp    %r9,%rcx
je     1310 <basex_authenticate+0x170>
test   $0x18,%r9b
je     12a1 <basex_authenticate+0x101>
mov    %rcx,%rdx
mov    %r9d,%ecx
and    $0xfffffff8,%ecx
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13,%rdx,1),%rsi
mov    %rsi,(%rbx,%rdx,1)
add    $0x8,%rdx
cmp    %rdx,%rcx
jne    14e0 <basex_authenticate+0x340>
cmp    %r9,%rcx
je     1310 <basex_authenticate+0x170>
jmp    12a1 <basex_authenticate+0x101>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [26 x i8] c"Reading timestamp failed.\00"
@.str.1 = [34 x i8] c"Sending username failed. %d != %d\00"
@.str.2 = [37 x i8] c"md5 computation for password failed.\00"
@.str.3 = [49 x i8] c"md5 computation for password + timestamp failed.\00"
@.str.4 = [28 x i8] c"Sending credentials failed.\00"
@.str.5 = [40 x i8] c"Reading authentification status failed.\00"
@.str.6 = [24 x i8] c"Authentification failed\00"
define i32 @basex_authenticate(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i64
%19 = alloca i32
%20 = alloca i8*
%21 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%22 = load i32, i32* @BUFSIZ
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %8
%25 = alloca i8, i64 %23
store i64 %23, i64* %9
%26 = load i32, i32* @BUFSIZ
%27 = call i32 @memset(i8* %25, i32 0, i32 %26)
%28 = load i32, i32* %5
%29 = bitcast i8* %25 to i8**
%30 = load i32, i32* @BUFSIZ
%31 = call i32 @read(i32 %28, i8** %29, i32 %30)
store i32 %31, i32* %12
%32 = load i32, i32* %12
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %3
%35 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
store i32 1, i32* %14
br label %148
36: ; preds = %3
%37 = call i32 @strlen(i8* %25)
store i32 %37, i32* %11
%38 = load i8*, i8** %6
%39 = call i32 @strlen(i8* %38)
%40 = add nsw i32 %39, 1
store i32 %40, i32* %15
%41 = load i32, i32* %5
%42 = load i8*, i8** %6
%43 = load i32, i32* %15
%44 = call i32 @write(i32 %41, i8* %42, i32 %43)
store i32 %44, i32* %12
%45 = load i32, i32* %12
%46 = icmp eq i32 %45, -1
br i1 %46, label %51, label %47
47: ; preds = %36
%48 = load i32, i32* %12
%49 = load i32, i32* %15
%50 = icmp ne i32 %48, %49
br i1 %50, label %51, label %55
51: ; preds = %47, %36
%52 = load i32, i32* %12
%53 = load i32, i32* %15
%54 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %52, i32 %53)
store i32 -1, i32* %4
store i32 1, i32* %14
br label %148
55: ; preds = %47
%56 = load i8*, i8** %7
%57 = call i8* @md5(i8* %56)
store i8* %57, i8** %10
%58 = load i8*, i8** %10
%59 = icmp eq i8* %58, null
br i1 %59, label %60, label %62
60: ; preds = %55
%61 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
store i32 1, i32* %14
br label %148
62: ; preds = %55
%63 = load i8*, i8** %10
%64 = call i32 @strlen(i8* %63)
store i32 %64, i32* %16
%65 = load i32, i32* %16
%66 = load i32, i32* %11
%67 = add nsw i32 %65, %66
%68 = add nsw i32 %67, 1
store i32 %68, i32* %17
%69 = load i32, i32* %17
%70 = zext i32 %69 to i64
%71 = alloca i8, i64 %70
store i64 %70, i64* %18
%72 = trunc i64 %70 to i32
%73 = call i32 @memset(i8* %71, i32 0, i32 %72)
store i32 0, i32* %13
br label %74
74: ; preds = %87, %62
%75 = load i32, i32* %13
%76 = load i32, i32* %16
%77 = icmp slt i32 %75, %76
br i1 %77, label %78, label %90
78: ; preds = %74
%79 = load i8*, i8** %10
%80 = load i32, i32* %13
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %79, i64 %81
%83 = load i8, i8* %82
%84 = load i32, i32* %13
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %71, i64 %85
store i8 %83, i8* %86
br label %87
87: ; preds = %78
%88 = load i32, i32* %13
%89 = add nsw i32 %88, 1
store i32 %89, i32* %13
br label %74
90: ; preds = %74
%91 = load i32, i32* %16
store i32 %91, i32* %19
store i32 0, i32* %13
br label %92
92: ; preds = %104, %90
%93 = load i32, i32* %13
%94 = load i32, i32* %11
%95 = icmp slt i32 %93, %94
br i1 %95, label %96, label %109
96: ; preds = %92
%97 = load i32, i32* %13
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %25, i64 %98
%100 = load i8, i8* %99
%101 = load i32, i32* %19
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i8, i8* %71, i64 %102
store i8 %100, i8* %103
br label %104
104: ; preds = %96
%105 = load i32, i32* %13
%106 = add nsw i32 %105, 1
store i32 %106, i32* %13
%107 = load i32, i32* %19
%108 = add nsw i32 %107, 1
store i32 %108, i32* %19
br label %92
109: ; preds = %92
%110 = load i32, i32* %17
%111 = sub nsw i32 %110, 1
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i8, i8* %71, i64 %112
store i8 0, i8* %113
%114 = call i8* @md5(i8* %71)
store i8* %114, i8** %20
%115 = load i8*, i8** %20
%116 = icmp eq i8* %115, null
br i1 %116, label %117, label %119
117: ; preds = %109
%118 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %4
store i32 1, i32* %14
br label %148
119: ; preds = %109
%120 = load i8*, i8** %20
%121 = call i32 @strlen(i8* %120)
store i32 %121, i32* %21
%122 = load i32, i32* %5
%123 = load i8*, i8** %20
%124 = load i32, i32* %21
%125 = add nsw i32 %124, 1
%126 = call i32 @send_db(i32 %122, i8* %123, i32 %125)
store i32 %126, i32* %12
%127 = load i32, i32* %12
%128 = icmp eq i32 %127, -1
br i1 %128, label %129, label %131
129: ; preds = %119
%130 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %4
store i32 1, i32* %14
br label %148
131: ; preds = %119
%132 = load i8*, i8** %10
%133 = call i32 @free(i8* %132)
%134 = load i8*, i8** %20
%135 = call i32 @free(i8* %134)
%136 = load i32, i32* %5
%137 = call i32 @basex_status(i32 %136)
store i32 %137, i32* %12
%138 = load i32, i32* %12
%139 = icmp eq i32 %138, -1
br i1 %139, label %140, label %142
140: ; preds = %131
%141 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %4
store i32 1, i32* %14
br label %148
142: ; preds = %131
%143 = load i32, i32* %12
%144 = icmp ne i32 %143, 0
br i1 %144, label %145, label %147
145: ; preds = %142
%146 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %4
store i32 1, i32* %14
br label %148
147: ; preds = %142
store i32 0, i32* %4
store i32 1, i32* %14
br label %148
148: ; preds = %147, %145, %140, %129, %117, %60, %51, %34
%149 = load i8*, i8** %8
%150 = load i32, i32* %4
ret i32 %150
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [26 x i8] c"Reading timestamp failed.\00"
@.str.1 = [34 x i8] c"Sending username failed. %d != %d\00"
@.str.2 = [37 x i8] c"md5 computation for password failed.\00"
@.str.3 = [49 x i8] c"md5 computation for password + timestamp failed.\00"
@.str.4 = [28 x i8] c"Sending credentials failed.\00"
@.str.5 = [40 x i8] c"Reading authentification status failed.\00"
@.str.6 = [24 x i8] c"Authentification failed\00"
define i32 @basex_authenticate(i32 %0, i8* %1, i8* %2) {
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @memset(i8* %6, i32 0, i32 %4)
%8 = bitcast i8* %6 to i8**
%9 = load i32, i32* @BUFSIZ
%10 = call i32 @read(i32 %0, i8** %8, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %209
14: ; preds = %3
%15 = call i32 @strlen(i8* %6)
%16 = call i32 @strlen(i8* %1)
%17 = add nsw i32 %16, 1
%18 = call i32 @write(i32 %0, i8* %1, i32 %17)
%19 = icmp ne i32 %18, -1
%20 = icmp eq i32 %18, %17
%21 = and i1 %19, %20
br i1 %21, label %24, label %22
22: ; preds = %14
%23 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %17)
br label %209
24: ; preds = %14
%25 = call i8* @md5(i8* %2)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %209
29: ; preds = %24
%30 = call i32 @strlen(i8* %25)
%31 = add nsw i32 %30, %15
%32 = add nsw i32 %31, 1
%33 = zext i32 %32 to i64
%34 = alloca i8, i64 %33
%35 = call i32 @memset(i8* %34, i32 0, i32 %32)
%36 = icmp sgt i32 %30, 0
br i1 %36, label %37, label %162
37: ; preds = %29
%38 = zext i32 %30 to i64
%39 = icmp ult i32 %30, 8
br i1 %39, label %144, label %40
40: ; preds = %37
%41 = getelementptr i8, i8* %34, i64 %38
%42 = getelementptr i8, i8* %25, i64 %38
%43 = icmp ult i8* %34, %42
%44 = icmp ult i8* %25, %41
%45 = and i1 %43, %44
br i1 %45, label %144, label %46
46: ; preds = %40
%47 = icmp ult i32 %30, 32
br i1 %47, label %130, label %48
48: ; preds = %46
%49 = and i64 %38, 4294967264
%50 = add nsw i64 %49, -32
%51 = lshr exact i64 %50, 5
%52 = add nuw nsw i64 %51, 1
%53 = and i64 %52, 3
%54 = icmp ult i64 %50, 96
br i1 %54, label %106, label %55
55: ; preds = %48
%56 = and i64 %52, 1152921504606846972
br label %57
57: ; preds = %57, %55
%58 = phi i64 [ 0, %55 ], [ %103, %57 ]
%59 = phi i64 [ 0, %55 ], [ %104, %57 ]
%60 = getelementptr inbounds i8, i8* %25, i64 %58
%61 = bitcast i8* %60 to <16 x i8>*
%62 = load <16 x i8>, <16 x i8>* %61
%63 = getelementptr inbounds i8, i8* %60, i64 16
%64 = bitcast i8* %63 to <16 x i8>*
%65 = load <16 x i8>, <16 x i8>* %64
%66 = getelementptr inbounds i8, i8* %34, i64 %58
%67 = bitcast i8* %66 to <16 x i8>*
store <16 x i8> %62, <16 x i8>* %67
%68 = getelementptr inbounds i8, i8* %66, i64 16
%69 = bitcast i8* %68 to <16 x i8>*
store <16 x i8> %65, <16 x i8>* %69
%70 = or i64 %58, 32
%71 = getelementptr inbounds i8, i8* %25, i64 %70
%72 = bitcast i8* %71 to <16 x i8>*
%73 = load <16 x i8>, <16 x i8>* %72
%74 = getelementptr inbounds i8, i8* %71, i64 16
%75 = bitcast i8* %74 to <16 x i8>*
%76 = load <16 x i8>, <16 x i8>* %75
%77 = getelementptr inbounds i8, i8* %34, i64 %70
%78 = bitcast i8* %77 to <16 x i8>*
store <16 x i8> %73, <16 x i8>* %78
%79 = getelementptr inbounds i8, i8* %77, i64 16
%80 = bitcast i8* %79 to <16 x i8>*
store <16 x i8> %76, <16 x i8>* %80
%81 = or i64 %58, 64
%82 = getelementptr inbounds i8, i8* %25, i64 %81
%83 = bitcast i8* %82 to <16 x i8>*
%84 = load <16 x i8>, <16 x i8>* %83
%85 = getelementptr inbounds i8, i8* %82, i64 16
%86 = bitcast i8* %85 to <16 x i8>*
%87 = load <16 x i8>, <16 x i8>* %86
%88 = getelementptr inbounds i8, i8* %34, i64 %81
%89 = bitcast i8* %88 to <16 x i8>*
store <16 x i8> %84, <16 x i8>* %89
%90 = getelementptr inbounds i8, i8* %88, i64 16
%91 = bitcast i8* %90 to <16 x i8>*
store <16 x i8> %87, <16 x i8>* %91
%92 = or i64 %58, 96
%93 = getelementptr inbounds i8, i8* %25, i64 %92
%94 = bitcast i8* %93 to <16 x i8>*
%95 = load <16 x i8>, <16 x i8>* %94
%96 = getelementptr inbounds i8, i8* %93, i64 16
%97 = bitcast i8* %96 to <16 x i8>*
%98 = load <16 x i8>, <16 x i8>* %97
%99 = getelementptr inbounds i8, i8* %34, i64 %92
%100 = bitcast i8* %99 to <16 x i8>*
store <16 x i8> %95, <16 x i8>* %100
%101 = getelementptr inbounds i8, i8* %99, i64 16
%102 = bitcast i8* %101 to <16 x i8>*
store <16 x i8> %98, <16 x i8>* %102
%103 = add nuw i64 %58, 128
%104 = add i64 %59, 4
%105 = icmp eq i64 %104, %56
br i1 %105, label %106, label %57
106: ; preds = %57, %48
%107 = phi i64 [ 0, %48 ], [ %103, %57 ]
%108 = icmp eq i64 %53, 0
br i1 %108, label %125, label %109
109: ; preds = %106, %109
%110 = phi i64 [ %122, %109 ], [ %107, %106 ]
%111 = phi i64 [ %123, %109 ], [ 0, %106 ]
%112 = getelementptr inbounds i8, i8* %25, i64 %110
%113 = bitcast i8* %112 to <16 x i8>*
%114 = load <16 x i8>, <16 x i8>* %113
%115 = getelementptr inbounds i8, i8* %112, i64 16
%116 = bitcast i8* %115 to <16 x i8>*
%117 = load <16 x i8>, <16 x i8>* %116
%118 = getelementptr inbounds i8, i8* %34, i64 %110
%119 = bitcast i8* %118 to <16 x i8>*
store <16 x i8> %114, <16 x i8>* %119
%120 = getelementptr inbounds i8, i8* %118, i64 16
%121 = bitcast i8* %120 to <16 x i8>*
store <16 x i8> %117, <16 x i8>* %121
%122 = add nuw i64 %110, 32
%123 = add i64 %111, 1
%124 = icmp eq i64 %123, %53
br i1 %124, label %125, label %109
125: ; preds = %109, %106
%126 = icmp eq i64 %49, %38
br i1 %126, label %162, label %127
127: ; preds = %125
%128 = and i64 %38, 24
%129 = icmp eq i64 %128, 0
br i1 %129, label %144, label %130
130: ; preds = %46, %127
%131 = phi i64 [ %49, %127 ], [ 0, %46 ]
%132 = and i64 %38, 4294967288
br label %133
133: ; preds = %133, %130
%134 = phi i64 [ %131, %130 ], [ %140, %133 ]
%135 = getelementptr inbounds i8, i8* %25, i64 %134
%136 = bitcast i8* %135 to <8 x i8>*
%137 = load <8 x i8>, <8 x i8>* %136
%138 = getelementptr inbounds i8, i8* %34, i64 %134
%139 = bitcast i8* %138 to <8 x i8>*
store <8 x i8> %137, <8 x i8>* %139
%140 = add nuw i64 %134, 8
%141 = icmp eq i64 %140, %132
br i1 %141, label %142, label %133
142: ; preds = %133
%143 = icmp eq i64 %132, %38
br i1 %143, label %162, label %144
144: ; preds = %40, %37, %127, %142
%145 = phi i64 [ 0, %37 ], [ 0, %40 ], [ %49, %127 ], [ %132, %142 ]
%146 = xor i64 %145, -1
%147 = add nsw i64 %146, %38
%148 = and i64 %38, 3
%149 = icmp eq i64 %148, 0
br i1 %149, label %159, label %150
150: ; preds = %144, %150
%151 = phi i64 [ %156, %150 ], [ %145, %144 ]
%152 = phi i64 [ %157, %150 ], [ 0, %144 ]
%153 = getelementptr inbounds i8, i8* %25, i64 %151
%154 = load i8, i8* %153
%155 = getelementptr inbounds i8, i8* %34, i64 %151
store i8 %154, i8* %155
%156 = add nuw nsw i64 %151, 1
%157 = add i64 %152, 1
%158 = icmp eq i64 %157, %148
br i1 %158, label %159, label %150
159: ; preds = %150, %144
%160 = phi i64 [ %145, %144 ], [ %156, %150 ]
%161 = icmp ult i64 %147, 3
br i1 %161, label %162, label %168
162: ; preds = %159, %168, %125, %142, %29
%163 = icmp sgt i32 %15, 0
br i1 %163, label %164, label %187
164: ; preds = %162
%165 = sext i32 %30 to i64
%166 = getelementptr i8, i8* %34, i64 %165
%167 = zext i32 %15 to i64
br label %187
168: ; preds = %159, %168
%169 = phi i64 [ %185, %168 ], [ %160, %159 ]
%170 = getelementptr inbounds i8, i8* %25, i64 %169
%171 = load i8, i8* %170
%172 = getelementptr inbounds i8, i8* %34, i64 %169
store i8 %171, i8* %172
%173 = add nuw nsw i64 %169, 1
%174 = getelementptr inbounds i8, i8* %25, i64 %173
%175 = load i8, i8* %174
%176 = getelementptr inbounds i8, i8* %34, i64 %173
store i8 %175, i8* %176
%177 = add nuw nsw i64 %169, 2
%178 = getelementptr inbounds i8, i8* %25, i64 %177
%179 = load i8, i8* %178
%180 = getelementptr inbounds i8, i8* %34, i64 %177
store i8 %179, i8* %180
%181 = add nuw nsw i64 %169, 3
%182 = getelementptr inbounds i8, i8* %25, i64 %181
%183 = load i8, i8* %182
%184 = getelementptr inbounds i8, i8* %34, i64 %181
store i8 %183, i8* %184
%185 = add nuw nsw i64 %169, 4
%186 = icmp eq i64 %185, %38
br i1 %186, label %162, label %168
187: ; preds = %164, %162
%188 = sext i32 %31 to i64
%189 = getelementptr inbounds i8, i8* %34, i64 %188
store i8 0, i8* %189
%190 = call i8* @md5(i8* %34)
%191 = icmp eq i8* %190, null
br i1 %191, label %192, label %194
192: ; preds = %187
%193 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
br label %209
194: ; preds = %187
%195 = call i32 @strlen(i8* %190)
%196 = add nsw i32 %195, 1
%197 = call i32 @send_db(i32 %0, i8* %190, i32 %196)
%198 = icmp eq i32 %197, -1
br i1 %198, label %199, label %201
199: ; preds = %194
%200 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %209
201: ; preds = %194
%202 = call i32 @free(i8* %25)
%203 = call i32 @free(i8* %190)
%204 = call i32 @basex_status(i32 %0)
switch i32 %204, label %207 [
i32 -1, label %205
i32 0, label %209
]
205: ; preds = %201
%206 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
br label %209
207: ; preds = %201
%208 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %209
209: ; preds = %22, %27, %199, %205, %207, %201, %192, %12
%210 = phi i32 [ -1, %12 ], [ -1, %22 ], [ -1, %27 ], [ -1, %192 ], [ -1, %199 ], [ -1, %205 ], [ -1, %207 ], [ %204, %201 ]
ret i32 %210
}