#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*/ mfm_drain_input();
int /*<<< orphan*/ printf(char *, char *);
int read(int /*<<< orphan*/, char *, int);
void mfm_scr_size(int *h, int *w) {
  *h = 0;
  *w = 0;
  mfm_drain_input();
  printf("%s", "\e[1000;5000H\e[6n");
  int *t = h, res;
  for (char c = '\0'; c != 'R'; res = read(0, &c, 1)) {
    if (c == ';') {
      t = w;
    } else if (c >= '0' && c <= '9') {
      *t = *t * 10 + c - 48;
    }
  }
  mfm_drain_input();
}


x86 assembly (clang, -O0):
<mfm_scr_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    $0x0,%al
call   1050 <mfm_drain_input@plt>
lea    0xe9e(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0x52,%eax
je     11f3 <mfm_scr_size+0xc3>
movsbl -0x1d(%rbp),%eax
cmp    $0x3b,%eax
jne    11a1 <mfm_scr_size+0x71>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11d6 <mfm_scr_size+0xa6>
movsbl -0x1d(%rbp),%eax
cmp    $0x30,%eax
jl     11d1 <mfm_scr_size+0xa1>
movsbl -0x1d(%rbp),%eax
cmp    $0x39,%eax
jg     11d1 <mfm_scr_size+0xa1>
mov    -0x18(%rbp),%rax
imul   $0xa,(%rax),%ecx
movsbl -0x1d(%rbp),%eax
add    %eax,%ecx
sub    $0x30,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11d6 <mfm_scr_size+0xa6>
jmp    11db <mfm_scr_size+0xab>
xor    %edi,%edi
lea    -0x1d(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
jmp    117a <mfm_scr_size+0x4a>
mov    $0x0,%al
call   1050 <mfm_drain_input@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mfm_scr_size>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
movl   $0x0,(%rdi)
movl   $0x0,(%rsi)
xor    %r13d,%r13d
xor    %eax,%eax
call   1050 <mfm_drain_input@plt>
lea    0xea0(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1030 <printf@plt>
movb   $0x0,0xf(%rsp)
lea    0xf(%rsp),%r15
jmp    119b <mfm_scr_size+0x6b>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rbx
xor    %edi,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
movzbl 0xf(%rsp),%r13d
mov    %rbx,%r12
mov    %r14,%rbx
cmp    $0x3b,%r13b
je     1183 <mfm_scr_size+0x53>
cmp    $0x52,%r13b
je     11c9 <mfm_scr_size+0x99>
lea    -0x30(%r13),%eax
cmp    $0x9,%al
ja     1180 <mfm_scr_size+0x50>
movsbl %r13b,%eax
mov    (%r12),%ecx
lea    (%rcx,%rcx,4),%ecx
lea    (%rax,%rcx,2),%eax
add    $0xffffffd0,%eax
mov    %eax,(%r12)
jmp    1180 <mfm_scr_size+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <mfm_drain_input@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [17 x i8] c"\1B[1000;5000H\1B[6n\00"
define void @mfm_scr_size(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca i8
store i32 0, i32* %0
store i32 0, i32* %1
%4 = tail call i32 (...) @mfm_drain_input()
%5 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i8 0, i8* %3
br label %6
6: ; preds = %20, %2
%7 = phi i8 [ %23, %20 ], [ 0, %2 ]
%8 = phi i32* [ %21, %20 ], [ %0, %2 ]
%9 = sext i8 %7 to i32
switch i8 %7, label %12 [
i8 82, label %10
i8 59, label %20
]
10: ; preds = %6
%11 = tail call i32 (...) @mfm_drain_input()
ret void
12: ; preds = %6
%13 = add i8 %7, -48
%14 = icmp ult i8 %13, 10
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* %8
%17 = mul nsw i32 %16, 10
%18 = add nsw i32 %9, -48
%19 = add i32 %18, %17
store i32 %19, i32* %8
br label %20
20: ; preds = %6, %15, %12
%21 = phi i32* [ %8, %15 ], [ %8, %12 ], [ %1, %6 ]
%22 = call i32 @read(i32 0, i8* %3, i32 1)
%23 = load i8, i8* %3
br label %6
}