#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*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
char *read_dcs();
int sscanf(char *, char *, int *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int query_rqss_numeric(char *cmd) {
  printf("\x1bP$q%s\x1b\\", cmd);
  char *s = NULL;
  do {
    if (s)
      free(s);
    s = read_dcs();
    if (!s)
      return -1;
    if (strlen(s) < strlen(cmd))
      return -1;
    if (strcmp(s + strlen(s) - strlen(cmd), cmd) != 0) {
      printf("No match\n");
      continue;
    }
    if (s[0] != '1' || s[1] != '$' || s[2] != 'r')
      return -1;
    int num;
    if (sscanf(s + 3, "%d", &num) != 1)
      return -1;
    return num;
  } while (1);
}


x86 assembly (clang, -O0):
<query_rqss_numeric>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119a <query_rqss_numeric+0x3a>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1040 <read_dcs@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bc <query_rqss_numeric+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ce <query_rqss_numeric+0x16e>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11ea <query_rqss_numeric+0x8a>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ce <query_rqss_numeric+0x16e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
movslq %eax,%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1249 <query_rqss_numeric+0xe9>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12bf <query_rqss_numeric+0x15f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x31,%eax
jne    127b <query_rqss_numeric+0x11b>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x24,%eax
jne    127b <query_rqss_numeric+0x11b>
mov    -0x18(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x72,%eax
je     1287 <query_rqss_numeric+0x127>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ce <query_rqss_numeric+0x16e>
mov    -0x18(%rbp),%rdi
add    $0x3,%rdi
lea    0xd7d(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
je     12b4 <query_rqss_numeric+0x154>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ce <query_rqss_numeric+0x16e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12ce <query_rqss_numeric+0x16e>
mov    $0x1,%al
test   $0x1,%al
jne    1186 <query_rqss_numeric+0x26>
jmp    12ce <query_rqss_numeric+0x16e>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<query_rqss_numeric>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xe7a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe75(%rip),%r15
xor    %ebx,%ebx
mov    $0xffffffff,%r12d
test   %rbx,%rbx
je     11b8 <query_rqss_numeric+0x48>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1040 <read_dcs@plt>
test   %rax,%rax
je     1254 <query_rqss_numeric+0xe4>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <strlen@plt>
cmp    %eax,%ebp
jl     1254 <query_rqss_numeric+0xe4>
mov    %rbx,%rdi
call   1060 <strlen@plt>
movslq %eax,%rbp
add    %rbx,%rbp
mov    %r14,%rdi
call   1060 <strlen@plt>
cltq
sub    %rax,%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     121b <query_rqss_numeric+0xab>
mov    %r15,%rdi
call   1050 <puts@plt>
test   %rbx,%rbx
jne    11b0 <query_rqss_numeric+0x40>
jmp    11b8 <query_rqss_numeric+0x48>
cmpb   $0x31,(%rbx)
jne    1254 <query_rqss_numeric+0xe4>
cmpb   $0x24,0x1(%rbx)
jne    1254 <query_rqss_numeric+0xe4>
cmpb   $0x72,0x2(%rbx)
jne    1254 <query_rqss_numeric+0xe4>
add    $0x3,%rbx
lea    0xdd2(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1090 <sscanf@plt>
mov    $0xffffffff,%r12d
cmp    $0x1,%eax
jne    1254 <query_rqss_numeric+0xe4>
mov    0xc(%rsp),%r12d
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"\1BP$q%s\1B\\\00"
@.str.1 = [10 x i8] c"No match\0A\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @query_rqss_numeric(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %6)
store i8* null, i8** %4
br label %8
8: ; preds = %69, %1
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i8*, i8** %4
%13 = call i32 @free(i8* %12)
br label %14
14: ; preds = %11, %8
%15 = call i8* (...) @read_dcs()
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %14
store i32 -1, i32* %2
br label %70
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
%22 = load i8*, i8** %3
%23 = call i32 @strlen(i8* %22)
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %26
25: ; preds = %19
store i32 -1, i32* %2
br label %70
26: ; preds = %19
%27 = load i8*, i8** %4
%28 = load i8*, i8** %4
%29 = call i32 @strlen(i8* %28)
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = load i8*, i8** %3
%33 = call i32 @strlen(i8* %32)
%34 = sext i32 %33 to i64
%35 = sub i64 0, %34
%36 = getelementptr inbounds i8, i8* %31, i64 %35
%37 = load i8*, i8** %3
%38 = call i64 @strcmp(i8* %36, i8* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %26
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %69
42: ; preds = %26
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i64 0
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 49
br i1 %47, label %60, label %48
48: ; preds = %42
%49 = load i8*, i8** %4
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 36
br i1 %53, label %60, label %54
54: ; preds = %48
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i64 2
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp ne i32 %58, 114
br i1 %59, label %60, label %61
60: ; preds = %54, %48, %42
store i32 -1, i32* %2
br label %70
61: ; preds = %54
%62 = load i8*, i8** %4
%63 = getelementptr inbounds i8, i8* %62, i64 3
%64 = call i32 @sscanf(i8* %63, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%65 = icmp ne i32 %64, 1
br i1 %65, label %66, label %67
66: ; preds = %61
store i32 -1, i32* %2
br label %70
67: ; preds = %61
%68 = load i32, i32* %5
store i32 %68, i32* %2
br label %70
69: ; preds = %40
br i1 true, label %8, label %70
70: ; preds = %18, %25, %60, %66, %67, %69
%71 = load i32, i32* %2
ret i32 %71
}

LLVM IR (-O2):
@.str = [9 x i8] c"\1BP$q%s\1B\\\00"
@.str.2 = [3 x i8] c"%d\00"
@str = [9 x i8] c"No match\00"
define i32 @query_rqss_numeric(i8* %0) {
%2 = alloca i32
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %4
4: ; preds = %26, %1
%5 = phi i8* [ null, %1 ], [ %10, %26 ]
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @free(i8* %5)
br label %9
9: ; preds = %7, %4
%10 = tail call i8* (...) @read_dcs()
%11 = icmp eq i8* %10, null
br i1 %11, label %46, label %12
12: ; preds = %9
%13 = tail call i32 @strlen(i8* %10)
%14 = tail call i32 @strlen(i8* %0)
%15 = icmp slt i32 %13, %14
br i1 %15, label %46, label %16
16: ; preds = %12
%17 = tail call i32 @strlen(i8* %10)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %10, i64 %18
%20 = tail call i32 @strlen(i8* %0)
%21 = sext i32 %20 to i64
%22 = sub nsw i64 0, %21
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = tail call i64 @strcmp(i8* %23, i8* %0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %16
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %4
28: ; preds = %16
%29 = load i8, i8* %10
%30 = icmp eq i8 %29, 49
br i1 %30, label %31, label %46
31: ; preds = %28
%32 = getelementptr inbounds i8, i8* %10, i64 1
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 36
br i1 %34, label %35, label %46
35: ; preds = %31
%36 = getelementptr inbounds i8, i8* %10, i64 2
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 114
br i1 %38, label %39, label %46
39: ; preds = %35
%40 = bitcast i32* %2 to i8*
%41 = getelementptr inbounds i8, i8* %10, i64 3
%42 = call i32 @sscanf(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%43 = icmp eq i32 %42, 1
%44 = load i32, i32* %2
%45 = select i1 %43, i32 %44, i32 -1
br label %46
46: ; preds = %12, %9, %28, %31, %35, %39
%47 = phi i32 [ %45, %39 ], [ -1, %35 ], [ -1, %31 ], [ -1, %28 ], [ -1, %9 ], [ -1, %12 ]
ret i32 %47
}