#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*/ console_getpos(int *, int *);
int /*<<< orphan*/ console_setpos(int, int);
int /*<<< orphan*/ printf(char *, int);
void console_getsize(int *cols_p, int *rows_p) {
  int old = -1, rows, cols;
  int row, col;
  console_getpos(&col, &row);
  rows = row;
  cols = col;
  while (rows + cols != old) {
    printf("%c[99C", 0x1B);
    printf("%c[99B", 0x1B);
    old = rows + cols;
    console_getpos(&cols, &rows);
  }
  console_setpos(col, row);
  if (cols_p) {
    *cols_p = cols + 1;
  }
  if (rows_p) {
    *rows_p = rows + 1;
  }
}


x86 assembly (clang, -O0):
<console_getsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
lea    -0x24(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <console_getpos@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11ac <console_getsize+0x7c>
lea    0xe8a(%rip),%rdi
mov    $0x1b,%esi
call   1040 <printf@plt>
lea    0xe80(%rip),%rdi
mov    $0x1b,%esi
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0x1c(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <console_getpos@plt>
jmp    1160 <console_getsize+0x30>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1050 <console_setpos@plt>
cmpq   $0x0,-0x8(%rbp)
je     11ce <console_getsize+0x9e>
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     11e5 <console_getsize+0xb5>
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<console_getsize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x8(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1030 <console_getpos@plt>
mov    0xc(%rsp),%esi
mov    %esi,0x4(%rsp)
mov    0x8(%rsp),%edi
mov    %edi,(%rsp)
lea    (%rdi,%rsi,1),%eax
cmp    $0xffffffff,%eax
je     11d7 <console_getsize+0xa7>
mov    %rbx,0x10(%rsp)
lea    0xe8a(%rip),%r12
lea    0xe8a(%rip),%r13
mov    %rsp,%rbx
lea    0x4(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    $0x1b,%esi
call   1040 <printf@plt>
mov    %r13,%rdi
mov    $0x1b,%esi
call   1040 <printf@plt>
mov    (%rsp),%r14d
add    0x4(%rsp),%r14d
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <console_getpos@plt>
mov    (%rsp),%eax
add    0x4(%rsp),%eax
cmp    %r14d,%eax
jne    1190 <console_getsize+0x60>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%rbx
call   1050 <console_setpos@plt>
test   %r15,%r15
je     11ea <console_getsize+0xba>
mov    (%rsp),%eax
add    $0x1,%eax
mov    %eax,(%r15)
test   %rbx,%rbx
je     11f8 <console_getsize+0xc8>
mov    0x4(%rsp),%eax
add    $0x1,%eax
mov    %eax,(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%c[99C\00"
@.str.1 = [7 x i8] c"%c[99B\00"
define void @console_getsize(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 -1, i32* %5
%10 = call i32 @console_getpos(i32* %9, i32* %8)
%11 = load i32, i32* %8
store i32 %11, i32* %6
%12 = load i32, i32* %9
store i32 %12, i32* %7
br label %13
13: ; preds = %19, %2
%14 = load i32, i32* %6
%15 = load i32, i32* %7
%16 = add nsw i32 %14, %15
%17 = load i32, i32* %5
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %26
19: ; preds = %13
%20 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 27)
%21 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 27)
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = add nsw i32 %22, %23
store i32 %24, i32* %5
%25 = call i32 @console_getpos(i32* %7, i32* %6)
br label %13
26: ; preds = %13
%27 = load i32, i32* %9
%28 = load i32, i32* %8
%29 = call i32 @console_setpos(i32 %27, i32 %28)
%30 = load i32*, i32** %3
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
%35 = load i32*, i32** %3
store i32 %34, i32* %35
br label %36
36: ; preds = %32, %26
%37 = load i32*, i32** %4
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
%42 = load i32*, i32** %4
store i32 %41, i32* %42
br label %43
43: ; preds = %39, %36
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%c[99C\00"
@.str.1 = [7 x i8] c"%c[99B\00"
define void @console_getsize(i32* writeonly %0, i32* writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = call i32 @console_getpos(i32* %6, i32* %5)
%12 = load i32, i32* %5
store i32 %12, i32* %3
%13 = load i32, i32* %6
store i32 %13, i32* %4
%14 = add nsw i32 %13, %12
%15 = icmp eq i32 %14, -1
br i1 %15, label %30, label %16
16: ; preds = %2, %16
%17 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 27)
%18 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 27)
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = add nsw i32 %20, %19
%22 = call i32 @console_getpos(i32* %4, i32* %3)
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = add nsw i32 %24, %23
%26 = icmp eq i32 %25, %21
br i1 %26, label %27, label %16
27: ; preds = %16
%28 = load i32, i32* %6
%29 = load i32, i32* %5
br label %30
30: ; preds = %27, %2
%31 = phi i32 [ %29, %27 ], [ %12, %2 ]
%32 = phi i32 [ %28, %27 ], [ %13, %2 ]
%33 = call i32 @console_setpos(i32 %32, i32 %31)
%34 = icmp eq i32* %0, null
br i1 %34, label %38, label %35
35: ; preds = %30
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %0
br label %38
38: ; preds = %35, %30
%39 = icmp eq i32* %1, null
br i1 %39, label %43, label %40
40: ; preds = %38
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
store i32 %42, i32* %1
br label %43
43: ; preds = %40, %38
ret void
}