#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*/ memcpy(char *, unsigned char *, int);
int /*<<< orphan*/ rta_SQL_string(char *, int, char *, int *);
int /*<<< orphan*/ rta_log(char *, int, char *);
int rta_dbcommand(char *buf, int *nin, char *out, int *nout) {
  int length;
  if ((int)buf[0] == 0) {
    if (*nin < 4) {
      return ((1));
    }
    length = (int)((unsigned int)(0xff & buf[3]) +
                   ((unsigned int)(0xff & buf[2]) << 8) +
                   ((unsigned int)(0xff & buf[1]) << 16));
    if (*nin < length) {
      return ((1));
    }
    if (length == 8 && buf[4] == (char)0x04 && buf[5] == (char)0xd2 &&
        buf[6] == (char)0x16 && buf[7] == (char)0x2f) {
      *out = 'N';
      out++;
      *nout -= 1;
      *nin -= length;
      return ((0));
    }
    if (length < 13) {
      *nin -= length;
      return ((0));
    }
    if (buf[4] == 0 && buf[5] == 3 && buf[6] == 0 && buf[7] == 0) {
      unsigned char reply[164] = {
          'R',  0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 'S',  0x00,
          0x00, 0x00, 0x1e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x65,
          0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x00, 0x53, 0x51, 0x4c,
          0x5f, 0x41, 0x53, 0x43, 0x49, 0x49, 0x00, 'S',  0x00, 0x00, 0x00,
          0x17, 0x44, 0x61, 0x74, 0x65, 0x53, 0x74, 0x79, 0x6c, 0x65, 0x00,
          0x49, 0x53, 0x4f, 0x2c, 0x20, 0x4d, 0x44, 0x59, 0x00, 'S',  0x00,
          0x00, 0x00, 0x14, 0x69, 0x73, 0x5f, 0x73, 0x75, 0x70, 0x65, 0x72,
          0x75, 0x73, 0x65, 0x72, 0x00, 0x6f, 0x6e, 0x00, 'S',  0x00, 0x00,
          0x00, 0x17, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x76, 0x65,
          0x72, 0x73, 0x69, 0x6f, 0x6e, 0x00, 0x37, 0x2e, 0x34, 0x00, 'S',
          0x00, 0x00, 0x00, 0x23, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e,
          0x5f, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74,
          0x69, 0x6f, 0x6e, 0x00, 0x70, 0x6f, 0x73, 0x74, 0x67, 0x72, 0x65,
          0x73, 0x00, 'K',  0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x36, 0x94,
          0x56, 0xf4, 0x8d, 0x68, 'Z',  0x00, 0x00, 0x00, 0x05, 0x49};
      if (*nout < 164) {
        rta_log("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/librta/librta/refs/heads/"
                "master/src/api.c",
                339, "%s %d: Not enough buffer space");
        return ((4));
      }
      *nin -= length;
      (void)memcpy(out, reply, 164);
      *nout -= 164;
      return ((0));
    } else if (length == 16) {
      *nin -= length;
      return ((0));
    } else {
      *nin -= length;
      return ((0));
    }
  } else if (buf[0] == 'Q') {
    if (*nin < 5) {
      return ((1));
    }
    length = (int)((unsigned int)(0xff & buf[4]) +
                   ((unsigned int)(0xff & buf[3]) << 8) +
                   ((unsigned int)(0xff & buf[2]) << 16));
    length++;
    if (*nin < length) {
      return ((1));
    }
    rta_SQL_string(&buf[5], (*nin - 5), out, nout);
    *nin -= length;
    return ((0));
  } else if (buf[0] == 'X') {
    return ((3));
  }
  return ((3));
}


x86 assembly (clang, -O0):
<rta_dbcommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1375 <rta_dbcommand+0x245>
mov    -0x18(%rbp),%rax
cmpl   $0x4,(%rax)
jge    1174 <rta_dbcommand+0x44>
movl   $0x1,-0x4(%rbp)
jmp    145c <rta_dbcommand+0x32c>
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%eax
and    $0xff,%eax
mov    -0x10(%rbp),%rcx
movsbl 0x2(%rcx),%ecx
and    $0xff,%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
and    $0xff,%ecx
shl    $0x10,%ecx
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x2c(%rbp),%eax
jge    11c5 <rta_dbcommand+0x95>
movl   $0x1,-0x4(%rbp)
jmp    145c <rta_dbcommand+0x32c>
cmpl   $0x8,-0x2c(%rbp)
jne    124a <rta_dbcommand+0x11a>
mov    -0x10(%rbp),%rax
movsbl 0x4(%rax),%eax
cmp    $0x4,%eax
jne    124a <rta_dbcommand+0x11a>
mov    -0x10(%rbp),%rax
movsbl 0x5(%rax),%eax
cmp    $0xffffffd2,%eax
jne    124a <rta_dbcommand+0x11a>
mov    -0x10(%rbp),%rax
movsbl 0x6(%rax),%eax
cmp    $0x16,%eax
jne    124a <rta_dbcommand+0x11a>
mov    -0x10(%rbp),%rax
movsbl 0x7(%rax),%eax
cmp    $0x2f,%eax
jne    124a <rta_dbcommand+0x11a>
mov    -0x20(%rbp),%rax
movb   $0x4e,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    145c <rta_dbcommand+0x32c>
cmpl   $0xd,-0x2c(%rbp)
jge    126d <rta_dbcommand+0x13d>
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    145c <rta_dbcommand+0x32c>
mov    -0x10(%rbp),%rax
movsbl 0x4(%rax),%eax
cmp    $0x0,%eax
jne    1339 <rta_dbcommand+0x209>
mov    -0x10(%rbp),%rax
movsbl 0x5(%rax),%eax
cmp    $0x3,%eax
jne    1339 <rta_dbcommand+0x209>
mov    -0x10(%rbp),%rax
movsbl 0x6(%rax),%eax
cmp    $0x0,%eax
jne    1339 <rta_dbcommand+0x209>
mov    -0x10(%rbp),%rax
movsbl 0x7(%rax),%eax
cmp    $0x0,%eax
jne    1339 <rta_dbcommand+0x209>
lea    -0xd0(%rbp),%rdi
lea    0xd41(%rip),%rsi
mov    $0xa4,%edx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rax
cmpl   $0xa4,(%rax)
jge    12fd <rta_dbcommand+0x1cd>
lea    0xdc4(%rip),%rdi
mov    $0x153,%esi
lea    0xe3c(%rip),%rdx
call   1040 <rta_log@plt>
movl   $0x4,-0x4(%rbp)
jmp    145c <rta_dbcommand+0x32c>
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
mov    $0xa4,%edx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
sub    $0xa4,%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    145c <rta_dbcommand+0x32c>
cmpl   $0x10,-0x2c(%rbp)
jne    135c <rta_dbcommand+0x22c>
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    145c <rta_dbcommand+0x32c>
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    145c <rta_dbcommand+0x32c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x51,%eax
jne    142f <rta_dbcommand+0x2ff>
mov    -0x18(%rbp),%rax
cmpl   $0x5,(%rax)
jge    139e <rta_dbcommand+0x26e>
movl   $0x1,-0x4(%rbp)
jmp    145c <rta_dbcommand+0x32c>
mov    -0x10(%rbp),%rax
movsbl 0x4(%rax),%eax
and    $0xff,%eax
mov    -0x10(%rbp),%rcx
movsbl 0x3(%rcx),%ecx
and    $0xff,%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movsbl 0x2(%rcx),%ecx
and    $0xff,%ecx
shl    $0x10,%ecx
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x2c(%rbp),%eax
jge    13f8 <rta_dbcommand+0x2c8>
movl   $0x1,-0x4(%rbp)
jmp    145c <rta_dbcommand+0x32c>
mov    -0x10(%rbp),%rdi
add    $0x5,%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
sub    $0x5,%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <rta_SQL_string@plt>
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    145c <rta_dbcommand+0x32c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x58,%eax
jne    144b <rta_dbcommand+0x31b>
movl   $0x3,-0x4(%rbp)
jmp    145c <rta_dbcommand+0x32c>
jmp    1450 <rta_dbcommand+0x320>
jmp    1455 <rta_dbcommand+0x325>
movl   $0x3,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rta_dbcommand>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xa8,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    (%rdi),%cl
cmp    $0x51,%cl
je     11b4 <rta_dbcommand+0x84>
mov    $0x3,%eax
test   %cl,%cl
jne    121b <rta_dbcommand+0xeb>
mov    (%rbx),%ecx
mov    $0x1,%eax
cmp    $0x4,%ecx
jl     121b <rta_dbcommand+0xeb>
movzwl 0x2(%rdi),%esi
shl    $0x10,%esi
bswap  %esi
movzbl 0x1(%rdi),%edx
shl    $0x10,%edx
or     %esi,%edx
mov    %ecx,%ebp
sub    %edx,%ebp
jl     121b <rta_dbcommand+0xeb>
cmp    $0x8,%edx
jne    11ee <rta_dbcommand+0xbe>
cmpb   $0x4,0x4(%rdi)
jne    1217 <rta_dbcommand+0xe7>
cmpb   $0xd2,0x5(%rdi)
jne    1217 <rta_dbcommand+0xe7>
cmpb   $0x16,0x6(%rdi)
jne    1217 <rta_dbcommand+0xe7>
cmpb   $0x2f,0x7(%rdi)
jne    1217 <rta_dbcommand+0xe7>
movb   $0x4e,(%r15)
addl   $0xffffffff,(%r14)
addl   $0xfffffff8,(%rbx)
jmp    1219 <rta_dbcommand+0xe9>
mov    (%rbx),%esi
mov    $0x1,%eax
cmp    $0x5,%esi
jl     121b <rta_dbcommand+0xeb>
movzwl 0x3(%rdi),%ecx
shl    $0x10,%ecx
bswap  %ecx
movzbl 0x2(%rdi),%ebp
shl    $0x10,%ebp
or     %ecx,%ebp
cmp    %ebp,%esi
jle    121b <rta_dbcommand+0xeb>
not    %ebp
add    $0x5,%rdi
add    $0xfffffffb,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <rta_SQL_string@plt>
add    %ebp,(%rbx)
jmp    1219 <rta_dbcommand+0xe9>
cmp    $0xc,%edx
jbe    1217 <rta_dbcommand+0xe7>
cmpb   $0x0,0x4(%rdi)
jne    120b <rta_dbcommand+0xdb>
cmpb   $0x3,0x5(%rdi)
jne    120b <rta_dbcommand+0xdb>
cmpb   $0x0,0x6(%rdi)
jne    120b <rta_dbcommand+0xdb>
cmpb   $0x0,0x7(%rdi)
je     1229 <rta_dbcommand+0xf9>
cmp    $0x10,%edx
jne    1217 <rta_dbcommand+0xe7>
add    $0xfffffff0,%ecx
mov    %ecx,(%rbx)
jmp    1219 <rta_dbcommand+0xe9>
mov    %ebp,(%rbx)
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd0(%rip),%rsi
mov    %rsp,%rdi
mov    $0xa4,%edx
call   1030 <memcpy@plt>
cmpl   $0xa3,(%r14)
jg     1265 <rta_dbcommand+0x135>
lea    0xe57(%rip),%rdi
lea    0xed4(%rip),%rdx
mov    $0x153,%esi
call   1040 <rta_log@plt>
mov    $0x4,%eax
jmp    121b <rta_dbcommand+0xeb>
mov    %ebp,(%rbx)
mov    %rsp,%rsi
mov    %r15,%rdi
mov    $0xa4,%edx
call   1030 <memcpy@plt>
addl   $0xffffff5c,(%r14)
jmp    1219 <rta_dbcommand+0xe9>

LLVM IR (-O0):
@__const.rta_dbcommand.reply = [164 x i8] c"R\00\00\00\08\00\00\00\00S\00\00\00\1Eclient_encoding\00SQL_ASCII\00S\00\00\00\17DateStyle\00ISO, MDY\00S\00\00\00\14is_superuser\00on\00S\00\00\00\17server_version\007.4\00S\00\00\00#session_authorization\00postgres\00K\00\00\00\0C\00\006\94V\F4\8DhZ\00\00\00\05I"
@.str = [132 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/librta/librta/refs/heads/master/src/api.c\00"
@.str.1 = [31 x i8] c"%s %d: Not enough buffer space\00"
define i32 @rta_dbcommand(i8* %0, i32* %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca [164 x i8]
store i8* %0, i8** %6
store i32* %1, i32** %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%12 = load i8*, i8** %6
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %148
17: ; preds = %4
%18 = load i32*, i32** %7
%19 = load i32, i32* %18
%20 = icmp slt i32 %19, 4
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 1, i32* %5
br label %209
22: ; preds = %17
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 3
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = and i32 255, %26
%28 = load i8*, i8** %6
%29 = getelementptr inbounds i8, i8* %28, i64 2
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = and i32 255, %31
%33 = shl i32 %32, 8
%34 = add i32 %27, %33
%35 = load i8*, i8** %6
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = and i32 255, %38
%40 = shl i32 %39, 16
%41 = add i32 %34, %40
store i32 %41, i32* %10
%42 = load i32*, i32** %7
%43 = load i32, i32* %42
%44 = load i32, i32* %10
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %22
store i32 1, i32* %5
br label %209
47: ; preds = %22
%48 = load i32, i32* %10
%49 = icmp eq i32 %48, 8
br i1 %49, label %50, label %85
50: ; preds = %47
%51 = load i8*, i8** %6
%52 = getelementptr inbounds i8, i8* %51, i64 4
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 4
br i1 %55, label %56, label %85
56: ; preds = %50
%57 = load i8*, i8** %6
%58 = getelementptr inbounds i8, i8* %57, i64 5
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, -46
br i1 %61, label %62, label %85
62: ; preds = %56
%63 = load i8*, i8** %6
%64 = getelementptr inbounds i8, i8* %63, i64 6
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 22
br i1 %67, label %68, label %85
68: ; preds = %62
%69 = load i8*, i8** %6
%70 = getelementptr inbounds i8, i8* %69, i64 7
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 47
br i1 %73, label %74, label %85
74: ; preds = %68
%75 = load i8*, i8** %8
store i8 78, i8* %75
%76 = load i8*, i8** %8
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %8
%78 = load i32*, i32** %9
%79 = load i32, i32* %78
%80 = sub nsw i32 %79, 1
store i32 %80, i32* %78
%81 = load i32, i32* %10
%82 = load i32*, i32** %7
%83 = load i32, i32* %82
%84 = sub nsw i32 %83, %81
store i32 %84, i32* %82
store i32 0, i32* %5
br label %209
85: ; preds = %68, %62, %56, %50, %47
%86 = load i32, i32* %10
%87 = icmp slt i32 %86, 13
br i1 %87, label %88, label %93
88: ; preds = %85
%89 = load i32, i32* %10
%90 = load i32*, i32** %7
%91 = load i32, i32* %90
%92 = sub nsw i32 %91, %89
store i32 %92, i32* %90
store i32 0, i32* %5
br label %209
93: ; preds = %85
%94 = load i8*, i8** %6
%95 = getelementptr inbounds i8, i8* %94, i64 4
%96 = load i8, i8* %95
%97 = sext i8 %96 to i32
%98 = icmp eq i32 %97, 0
br i1 %98, label %99, label %135
99: ; preds = %93
%100 = load i8*, i8** %6
%101 = getelementptr inbounds i8, i8* %100, i64 5
%102 = load i8, i8* %101
%103 = sext i8 %102 to i32
%104 = icmp eq i32 %103, 3
br i1 %104, label %105, label %135
105: ; preds = %99
%106 = load i8*, i8** %6
%107 = getelementptr inbounds i8, i8* %106, i64 6
%108 = load i8, i8* %107
%109 = sext i8 %108 to i32
%110 = icmp eq i32 %109, 0
br i1 %110, label %111, label %135
111: ; preds = %105
%112 = load i8*, i8** %6
%113 = getelementptr inbounds i8, i8* %112, i64 7
%114 = load i8, i8* %113
%115 = sext i8 %114 to i32
%116 = icmp eq i32 %115, 0
br i1 %116, label %117, label %135
117: ; preds = %111
%118 = bitcast [164 x i8]* %11 to i8*
%119 = load i32*, i32** %9
%120 = load i32, i32* %119
%121 = icmp slt i32 %120, 164
br i1 %121, label %122, label %124
122: ; preds = %117
%123 = call i32 @rta_log(i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0), i32 339, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 4, i32* %5
br label %209
124: ; preds = %117
%125 = load i32, i32* %10
%126 = load i32*, i32** %7
%127 = load i32, i32* %126
%128 = sub nsw i32 %127, %125
store i32 %128, i32* %126
%129 = load i8*, i8** %8
%130 = getelementptr inbounds [164 x i8], [164 x i8]* %11, i64 0, i64 0
%131 = call i32 @memcpy(i8* %129, i8* %130, i32 164)
%132 = load i32*, i32** %9
%133 = load i32, i32* %132
%134 = sub nsw i32 %133, 164
store i32 %134, i32* %132
store i32 0, i32* %5
br label %209
135: ; preds = %111, %105, %99, %93
%136 = load i32, i32* %10
%137 = icmp eq i32 %136, 16
br i1 %137, label %138, label %143
138: ; preds = %135
%139 = load i32, i32* %10
%140 = load i32*, i32** %7
%141 = load i32, i32* %140
%142 = sub nsw i32 %141, %139
store i32 %142, i32* %140
store i32 0, i32* %5
br label %209
143: ; preds = %135
%144 = load i32, i32* %10
%145 = load i32*, i32** %7
%146 = load i32, i32* %145
%147 = sub nsw i32 %146, %144
store i32 %147, i32* %145
store i32 0, i32* %5
br label %209
148: ; preds = %4
%149 = load i8*, i8** %6
%150 = getelementptr inbounds i8, i8* %149, i64 0
%151 = load i8, i8* %150
%152 = sext i8 %151 to i32
%153 = icmp eq i32 %152, 81
br i1 %153, label %154, label %199
154: ; preds = %148
%155 = load i32*, i32** %7
%156 = load i32, i32* %155
%157 = icmp slt i32 %156, 5
br i1 %157, label %158, label %159
158: ; preds = %154
store i32 1, i32* %5
br label %209
159: ; preds = %154
%160 = load i8*, i8** %6
%161 = getelementptr inbounds i8, i8* %160, i64 4
%162 = load i8, i8* %161
%163 = sext i8 %162 to i32
%164 = and i32 255, %163
%165 = load i8*, i8** %6
%166 = getelementptr inbounds i8, i8* %165, i64 3
%167 = load i8, i8* %166
%168 = sext i8 %167 to i32
%169 = and i32 255, %168
%170 = shl i32 %169, 8
%171 = add i32 %164, %170
%172 = load i8*, i8** %6
%173 = getelementptr inbounds i8, i8* %172, i64 2
%174 = load i8, i8* %173
%175 = sext i8 %174 to i32
%176 = and i32 255, %175
%177 = shl i32 %176, 16
%178 = add i32 %171, %177
store i32 %178, i32* %10
%179 = load i32, i32* %10
%180 = add nsw i32 %179, 1
store i32 %180, i32* %10
%181 = load i32*, i32** %7
%182 = load i32, i32* %181
%183 = load i32, i32* %10
%184 = icmp slt i32 %182, %183
br i1 %184, label %185, label %186
185: ; preds = %159
store i32 1, i32* %5
br label %209
186: ; preds = %159
%187 = load i8*, i8** %6
%188 = getelementptr inbounds i8, i8* %187, i64 5
%189 = load i32*, i32** %7
%190 = load i32, i32* %189
%191 = sub nsw i32 %190, 5
%192 = load i8*, i8** %8
%193 = load i32*, i32** %9
%194 = call i32 @rta_SQL_string(i8* %188, i32 %191, i8* %192, i32* %193)
%195 = load i32, i32* %10
%196 = load i32*, i32** %7
%197 = load i32, i32* %196
%198 = sub nsw i32 %197, %195
store i32 %198, i32* %196
store i32 0, i32* %5
br label %209
199: ; preds = %148
%200 = load i8*, i8** %6
%201 = getelementptr inbounds i8, i8* %200, i64 0
%202 = load i8, i8* %201
%203 = sext i8 %202 to i32
%204 = icmp eq i32 %203, 88
br i1 %204, label %205, label %206
205: ; preds = %199
store i32 3, i32* %5
br label %209
206: ; preds = %199
br label %207
207: ; preds = %206
br label %208
208: ; preds = %207
store i32 3, i32* %5
br label %209
209: ; preds = %208, %205, %186, %185, %158, %143, %138, %124, %122, %88, %74, %46, %21
%210 = load i32, i32* %5
ret i32 %210
}

LLVM IR (-O2):
@__const.rta_dbcommand.reply = [164 x i8] c"R\00\00\00\08\00\00\00\00S\00\00\00\1Eclient_encoding\00SQL_ASCII\00S\00\00\00\17DateStyle\00ISO, MDY\00S\00\00\00\14is_superuser\00on\00S\00\00\00\17server_version\007.4\00S\00\00\00#session_authorization\00postgres\00K\00\00\00\0C\00\006\94V\F4\8DhZ\00\00\00\05I"
@.str = [132 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/librta/librta/refs/heads/master/src/api.c\00"
@.str.1 = [31 x i8] c"%s %d: Not enough buffer space\00"
define i32 @rta_dbcommand(i8* %0, i32* nocapture %1, i8* %2, i32* %3) {
%5 = alloca [164 x i8]
%6 = load i8, i8* %0
switch i8 %6, label %112 [
i8 0, label %7
i8 81, label %87
]
7: ; preds = %4
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 4
br i1 %9, label %112, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %0, i64 3
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = getelementptr inbounds i8, i8* %0, i64 2
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = shl nuw nsw i32 %16, 8
%18 = or i32 %17, %13
%19 = getelementptr inbounds i8, i8* %0, i64 1
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = shl nuw nsw i32 %21, 16
%23 = or i32 %18, %22
%24 = icmp slt i32 %8, %23
br i1 %24, label %112, label %25
25: ; preds = %10
%26 = icmp eq i32 %23, 8
br i1 %26, label %27, label %48
27: ; preds = %25
%28 = getelementptr inbounds i8, i8* %0, i64 4
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 4
br i1 %30, label %31, label %50
31: ; preds = %27
%32 = getelementptr inbounds i8, i8* %0, i64 5
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, -46
br i1 %34, label %35, label %50
35: ; preds = %31
%36 = getelementptr inbounds i8, i8* %0, i64 6
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 22
br i1 %38, label %39, label %50
39: ; preds = %35
%40 = getelementptr inbounds i8, i8* %0, i64 7
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 47
br i1 %42, label %43, label %50
43: ; preds = %39
store i8 78, i8* %2
%44 = load i32, i32* %3
%45 = add nsw i32 %44, -1
store i32 %45, i32* %3
%46 = load i32, i32* %1
%47 = add nsw i32 %46, -8
store i32 %47, i32* %1
br label %112
48: ; preds = %25
%49 = icmp ult i32 %23, 13
br i1 %49, label %50, label %52
50: ; preds = %27, %31, %35, %39, %48
%51 = sub nsw i32 %8, %23
store i32 %51, i32* %1
br label %112
52: ; preds = %48
%53 = getelementptr inbounds i8, i8* %0, i64 4
%54 = load i8, i8* %53
%55 = icmp eq i8 %54, 0
br i1 %55, label %56, label %81
56: ; preds = %52
%57 = getelementptr inbounds i8, i8* %0, i64 5
%58 = load i8, i8* %57
%59 = icmp eq i8 %58, 3
br i1 %59, label %60, label %81
60: ; preds = %56
%61 = getelementptr inbounds i8, i8* %0, i64 6
%62 = load i8, i8* %61
%63 = icmp eq i8 %62, 0
br i1 %63, label %64, label %81
64: ; preds = %60
%65 = getelementptr inbounds i8, i8* %0, i64 7
%66 = load i8, i8* %65
%67 = icmp eq i8 %66, 0
br i1 %67, label %68, label %81
68: ; preds = %64
%69 = getelementptr inbounds [164 x i8], [164 x i8]* %5, i64 0, i64 0
%70 = load i32, i32* %3
%71 = icmp slt i32 %70, 164
br i1 %71, label %72, label %74
72: ; preds = %68
%73 = tail call i32 @rta_log(i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0), i32 339, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %79
74: ; preds = %68
%75 = sub nsw i32 %8, %23
store i32 %75, i32* %1
%76 = call i32 @memcpy(i8* %2, i8* %69, i32 164)
%77 = load i32, i32* %3
%78 = add nsw i32 %77, -164
store i32 %78, i32* %3
br label %79
79: ; preds = %74, %72
%80 = phi i32 [ 4, %72 ], [ 0, %74 ]
br label %112
81: ; preds = %64, %60, %56, %52
%82 = icmp eq i32 %23, 16
br i1 %82, label %83, label %85
83: ; preds = %81
%84 = add nsw i32 %8, -16
store i32 %84, i32* %1
br label %112
85: ; preds = %81
%86 = sub nsw i32 %8, %23
store i32 %86, i32* %1
br label %112
87: ; preds = %4
%88 = load i32, i32* %1
%89 = icmp slt i32 %88, 5
br i1 %89, label %112, label %90
90: ; preds = %87
%91 = getelementptr inbounds i8, i8* %0, i64 4
%92 = load i8, i8* %91
%93 = zext i8 %92 to i32
%94 = getelementptr inbounds i8, i8* %0, i64 3
%95 = load i8, i8* %94
%96 = zext i8 %95 to i32
%97 = shl nuw nsw i32 %96, 8
%98 = or i32 %97, %93
%99 = getelementptr inbounds i8, i8* %0, i64 2
%100 = load i8, i8* %99
%101 = zext i8 %100 to i32
%102 = shl nuw nsw i32 %101, 16
%103 = or i32 %98, %102
%104 = icmp sgt i32 %88, %103
br i1 %104, label %105, label %112
105: ; preds = %90
%106 = xor i32 %103, -1
%107 = getelementptr inbounds i8, i8* %0, i64 5
%108 = add nsw i32 %88, -5
%109 = tail call i32 @rta_SQL_string(i8* %107, i32 %108, i8* %2, i32* %3)
%110 = load i32, i32* %1
%111 = add i32 %110, %106
store i32 %111, i32* %1
br label %112
112: ; preds = %4, %90, %87, %10, %7, %105, %85, %83, %79, %50, %43
%113 = phi i32 [ 0, %43 ], [ 0, %50 ], [ %80, %79 ], [ 0, %83 ], [ 0, %85 ], [ 0, %105 ], [ 1, %7 ], [ 1, %10 ], [ 1, %87 ], [ 1, %90 ], [ 3, %4 ]
ret i32 %113
}