#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*/ do_csi(char *);
int /*<<< orphan*/ el(int);
char *get_reply();
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ restore_ttymodes();
int /*<<< orphan*/ set_tty_echo(int /*<<< orphan*/);
int /*<<< orphan*/ set_tty_raw(int);
char *skip_csi(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ vt_move(int, int);
void check_rc(int row, int col) {
  char *report;
  char *params;
  char expected[80];
  sprintf(expected, "%d;%dR", row, col);
  set_tty_raw((1));
  set_tty_echo((0));
  do_csi("6n");
  report = get_reply();
  restore_ttymodes();
  vt_move(row, 1);
  el(2);
  if ((params = skip_csi(report)) == 0 || strcmp(params, expected) != 0) {
    printf("cursor save/restore %s, got \"%s\", expected \"%s\"", "failed",
           params, expected);
  } else {
    printf("cursor save/restore %s", "ok");
  }
}


x86 assembly (clang, -O0):
<check_rc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe31(%rip),%rsi
call   10d0 <sprintf@plt>
mov    $0x1,%edi
call   10a0 <set_tty_raw@plt>
xor    %edi,%edi
call   10c0 <set_tty_echo@plt>
lea    0xe1b(%rip),%rdi
call   10b0 <do_csi@plt>
mov    $0x0,%al
call   1050 <get_reply@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <restore_ttymodes@plt>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1070 <vt_move@plt>
mov    $0x2,%edi
call   1090 <el@plt>
mov    -0x10(%rbp),%rdi
call   1040 <skip_csi@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1248 <check_rc+0x98>
mov    -0x18(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     126a <check_rc+0xba>
mov    -0x18(%rbp),%rdx
lea    -0x70(%rbp),%rcx
lea    0xdb3(%rip),%rdi
lea    0xddc(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    127f <check_rc+0xcf>
lea    0xdd0(%rip),%rdi
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_rc>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %esi,%ecx
mov    %edi,%ebx
lea    0xe3e(%rip),%rsi
mov    %rsp,%rdi
mov    %ebx,%edx
call   10d0 <sprintf@plt>
mov    $0x1,%edi
call   10a0 <set_tty_raw@plt>
xor    %edi,%edi
call   10c0 <set_tty_echo@plt>
lea    0xe23(%rip),%rdi
call   10b0 <do_csi@plt>
xor    %eax,%eax
call   1050 <get_reply@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <restore_ttymodes@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1070 <vt_move@plt>
mov    $0x2,%edi
call   1090 <el@plt>
mov    %r14,%rdi
call   1040 <skip_csi@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1230 <check_rc+0x80>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     124d <check_rc+0x9d>
lea    0xdd3(%rip),%rdi
lea    0xdfc(%rip),%rsi
mov    %rsp,%rcx
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1262 <check_rc+0xb2>
lea    0xded(%rip),%rdi
lea    0xdfd(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d;%dR\00"
@.str.1 = [3 x i8] c"6n\00"
@.str.2 = [48 x i8] c"cursor save/restore %s, got \22%s\22, expected \22%s\22\00"
@.str.3 = [7 x i8] c"failed\00"
@.str.4 = [23 x i8] c"cursor save/restore %s\00"
@.str.5 = [3 x i8] c"ok\00"
define void @check_rc(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [80 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
%12 = call i32 @set_tty_raw(i32 1)
%13 = call i32 @set_tty_echo(i32 0)
%14 = call i32 @do_csi(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = call i8* (...) @get_reply()
store i8* %15, i8** %5
%16 = call i32 (...) @restore_ttymodes()
%17 = load i32, i32* %3
%18 = call i32 @vt_move(i32 %17, i32 1)
%19 = call i32 @el(i32 2)
%20 = load i8*, i8** %5
%21 = call i8* @skip_csi(i8* %20)
store i8* %21, i8** %6
%22 = icmp eq i8* %21, null
br i1 %22, label %28, label %23
23: ; preds = %2
%24 = load i8*, i8** %6
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%26 = call i64 @strcmp(i8* %24, i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23, %2
%29 = load i8*, i8** %6
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%31 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %29, i8* %30)
br label %34
32: ; preds = %23
%33 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d;%dR\00"
@.str.1 = [3 x i8] c"6n\00"
@.str.2 = [48 x i8] c"cursor save/restore %s, got \22%s\22, expected \22%s\22\00"
@.str.3 = [7 x i8] c"failed\00"
@.str.4 = [23 x i8] c"cursor save/restore %s\00"
@.str.5 = [3 x i8] c"ok\00"
define void @check_rc(i32 %0, i32 %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
%6 = tail call i32 @set_tty_raw(i32 1)
%7 = tail call i32 @set_tty_echo(i32 0)
%8 = tail call i32 @do_csi(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i8* (...) @get_reply()
%10 = tail call i32 (...) @restore_ttymodes()
%11 = tail call i32 @vt_move(i32 %0, i32 1)
%12 = tail call i32 @el(i32 2)
%13 = tail call i8* @skip_csi(i8* %9)
%14 = icmp eq i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = call i64 @strcmp(i8* %13, i8* %4)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15, %2
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %13, i8* %4)
br label %22
20: ; preds = %15
%21 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
ret void
}