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

/* Variables and functions */
int /*<<< orphan*/ await_c1(int);
char getchar();
char *strdup(char *);
char *read_csi() {
  await_c1(0x9B);
  char csi[32];
  int i = 0;
  for (; i < sizeof(csi) - 1; i++) {
    char c = csi[i] = getchar();
    if (c >= 0x40 && c <= 0x7e)
      break;
  }
  csi[++i] = 0;
  return strdup(csi);
}


x86 assembly (clang, -O0):
<read_csi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x9b,%edi
call   1050 <await_c1@plt>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0x1f,%rax
jae    119b <read_csi+0x6b>
mov    $0x0,%al
call   1030 <getchar@plt>
movslq -0x24(%rbp),%rcx
mov    %al,-0x20(%rbp,%rcx,1)
mov    %al,-0x25(%rbp)
movsbl -0x25(%rbp),%eax
cmp    $0x40,%eax
jl     1188 <read_csi+0x58>
movsbl -0x25(%rbp),%eax
cmp    $0x7e,%eax
jg     1188 <read_csi+0x58>
jmp    119b <read_csi+0x6b>
jmp    118d <read_csi+0x5d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1149 <read_csi+0x19>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cltq
movb   $0x0,-0x20(%rbp,%rax,1)
lea    -0x20(%rbp),%rdi
call   1040 <strdup@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_csi>:
push   %rbx
sub    $0x20,%rsp
mov    $0x9b,%edi
call   1050 <await_c1@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %al,(%rsp,%rbx,1)
add    $0xc0,%al
cmp    $0x3f,%al
jb     116f <read_csi+0x3f>
add    $0x1,%rbx
cmp    $0x1f,%rbx
jne    1150 <read_csi+0x20>
mov    $0x1f,%ebx
add    $0x1,%ebx
movb   $0x0,(%rsp,%rbx,1)
mov    %rsp,%rdi
call   1040 <strdup@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i8* @read_csi() {
%1 = alloca [32 x i8]
%2 = alloca i32
%3 = alloca i8
%4 = call i32 @await_c1(i32 155)
store i32 0, i32* %2
br label %5
5: ; preds = %23, %0
%6 = load i32, i32* %2
%7 = sext i32 %6 to i64
%8 = icmp ult i64 %7, 31
br i1 %8, label %9, label %26
9: ; preds = %5
%10 = call signext i8 (...) @getchar()
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 %12
store i8 %10, i8* %13
store i8 %10, i8* %3
%14 = load i8, i8* %3
%15 = sext i8 %14 to i32
%16 = icmp sge i32 %15, 64
br i1 %16, label %17, label %22
17: ; preds = %9
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = icmp sle i32 %19, 126
br i1 %20, label %21, label %22
21: ; preds = %17
br label %26
22: ; preds = %17, %9
br label %23
23: ; preds = %22
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 1
store i32 %25, i32* %2
br label %5
26: ; preds = %21, %5
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 %29
store i8 0, i8* %30
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%32 = call i8* @strdup(i8* %31)
ret i8* %32
}

LLVM IR (-O2):
define noalias i8* @read_csi() {
%1 = alloca [32 x i8]
%2 = tail call i32 @await_c1(i32 155)
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
br label %4
4: ; preds = %0, %10
%5 = phi i64 [ 0, %0 ], [ %11, %10 ]
%6 = tail call signext i8 (...) @getchar()
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 %5
store i8 %6, i8* %7
%8 = add i8 %6, -64
%9 = icmp ult i8 %8, 63
br i1 %9, label %13, label %10
10: ; preds = %4
%11 = add nuw nsw i64 %5, 1
%12 = icmp eq i64 %11, 31
br i1 %12, label %13, label %4
13: ; preds = %4, %10
%14 = phi i64 [ %5, %4 ], [ 31, %10 ]
%15 = add nuw i64 %14, 1
%16 = and i64 %15, 4294967295
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 %16
store i8 0, i8* %17
%18 = call i8* @strdup(i8* %3)
ret i8* %18
}