#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 ERR;
int KEY_BACKSPACE;
int KEY_ENTER;
int KEY_LEFT;
int KEY_RIGHT;
int /*<<< orphan*/ addch(int);
int /*<<< orphan*/ cclog(int, char *, int, char *, ...);
int /*<<< orphan*/ delch();
int getch();
int /*<<< orphan*/ getyx(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ insch(int);
int /*<<< orphan*/ move(int, int);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ stdscr;
int /*<<< orphan*/ updateTerm();
int term_getChat(char *buffer, int bSize) {
  int curPos = 1, inputLen = 0, i;
  int key;
  int y, x;
  while (inputLen < bSize) {
    key = getch();
    cclog(1,
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/lait894/CChat/refs/heads/master/src/"
          "client.c",
          54, "key=[%d] pressed\n", key);
    if (key == ERR) {
      break;
    } else {
      if (key >= 32 && key <= 126) {
        if (curPos > inputLen) {
          buffer[inputLen++] = key;
          addch(key);
          curPos++;
        } else {
          for (i = ++inputLen; i > curPos; i--) {
            buffer[i] = buffer[i - 1];
          }
          buffer[curPos++] = key;
          insch(key);
        }
      } else {
        if (key == KEY_ENTER || key == 10) {
          cclog(1,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/lait894/CChat/refs/heads/"
                "master/src/client.c",
                72, "KEY_ENTER pressed!\n");
          cclog(1,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/lait894/CChat/refs/heads/"
                "master/src/client.c",
                73, "inputLen=[%d] buffer=[%s]\n", inputLen, buffer);
          refresh();
          updateTerm();
          if (inputLen > 0)
            break;
          else
            continue;
        } else if (key == KEY_BACKSPACE || key == 127) {
          cclog(1,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/lait894/CChat/refs/heads/"
                "master/src/client.c",
                80, "KEY_BACKSPACE pressed!\n");
          if (curPos > 1) {
            for (i = curPos - 2; i < inputLen - 1; i++) {
              buffer[i] = buffer[i + 1];
            }
            buffer[--inputLen] = '\0';
            curPos--;
            getyx(stdscr, y, x);
            move(y, x - 1);
            delch();
            refresh();
          }
        } else if (key == KEY_LEFT || key == 260) {
          cclog(1,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/lait894/CChat/refs/heads/"
                "master/src/client.c",
                93, "KEY_LEFT pressed!\n");
          if (curPos > 1) {
            curPos--;
            getyx(stdscr, y, x);
            move(y, x - 1);
            refresh();
          }
        } else if (key == KEY_RIGHT || key == 261) {
          cclog(1,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/lait894/CChat/refs/heads/"
                "master/src/client.c",
                101, "KEY_RIGHT pressed!\n");
          if (curPos <= inputLen) {
            curPos++;
            getyx(stdscr, y, x);
            move(y, x + 1);
            refresh();
          }
        }
      }
    }
  }
  return inputLen;
}


x86 assembly (clang, -O0):
<term_getChat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1531 <term_getChat+0x3a1>
mov    $0x0,%al
call   1070 <getch@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%r8d
mov    $0x1,%edi
lea    0xe2d(%rip),%rsi
mov    $0x36,%edx
lea    0xea8(%rip),%rcx
mov    $0x0,%al
call   1090 <cclog@plt>
mov    -0x1c(%rbp),%eax
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%eax
jne    11fd <term_getChat+0x6d>
jmp    1531 <term_getChat+0x3a1>
cmpl   $0x20,-0x1c(%rbp)
jl     12b5 <term_getChat+0x125>
cmpl   $0x7e,-0x1c(%rbp)
jg     12b5 <term_getChat+0x125>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    124d <term_getChat+0xbd>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%edi
call   1050 <addch@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12b0 <term_getChat+0x120>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    128e <term_getChat+0xfe>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1259 <term_getChat+0xc9>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%edi
call   10a0 <insch@plt>
jmp    1527 <term_getChat+0x397>
mov    -0x1c(%rbp),%eax
mov    0x2cf1(%rip),%rcx
cmp    (%rcx),%eax
je     12d1 <term_getChat+0x141>
cmpl   $0xa,-0x1c(%rbp)
jne    1339 <term_getChat+0x1a9>
mov    $0x1,%edi
lea    0xd23(%rip),%rsi
mov    $0x48,%edx
lea    0xdb0(%rip),%rcx
mov    $0x0,%al
call   1090 <cclog@plt>
mov    -0x14(%rbp),%r8d
mov    -0x8(%rbp),%r9
mov    $0x1,%edi
lea    0xcfc(%rip),%rsi
mov    $0x49,%edx
lea    0xd9d(%rip),%rcx
mov    $0x0,%al
call   1090 <cclog@plt>
mov    $0x0,%al
call   1060 <refresh@plt>
mov    $0x0,%al
call   1080 <updateTerm@plt>
cmpl   $0x0,-0x14(%rbp)
jle    1334 <term_getChat+0x1a4>
jmp    1531 <term_getChat+0x3a1>
jmp    11ad <term_getChat+0x1d>
mov    -0x1c(%rbp),%eax
mov    0x2c9d(%rip),%rcx
cmp    (%rcx),%eax
je     1355 <term_getChat+0x1c5>
cmpl   $0x7f,-0x1c(%rbp)
jne    1413 <term_getChat+0x283>
mov    $0x1,%edi
lea    0xc9f(%rip),%rsi
mov    $0x50,%edx
lea    0xd5b(%rip),%rcx
mov    $0x0,%al
call   1090 <cclog@plt>
cmpl   $0x1,-0x10(%rbp)
jle    140e <term_getChat+0x27e>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    13c1 <term_getChat+0x231>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1387 <term_getChat+0x1f7>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    0x2bf3(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1030 <getyx@plt>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
sub    $0x1,%esi
call   10b0 <move@plt>
mov    $0x0,%al
call   1040 <delch@plt>
mov    $0x0,%al
call   1060 <refresh@plt>
jmp    151d <term_getChat+0x38d>
mov    -0x1c(%rbp),%eax
mov    0x2ba3(%rip),%rcx
cmp    (%rcx),%eax
je     1432 <term_getChat+0x2a2>
cmpl   $0x104,-0x1c(%rbp)
jne    1492 <term_getChat+0x302>
mov    $0x1,%edi
lea    0xbc2(%rip),%rsi
mov    $0x5d,%edx
lea    0xc96(%rip),%rcx
mov    $0x0,%al
call   1090 <cclog@plt>
cmpl   $0x1,-0x10(%rbp)
jle    148d <term_getChat+0x2fd>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    0x2b6d(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1030 <getyx@plt>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
sub    $0x1,%esi
call   10b0 <move@plt>
mov    $0x0,%al
call   1060 <refresh@plt>
jmp    1518 <term_getChat+0x388>
mov    -0x1c(%rbp),%eax
mov    0x2b2c(%rip),%rcx
cmp    (%rcx),%eax
je     14b1 <term_getChat+0x321>
cmpl   $0x105,-0x1c(%rbp)
jne    1513 <term_getChat+0x383>
mov    $0x1,%edi
lea    0xb43(%rip),%rsi
mov    $0x65,%edx
lea    0xc2a(%rip),%rcx
mov    $0x0,%al
call   1090 <cclog@plt>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     150e <term_getChat+0x37e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    0x2aec(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1030 <getyx@plt>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
call   10b0 <move@plt>
mov    $0x0,%al
call   1060 <refresh@plt>
jmp    1513 <term_getChat+0x383>
jmp    1518 <term_getChat+0x388>
jmp    151d <term_getChat+0x38d>
jmp    1522 <term_getChat+0x392>
jmp    1527 <term_getChat+0x397>
jmp    152c <term_getChat+0x39c>
jmp    11ad <term_getChat+0x1d>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<term_getChat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,0x14(%rsp)
test   %esi,%esi
jle    1570 <term_getChat+0x3e0>
mov    %rdi,%r12
lea    0x31(%rdi),%rax
mov    %rax,0x18(%rsp)
lea    0x1(%rdi),%rax
mov    %rax,0x20(%rsp)
mov    $0x1,%eax
mov    %rax,0x8(%rsp)
lea    0xe30(%rip),%r13
xor    %r15d,%r15d
xor    %r14d,%r14d
lea    0xeaa(%rip),%rbx
jmp    1234 <term_getChat+0xa4>
nop
mov    $0x1,%edi
mov    %r13,%rsi
mov    $0x48,%edx
lea    0xea5(%rip),%rcx
xor    %eax,%eax
call   1090 <cclog@plt>
mov    $0x1,%edi
mov    %r13,%rsi
mov    $0x49,%edx
lea    0xe9e(%rip),%rcx
mov    %r14d,%r8d
mov    %r12,%r9
xor    %eax,%eax
call   1090 <cclog@plt>
xor    %eax,%eax
call   1060 <refresh@plt>
xor    %eax,%eax
call   1080 <updateTerm@plt>
test   $0x1,%r15b
jne    156b <term_getChat+0x3db>
xor    %eax,%eax
call   1070 <getch@plt>
mov    %eax,%ebp
mov    $0x1,%edi
mov    %r13,%rsi
mov    $0x36,%edx
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1090 <cclog@plt>
mov    0x2d8a(%rip),%rax
cmp    (%rax),%ebp
je     156b <term_getChat+0x3db>
lea    -0x20(%rbp),%eax
cmp    $0x5e,%eax
jbe    1310 <term_getChat+0x180>
cmp    $0xa,%ebp
je     11e0 <term_getChat+0x50>
mov    0x2d2e(%rip),%rax
cmp    (%rax),%ebp
je     11e0 <term_getChat+0x50>
cmp    $0x7f,%ebp
je     137f <term_getChat+0x1ef>
mov    0x2d46(%rip),%rax
cmp    (%rax),%ebp
je     137f <term_getChat+0x1ef>
cmp    $0x104,%ebp
je     13c6 <term_getChat+0x236>
mov    0x2d0b(%rip),%rax
cmp    (%rax),%ebp
je     13c6 <term_getChat+0x236>
cmp    $0x105,%ebp
je     12d4 <term_getChat+0x144>
mov    0x2cfc(%rip),%rax
cmp    (%rax),%ebp
jne    1410 <term_getChat+0x280>
mov    $0x1,%edi
mov    %r13,%rsi
mov    $0x65,%edx
lea    0xe0b(%rip),%rcx
xor    %eax,%eax
call   1090 <cclog@plt>
mov    0x8(%rsp),%rax
cmp    %eax,%r14d
jl     1410 <term_getChat+0x280>
add    $0x1,%eax
jmp    13ee <term_getChat+0x25e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%rsp),%r15
cmp    %r15d,%r14d
jge    133a <term_getChat+0x1aa>
movslq %r14d,%rax
add    $0x1,%r14d
mov    %bpl,(%r12,%rax,1)
mov    %ebp,%edi
call   1050 <addch@plt>
add    $0x1,%r15d
mov    %r15,0x8(%rsp)
jmp    1410 <term_getChat+0x280>
add    $0x1,%r14d
movslq %r14d,%rcx
movslq %r15d,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl -0x1(%r12,%rcx,1),%edx
mov    %dl,(%r12,%rcx,1)
lea    -0x1(%rcx),%rdx
mov    %rdx,%rcx
cmp    %rax,%rdx
jg     1350 <term_getChat+0x1c0>
add    $0x1,%r15d
mov    %r15,0x8(%rsp)
mov    %bpl,(%r12,%rax,1)
mov    %ebp,%edi
call   10a0 <insch@plt>
jmp    1410 <term_getChat+0x280>
mov    $0x1,%edi
mov    %r13,%rsi
mov    $0x50,%edx
lea    0xd35(%rip),%rcx
xor    %eax,%eax
call   1090 <cclog@plt>
mov    0x8(%rsp),%rbp
cmp    $0x2,%ebp
jl     1410 <term_getChat+0x280>
lea    -0x2(%rbp),%eax
lea    -0x1(%r14),%ebx
cmp    %ebx,%eax
jge    1535 <term_getChat+0x3a5>
mov    %eax,%eax
sub    %ebp,%r14d
cmp    $0x7,%r14d
jae    142b <term_getChat+0x29b>
mov    %rax,%rdx
jmp    150f <term_getChat+0x37f>
mov    $0x1,%edi
mov    %r13,%rsi
mov    $0x5d,%edx
lea    0xd06(%rip),%rcx
xor    %eax,%eax
call   1090 <cclog@plt>
mov    0x8(%rsp),%rax
cmp    $0x2,%eax
jl     1410 <term_getChat+0x280>
add    $0xffffffff,%eax
mov    %rax,0x8(%rsp)
mov    0x2bde(%rip),%rax
mov    (%rax),%edi
call   1030 <getyx@plt>
call   10b0 <move@plt>
xor    %eax,%eax
call   1060 <refresh@plt>
nopl   (%rax)
mov    %r14d,%ebx
test   %ebx,%ebx
setg   %r15b
mov    %ebx,%r14d
cmp    0x14(%rsp),%ebx
jl     11d6 <term_getChat+0x46>
jmp    1572 <term_getChat+0x3e2>
cmp    $0x1f,%r14d
jae    1438 <term_getChat+0x2a8>
xor    %ecx,%ecx
jmp    14d1 <term_getChat+0x341>
lea    0x1(%r14),%r8
mov    %r8,%rcx
movabs $0x1ffffffe0,%rdx
and    %rdx,%rcx
lea    -0x20(%rcx),%rdx
mov    %rdx,%r9
shr    $0x5,%r9
add    $0x1,%r9
test   %rdx,%rdx
je     14a4 <term_getChat+0x314>
mov    %r9,%rsi
and    $0xfffffffffffffffe,%rsi
mov    0x18(%rsp),%rdx
add    %rax,%rdx
xor    %edi,%edi
movups -0x30(%rdx,%rdi,1),%xmm0
movups -0x20(%rdx,%rdi,1),%xmm1
movups -0x10(%rdx,%rdi,1),%xmm2
movups (%rdx,%rdi,1),%xmm3
movups %xmm0,-0x31(%rdx,%rdi,1)
movups %xmm1,-0x21(%rdx,%rdi,1)
movups %xmm2,-0x11(%rdx,%rdi,1)
movups %xmm3,-0x1(%rdx,%rdi,1)
add    $0x40,%rdi
add    $0xfffffffffffffffe,%rsi
jne    1471 <term_getChat+0x2e1>
jmp    14a6 <term_getChat+0x316>
xor    %edi,%edi
test   $0x1,%r9b
je     14c6 <term_getChat+0x336>
add    %rax,%rdi
movups 0x1(%r12,%rdi,1),%xmm0
movups 0x11(%r12,%rdi,1),%xmm1
movups %xmm0,(%r12,%rdi,1)
movups %xmm1,0x10(%r12,%rdi,1)
cmp    %rcx,%r8
je     1535 <term_getChat+0x3a5>
test   $0x18,%r8b
je     1509 <term_getChat+0x379>
add    $0x1,%r14
movabs $0x1ffffffe0,%rdx
lea    0x18(%rdx),%rsi
and    %r14,%rsi
lea    (%rsi,%rax,1),%rdx
add    0x20(%rsp),%rax
nop
mov    (%rax,%rcx,1),%rdi
mov    %rdi,-0x1(%rax,%rcx,1)
add    $0x8,%rcx
cmp    %rcx,%rsi
jne    14f0 <term_getChat+0x360>
cmp    %rsi,%r14
jne    150f <term_getChat+0x37f>
jmp    1535 <term_getChat+0x3a5>
add    %rax,%rcx
mov    %rcx,%rdx
mov    %ebx,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%r12,%rdx,1),%ecx
mov    %cl,(%r12,%rdx,1)
lea    0x1(%rdx),%rcx
mov    %rcx,%rdx
cmp    %ecx,%eax
jne    1520 <term_getChat+0x390>
movslq %ebx,%rax
movb   $0x0,(%r12,%rax,1)
add    $0xffffffff,%ebp
mov    %rbp,0x8(%rsp)
mov    0x2a8c(%rip),%rax
mov    (%rax),%edi
call   1030 <getyx@plt>
call   10b0 <move@plt>
xor    %eax,%eax
call   1040 <delch@plt>
xor    %eax,%eax
call   1060 <refresh@plt>
jmp    1413 <term_getChat+0x283>
mov    %r14d,%ebx
jmp    1572 <term_getChat+0x3e2>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/lait894/CChat/refs/heads/master/src/client.c\00"
@.str.1 = [18 x i8] c"key=[%d] pressed\0A\00"
@ERR = global i32 0
@KEY_ENTER = global i32 0
@.str.2 = [20 x i8] c"KEY_ENTER pressed!\0A\00"
@.str.3 = [27 x i8] c"inputLen=[%d] buffer=[%s]\0A\00"
@KEY_BACKSPACE = global i32 0
@.str.4 = [24 x i8] c"KEY_BACKSPACE pressed!\0A\00"
@stdscr = global i32 0
@KEY_LEFT = global i32 0
@.str.5 = [19 x i8] c"KEY_LEFT pressed!\0A\00"
@KEY_RIGHT = global i32 0
@.str.6 = [20 x i8] c"KEY_RIGHT pressed!\0A\00"
define i32 @term_getChat(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 1, i32* %5
store i32 0, i32* %6
br label %11
11: ; preds = %201, %94, %2
%12 = load i32, i32* %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %202
15: ; preds = %11
%16 = call i32 (...) @getch()
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = call i32 (i32, i8*, i32, i8*, ...) @cclog(i32 1, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str, i64 0, i64 0), i32 54, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %8
%20 = load i32, i32* @ERR
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %15
br label %202
23: ; preds = %15
%24 = load i32, i32* %8
%25 = icmp sge i32 %24, 32
br i1 %25, label %26, label %77
26: ; preds = %23
%27 = load i32, i32* %8
%28 = icmp sle i32 %27, 126
br i1 %28, label %29, label %77
29: ; preds = %26
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = icmp sgt i32 %30, %31
br i1 %32, label %33, label %45
33: ; preds = %29
%34 = load i32, i32* %8
%35 = trunc i32 %34 to i8
%36 = load i8*, i8** %3
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
store i8 %35, i8* %40
%41 = load i32, i32* %8
%42 = call i32 @addch(i32 %41)
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %76
45: ; preds = %29
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
store i32 %47, i32* %7
br label %48
48: ; preds = %63, %45
%49 = load i32, i32* %7
%50 = load i32, i32* %5
%51 = icmp sgt i32 %49, %50
br i1 %51, label %52, label %66
52: ; preds = %48
%53 = load i8*, i8** %3
%54 = load i32, i32* %7
%55 = sub nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
%58 = load i8, i8* %57
%59 = load i8*, i8** %3
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
store i8 %58, i8* %62
br label %63
63: ; preds = %52
%64 = load i32, i32* %7
%65 = add nsw i32 %64, -1
store i32 %65, i32* %7
br label %48
66: ; preds = %48
%67 = load i32, i32* %8
%68 = trunc i32 %67 to i8
%69 = load i8*, i8** %3
%70 = load i32, i32* %5
%71 = add nsw i32 %70, 1
store i32 %71, i32* %5
%72 = sext i32 %70 to i64
%73 = getelementptr inbounds i8, i8* %69, i64 %72
store i8 %68, i8* %73
%74 = load i32, i32* %8
%75 = call i32 @insch(i32 %74)
br label %76
76: ; preds = %66, %33
br label %200
77: ; preds = %26, %23
%78 = load i32, i32* %8
%79 = load i32, i32* @KEY_ENTER
%80 = icmp eq i32 %78, %79
br i1 %80, label %84, label %81
81: ; preds = %77
%82 = load i32, i32* %8
%83 = icmp eq i32 %82, 10
br i1 %83, label %84, label %95
84: ; preds = %81, %77
%85 = call i32 (i32, i8*, i32, i8*, ...) @cclog(i32 1, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str, i64 0, i64 0), i32 72, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%86 = load i32, i32* %6
%87 = load i8*, i8** %3
%88 = call i32 (i32, i8*, i32, i8*, ...) @cclog(i32 1, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str, i64 0, i64 0), i32 73, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %86, i8* %87)
%89 = call i32 (...) @refresh()
%90 = call i32 (...) @updateTerm()
%91 = load i32, i32* %6
%92 = icmp sgt i32 %91, 0
br i1 %92, label %93, label %94
93: ; preds = %84
br label %202
94: ; preds = %84
br label %11
95: ; preds = %81
%96 = load i32, i32* %8
%97 = load i32, i32* @KEY_BACKSPACE
%98 = icmp eq i32 %96, %97
br i1 %98, label %102, label %99
99: ; preds = %95
%100 = load i32, i32* %8
%101 = icmp eq i32 %100, 127
br i1 %101, label %102, label %147
102: ; preds = %99, %95
%103 = call i32 (i32, i8*, i32, i8*, ...) @cclog(i32 1, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str, i64 0, i64 0), i32 80, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%104 = load i32, i32* %5
%105 = icmp sgt i32 %104, 1
br i1 %105, label %106, label %146
106: ; preds = %102
%107 = load i32, i32* %5
%108 = sub nsw i32 %107, 2
store i32 %108, i32* %7
br label %109
109: ; preds = %125, %106
%110 = load i32, i32* %7
%111 = load i32, i32* %6
%112 = sub nsw i32 %111, 1
%113 = icmp slt i32 %110, %112
br i1 %113, label %114, label %128
114: ; preds = %109
%115 = load i8*, i8** %3
%116 = load i32, i32* %7
%117 = add nsw i32 %116, 1
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds i8, i8* %115, i64 %118
%120 = load i8, i8* %119
%121 = load i8*, i8** %3
%122 = load i32, i32* %7
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds i8, i8* %121, i64 %123
store i8 %120, i8* %124
br label %125
125: ; preds = %114
%126 = load i32, i32* %7
%127 = add nsw i32 %126, 1
store i32 %127, i32* %7
br label %109
128: ; preds = %109
%129 = load i8*, i8** %3
%130 = load i32, i32* %6
%131 = add nsw i32 %130, -1
store i32 %131, i32* %6
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds i8, i8* %129, i64 %132
store i8 0, i8* %133
%134 = load i32, i32* %5
%135 = add nsw i32 %134, -1
store i32 %135, i32* %5
%136 = load i32, i32* @stdscr
%137 = load i32, i32* %9
%138 = load i32, i32* %10
%139 = call i32 @getyx(i32 %136, i32 %137, i32 %138)
%140 = load i32, i32* %9
%141 = load i32, i32* %10
%142 = sub nsw i32 %141, 1
%143 = call i32 @move(i32 %140, i32 %142)
%144 = call i32 (...) @delch()
%145 = call i32 (...) @refresh()
br label %146
146: ; preds = %128, %102
br label %198
147: ; preds = %99
%148 = load i32, i32* %8
%149 = load i32, i32* @KEY_LEFT
%150 = icmp eq i32 %148, %149
br i1 %150, label %154, label %151
151: ; preds = %147
%152 = load i32, i32* %8
%153 = icmp eq i32 %152, 260
br i1 %153, label %154, label %171
154: ; preds = %151, %147
%155 = call i32 (i32, i8*, i32, i8*, ...) @cclog(i32 1, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str, i64 0, i64 0), i32 93, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%156 = load i32, i32* %5
%157 = icmp sgt i32 %156, 1
br i1 %157, label %158, label %170
158: ; preds = %154
%159 = load i32, i32* %5
%160 = add nsw i32 %159, -1
store i32 %160, i32* %5
%161 = load i32, i32* @stdscr
%162 = load i32, i32* %9
%163 = load i32, i32* %10
%164 = call i32 @getyx(i32 %161, i32 %162, i32 %163)
%165 = load i32, i32* %9
%166 = load i32, i32* %10
%167 = sub nsw i32 %166, 1
%168 = call i32 @move(i32 %165, i32 %167)
%169 = call i32 (...) @refresh()
br label %170
170: ; preds = %158, %154
br label %197
171: ; preds = %151
%172 = load i32, i32* %8
%173 = load i32, i32* @KEY_RIGHT
%174 = icmp eq i32 %172, %173
br i1 %174, label %178, label %175
175: ; preds = %171
%176 = load i32, i32* %8
%177 = icmp eq i32 %176, 261
br i1 %177, label %178, label %196
178: ; preds = %175, %171
%179 = call i32 (i32, i8*, i32, i8*, ...) @cclog(i32 1, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str, i64 0, i64 0), i32 101, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%180 = load i32, i32* %5
%181 = load i32, i32* %6
%182 = icmp sle i32 %180, %181
br i1 %182, label %183, label %195
183: ; preds = %178
%184 = load i32, i32* %5
%185 = add nsw i32 %184, 1
store i32 %185, i32* %5
%186 = load i32, i32* @stdscr
%187 = load i32, i32* %9
%188 = load i32, i32* %10
%189 = call i32 @getyx(i32 %186, i32 %187, i32 %188)
%190 = load i32, i32* %9
%191 = load i32, i32* %10
%192 = add nsw i32 %191, 1
%193 = call i32 @move(i32 %190, i32 %192)
%194 = call i32 (...) @refresh()
br label %195
195: ; preds = %183, %178
br label %196
196: ; preds = %195, %175
br label %197
197: ; preds = %196, %170
br label %198
198: ; preds = %197, %146
br label %199
199: ; preds = %198
br label %200
200: ; preds = %199, %76
br label %201
201: ; preds = %200
br label %11
202: ; preds = %93, %22, %11
%203 = load i32, i32* %6
ret i32 %203
}

LLVM IR (-O2):
@.str = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/lait894/CChat/refs/heads/master/src/client.c\00"
@.str.1 = [18 x i8] c"key=[%d] pressed\0A\00"
@ERR = global i32 0
@KEY_ENTER = global i32 0
@.str.2 = [20 x i8] c"KEY_ENTER pressed!\0A\00"
@.str.3 = [27 x i8] c"inputLen=[%d] buffer=[%s]\0A\00"
@KEY_BACKSPACE = global i32 0
@.str.4 = [24 x i8] c"KEY_BACKSPACE pressed!\0A\00"
@stdscr = global i32 0
@KEY_LEFT = global i32 0
@.str.5 = [19 x i8] c"KEY_LEFT pressed!\0A\00"
@KEY_RIGHT = global i32 0
@.str.6 = [20 x i8] c"KEY_RIGHT pressed!\0A\00"
define i32 @term_getChat(i8* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %205
4: ; preds = %2, %200
%5 = phi i1 [ %204, %200 ], [ false, %2 ]
%6 = phi i32 [ %202, %200 ], [ 1, %2 ]
%7 = phi i32 [ %201, %200 ], [ 0, %2 ]
br label %8
8: ; preds = %4, %46
%9 = tail call i32 (...) @getch()
%10 = tail call i32 (i32, i8*, i32, i8*, ...) @cclog(i32 1, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str, i64 0, i64 0), i32 54, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @ERR
%12 = icmp eq i32 %9, %11
br i1 %12, label %205, label %13
13: ; preds = %8
%14 = add i32 %9, -32
%15 = icmp ult i32 %14, 95
br i1 %15, label %16, label %41
16: ; preds = %13
%17 = icmp slt i32 %7, %6
br i1 %17, label %18, label %25
18: ; preds = %16
%19 = trunc i32 %9 to i8
%20 = add nsw i32 %7, 1
%21 = sext i32 %7 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
store i8 %19, i8* %22
%23 = tail call i32 @addch(i32 %9)
%24 = add nsw i32 %6, 1
br label %200
25: ; preds = %16
%26 = add i32 %7, 1
%27 = sext i32 %26 to i64
%28 = sext i32 %6 to i64
br label %29
29: ; preds = %25, %29
%30 = phi i64 [ %27, %25 ], [ %31, %29 ]
%31 = add nsw i64 %30, -1
%32 = getelementptr inbounds i8, i8* %0, i64 %31
%33 = load i8, i8* %32
%34 = getelementptr inbounds i8, i8* %0, i64 %30
store i8 %33, i8* %34
%35 = icmp sgt i64 %31, %28
br i1 %35, label %29, label %36
36: ; preds = %29
%37 = trunc i32 %9 to i8
%38 = add nsw i32 %6, 1
%39 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 %37, i8* %39
%40 = tail call i32 @insch(i32 %9)
br label %200
41: ; preds = %13
%42 = load i32, i32* @KEY_ENTER
%43 = icmp eq i32 %9, %42
%44 = icmp eq i32 %9, 10
%45 = or i1 %44, %43
br i1 %45, label %46, label %51
46: ; preds = %41
%47 = tail call i32 (i32, i8*, i32, i8*, ...) @cclog(i32 1, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str, i64 0, i64 0), i32 72, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%48 = tail call i32 (i32, i8*, i32, i8*, ...) @cclog(i32 1, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str, i64 0, i64 0), i32 73, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %7, i8* %0)
%49 = tail call i32 (...) @refresh()
%50 = tail call i32 (...) @updateTerm()
br i1 %5, label %205, label %8
51: ; preds = %41
%52 = load i32, i32* @KEY_BACKSPACE
%53 = icmp eq i32 %9, %52
%54 = icmp eq i32 %9, 127
%55 = or i1 %54, %53
br i1 %55, label %56, label %172
56: ; preds = %51
%57 = tail call i32 (i32, i8*, i32, i8*, ...) @cclog(i32 1, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str, i64 0, i64 0), i32 80, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%58 = icmp sgt i32 %6, 1
br i1 %58, label %59, label %200
59: ; preds = %56
%60 = add nsw i32 %6, -2
%61 = add i32 %7, -1
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %163
63: ; preds = %59
%64 = zext i32 %60 to i64
%65 = sub i32 %7, %6
%66 = zext i32 %65 to i64
%67 = add nuw nsw i64 %66, 1
%68 = icmp ult i32 %65, 7
br i1 %68, label %153, label %69
69: ; preds = %63
%70 = icmp ult i32 %65, 31
br i1 %70, label %133, label %71
71: ; preds = %69
%72 = and i64 %67, 8589934560
%73 = add nsw i64 %72, -32
%74 = lshr exact i64 %73, 5
%75 = add nuw nsw i64 %74, 1
%76 = and i64 %75, 1
%77 = icmp eq i64 %73, 0
br i1 %77, label %111, label %78
78: ; preds = %71
%79 = and i64 %75, 1152921504606846974
br label %80
80: ; preds = %80, %78
%81 = phi i64 [ 0, %78 ], [ %108, %80 ]
%82 = phi i64 [ 0, %78 ], [ %109, %80 ]
%83 = add i64 %81, %64
%84 = add nuw nsw i64 %83, 1
%85 = getelementptr inbounds i8, i8* %0, i64 %84
%86 = bitcast i8* %85 to <16 x i8>*
%87 = load <16 x i8>, <16 x i8>* %86
%88 = getelementptr inbounds i8, i8* %85, i64 16
%89 = bitcast i8* %88 to <16 x i8>*
%90 = load <16 x i8>, <16 x i8>* %89
%91 = getelementptr inbounds i8, i8* %0, i64 %83
%92 = bitcast i8* %91 to <16 x i8>*
store <16 x i8> %87, <16 x i8>* %92
%93 = getelementptr inbounds i8, i8* %91, i64 16
%94 = bitcast i8* %93 to <16 x i8>*
store <16 x i8> %90, <16 x i8>* %94
%95 = or i64 %81, 32
%96 = add i64 %95, %64
%97 = add nuw nsw i64 %96, 1
%98 = getelementptr inbounds i8, i8* %0, i64 %97
%99 = bitcast i8* %98 to <16 x i8>*
%100 = load <16 x i8>, <16 x i8>* %99
%101 = getelementptr inbounds i8, i8* %98, i64 16
%102 = bitcast i8* %101 to <16 x i8>*
%103 = load <16 x i8>, <16 x i8>* %102
%104 = getelementptr inbounds i8, i8* %0, i64 %96
%105 = bitcast i8* %104 to <16 x i8>*
store <16 x i8> %100, <16 x i8>* %105
%106 = getelementptr inbounds i8, i8* %104, i64 16
%107 = bitcast i8* %106 to <16 x i8>*
store <16 x i8> %103, <16 x i8>* %107
%108 = add nuw i64 %81, 64
%109 = add i64 %82, 2
%110 = icmp eq i64 %109, %79
br i1 %110, label %111, label %80
111: ; preds = %80, %71
%112 = phi i64 [ 0, %71 ], [ %108, %80 ]
%113 = icmp eq i64 %76, 0
br i1 %113, label %127, label %114
114: ; preds = %111
%115 = add i64 %112, %64
%116 = add nuw nsw i64 %115, 1
%117 = getelementptr inbounds i8, i8* %0, i64 %116
%118 = bitcast i8* %117 to <16 x i8>*
%119 = load <16 x i8>, <16 x i8>* %118
%120 = getelementptr inbounds i8, i8* %117, i64 16
%121 = bitcast i8* %120 to <16 x i8>*
%122 = load <16 x i8>, <16 x i8>* %121
%123 = getelementptr inbounds i8, i8* %0, i64 %115
%124 = bitcast i8* %123 to <16 x i8>*
store <16 x i8> %119, <16 x i8>* %124
%125 = getelementptr inbounds i8, i8* %123, i64 16
%126 = bitcast i8* %125 to <16 x i8>*
store <16 x i8> %122, <16 x i8>* %126
br label %127
127: ; preds = %111, %114
%128 = icmp eq i64 %67, %72
br i1 %128, label %163, label %129
129: ; preds = %127
%130 = add nuw nsw i64 %72, %64
%131 = and i64 %67, 24
%132 = icmp eq i64 %131, 0
br i1 %132, label %153, label %133
133: ; preds = %69, %129
%134 = phi i64 [ %72, %129 ], [ 0, %69 ]
%135 = sub i32 %7, %6
%136 = zext i32 %135 to i64
%137 = add nuw nsw i64 %136, 1
%138 = and i64 %137, 8589934584
%139 = add nuw nsw i64 %138, %64
br label %140
140: ; preds = %140, %133
%141 = phi i64 [ %134, %133 ], [ %149, %140 ]
%142 = add i64 %141, %64
%143 = add nuw nsw i64 %142, 1
%144 = getelementptr inbounds i8, i8* %0, i64 %143
%145 = bitcast i8* %144 to <8 x i8>*
%146 = load <8 x i8>, <8 x i8>* %145
%147 = getelementptr inbounds i8, i8* %0, i64 %142
%148 = bitcast i8* %147 to <8 x i8>*
store <8 x i8> %146, <8 x i8>* %148
%149 = add nuw i64 %141, 8
%150 = icmp eq i64 %149, %138
br i1 %150, label %151, label %140
151: ; preds = %140
%152 = icmp eq i64 %137, %138
br i1 %152, label %163, label %153
153: ; preds = %63, %129, %151
%154 = phi i64 [ %64, %63 ], [ %130, %129 ], [ %139, %151 ]
br label %155
155: ; preds = %153, %155
%156 = phi i64 [ %157, %155 ], [ %154, %153 ]
%157 = add nuw nsw i64 %156, 1
%158 = getelementptr inbounds i8, i8* %0, i64 %157
%159 = load i8, i8* %158
%160 = getelementptr inbounds i8, i8* %0, i64 %156
store i8 %159, i8* %160
%161 = trunc i64 %157 to i32
%162 = icmp eq i32 %61, %161
br i1 %162, label %163, label %155
163: ; preds = %155, %127, %151, %59
%164 = sext i32 %61 to i64
%165 = getelementptr inbounds i8, i8* %0, i64 %164
store i8 0, i8* %165
%166 = add nsw i32 %6, -1
%167 = load i32, i32* @stdscr
%168 = tail call i32 @getyx(i32 %167, i32 undef, i32 undef)
%169 = tail call i32 @move(i32 undef, i32 undef)
%170 = tail call i32 (...) @delch()
%171 = tail call i32 (...) @refresh()
br label %200
172: ; preds = %51
%173 = load i32, i32* @KEY_LEFT
%174 = icmp eq i32 %9, %173
%175 = icmp eq i32 %9, 260
%176 = or i1 %175, %174
br i1 %176, label %177, label %186
177: ; preds = %172
%178 = tail call i32 (i32, i8*, i32, i8*, ...) @cclog(i32 1, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str, i64 0, i64 0), i32 93, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%179 = icmp sgt i32 %6, 1
br i1 %179, label %180, label %200
180: ; preds = %177
%181 = add nsw i32 %6, -1
%182 = load i32, i32* @stdscr
%183 = tail call i32 @getyx(i32 %182, i32 undef, i32 undef)
%184 = tail call i32 @move(i32 undef, i32 undef)
%185 = tail call i32 (...) @refresh()
br label %200
186: ; preds = %172
%187 = load i32, i32* @KEY_RIGHT
%188 = icmp eq i32 %9, %187
%189 = icmp eq i32 %9, 261
%190 = or i1 %189, %188
br i1 %190, label %191, label %200
191: ; preds = %186
%192 = tail call i32 (i32, i8*, i32, i8*, ...) @cclog(i32 1, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str, i64 0, i64 0), i32 101, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%193 = icmp slt i32 %7, %6
br i1 %193, label %200, label %194
194: ; preds = %191
%195 = add nsw i32 %6, 1
%196 = load i32, i32* @stdscr
%197 = tail call i32 @getyx(i32 %196, i32 undef, i32 undef)
%198 = tail call i32 @move(i32 undef, i32 undef)
%199 = tail call i32 (...) @refresh()
br label %200
200: ; preds = %36, %18, %163, %56, %186, %194, %191, %177, %180
%201 = phi i32 [ %20, %18 ], [ %26, %36 ], [ %61, %163 ], [ %7, %56 ], [ %7, %180 ], [ %7, %177 ], [ %7, %194 ], [ %7, %191 ], [ %7, %186 ]
%202 = phi i32 [ %24, %18 ], [ %38, %36 ], [ %166, %163 ], [ %6, %56 ], [ %181, %180 ], [ %6, %177 ], [ %195, %194 ], [ %6, %191 ], [ %6, %186 ]
%203 = icmp slt i32 %201, %1
%204 = icmp sgt i32 %201, 0
br i1 %203, label %4, label %205
205: ; preds = %200, %8, %46, %2
%206 = phi i32 [ 0, %2 ], [ %7, %46 ], [ %7, %8 ], [ %201, %200 ]
ret i32 %206
}