#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*/ echo_off();
int /*<<< orphan*/ echo_on();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main() {
  char buf[10];
  char *p = buf;
  char c;
  echo_off();
  write(0, "\x1b[6n", 4);
  for (int i = 0;; i++) {
    read(0, &c, 1);
    if (c >= 0x30 && c <= 0x39)
      *p++ = c;
    if (c == ';')
      *p++ = ' ';
    if (c == 'R')
      break;
  }
  *p = '\0';
  echo_on();
  printf("%s\n", buf);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xe(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1070 <echo_off@plt>
xor    %edi,%edi
lea    0xe89(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
movl   $0x0,-0x20(%rbp)
xor    %edi,%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl -0x19(%rbp),%eax
cmp    $0x30,%eax
jl     11c6 <main+0x76>
movsbl -0x19(%rbp),%eax
cmp    $0x39,%eax
jg     11c6 <main+0x76>
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
movsbl -0x19(%rbp),%eax
cmp    $0x3b,%eax
jne    11e5 <main+0x95>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x20,(%rax)
movsbl -0x19(%rbp),%eax
cmp    $0x52,%eax
jne    11f7 <main+0xa7>
jmp    120a <main+0xba>
jmp    11fc <main+0xac>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1188 <main+0x38>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x0,%al
call   1040 <echo_on@plt>
lea    -0xe(%rbp),%rsi
lea    0xde2(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe(%rsp),%rbx
xor    %eax,%eax
call   1070 <echo_off@plt>
lea    0xe96(%rip),%rsi
xor    %edi,%edi
mov    $0x4,%edx
call   1030 <write@plt>
lea    0xd(%rsp),%r14
jmp    1184 <main+0x34>
nopl   (%rax)
cmp    $0x52,%al
je     11cd <main+0x7d>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movzbl 0xd(%rsp),%eax
lea    -0x30(%rax),%ecx
cmp    $0x9,%cl
jbe    11b0 <main+0x60>
cmp    $0x3b,%al
jne    1180 <main+0x30>
jmp    11bf <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
mov    %al,(%rbx)
add    $0x1,%rbx
movzbl 0xd(%rsp),%eax
cmp    $0x3b,%al
jne    1180 <main+0x30>
movb   $0x20,(%rbx)
add    $0x1,%rbx
movzbl 0xd(%rsp),%eax
jmp    1180 <main+0x30>
movb   $0x0,(%rbx)
xor    %eax,%eax
call   1040 <echo_on@plt>
lea    0xe27(%rip),%rdi
lea    0xe(%rsp),%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\1B[6n\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
store i8* %6, i8** %3
%7 = call i32 (...) @echo_off()
%8 = call i32 @write(i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
store i32 0, i32* %5
br label %9
9: ; preds = %35, %0
%10 = call i32 @read(i32 0, i8* %4, i32 1)
%11 = load i8, i8* %4
%12 = sext i8 %11 to i32
%13 = icmp sge i32 %12, 48
br i1 %13, label %14, label %22
14: ; preds = %9
%15 = load i8, i8* %4
%16 = sext i8 %15 to i32
%17 = icmp sle i32 %16, 57
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i8, i8* %4
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %3
store i8 %19, i8* %20
br label %22
22: ; preds = %18, %14, %9
%23 = load i8, i8* %4
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 59
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %3
store i8 32, i8* %27
br label %29
29: ; preds = %26, %22
%30 = load i8, i8* %4
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 82
br i1 %32, label %33, label %34
33: ; preds = %29
br label %38
34: ; preds = %29
br label %35
35: ; preds = %34
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %9
38: ; preds = %33
%39 = load i8*, i8** %3
store i8 0, i8* %39
%40 = call i32 (...) @echo_on()
%41 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@.str = [5 x i8] c"\1B[6n\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%4 = tail call i32 (...) @echo_off()
%5 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
br label %6
6: ; preds = %22, %0
%7 = phi i8* [ %3, %0 ], [ %24, %22 ]
%8 = call i32 @read(i32 0, i8* %2, i32 1)
%9 = load i8, i8* %2
%10 = add i8 %9, -48
%11 = icmp ult i8 %10, 10
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %9, i8* %7
%14 = load i8, i8* %2
br label %15
15: ; preds = %12, %6
%16 = phi i8 [ %14, %12 ], [ %9, %6 ]
%17 = phi i8* [ %13, %12 ], [ %7, %6 ]
%18 = icmp eq i8 %16, 59
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = getelementptr inbounds i8, i8* %17, i64 1
store i8 32, i8* %17
%21 = load i8, i8* %2
br label %22
22: ; preds = %19, %15
%23 = phi i8 [ %21, %19 ], [ %16, %15 ]
%24 = phi i8* [ %20, %19 ], [ %17, %15 ]
%25 = icmp eq i8 %23, 82
br i1 %25, label %26, label %6
26: ; preds = %22
store i8 0, i8* %24
%27 = tail call i32 (...) @echo_on()
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %3)
ret i32 0
}