#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 */
typedef int uint16_t;
struct winsize {
  int ws_col;
  int ws_row;
};

/* Variables and functions */
int /*<<< orphan*/ TIOCGWINSZ;
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int /*<<< orphan*/, int /*<<< orphan*/,
                         struct winsize *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int check_terminal_size(void) {
  uint16_t ncols = 0;
  uint16_t nrows = 0;
  struct winsize winsz;
  ioctl(fileno(stdin), TIOCGWINSZ, &winsz);
  ncols = winsz.ws_col;
  nrows = winsz.ws_row;
  if (ncols < 80 || nrows < 25) {
    printf("Your window is not large enough.\n");
    printf("It must be at least %ux%u, but yours is %ux%u\n", 80, 25, ncols,
           nrows);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_terminal_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
mov    %eax,%edi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x50,-0x8(%rbp)
jl     1188 <check_terminal_size+0x58>
cmpl   $0x19,-0xc(%rbp)
jge    11c1 <check_terminal_size+0x91>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
lea    0xe7e(%rip),%rdi
mov    $0x50,%esi
mov    $0x19,%edx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <check_terminal_size+0x98>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_terminal_size>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    0x2e78(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1050 <ioctl@plt>
mov    (%rsp),%ebx
mov    0x4(%rsp),%ebp
cmp    $0x50,%ebx
jl     1177 <check_terminal_size+0x37>
xor    %eax,%eax
cmp    $0x18,%ebp
jg     11a5 <check_terminal_size+0x65>
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
lea    0xe76(%rip),%rdi
mov    $0x50,%esi
mov    $0x19,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.winsize = type { i32, i32 }
@stdin = global i32 0
@TIOCGWINSZ = global i32 0
@.str = [34 x i8] c"Your window is not large enough.\0A\00"
@.str.1 = [47 x i8] c"It must be at least %ux%u, but yours is %ux%u\0A\00"
define i32 @check_terminal_size() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.winsize
store i32 0, i32* %2
store i32 0, i32* %3
%5 = load i32, i32* @stdin
%6 = call i32 @fileno(i32 %5)
%7 = load i32, i32* @TIOCGWINSZ
%8 = call i32 @ioctl(i32 %6, i32 %7, %struct.winsize* %4)
%9 = getelementptr inbounds %struct.winsize, %struct.winsize* %4, i32 0, i32 0
%10 = load i32, i32* %9
store i32 %10, i32* %2
%11 = getelementptr inbounds %struct.winsize, %struct.winsize* %4, i32 0, i32 1
%12 = load i32, i32* %11
store i32 %12, i32* %3
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 80
br i1 %14, label %18, label %15
15: ; preds = %0
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 25
br i1 %17, label %18, label %23
18: ; preds = %15, %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 80, i32 25, i32 %20, i32 %21)
store i32 -1, i32* %1
br label %24
23: ; preds = %15
store i32 0, i32* %1
br label %24
24: ; preds = %23, %18
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
%struct.winsize = type { i32, i32 }
@stdin = global i32 0
@TIOCGWINSZ = global i32 0
@.str.1 = [47 x i8] c"It must be at least %ux%u, but yours is %ux%u\0A\00"
@str = [33 x i8] c"Your window is not large enough.\00"
define i32 @check_terminal_size() {
%1 = alloca %struct.winsize
%2 = bitcast %struct.winsize* %1 to i8*
%3 = load i32, i32* @stdin
%4 = tail call i32 @fileno(i32 %3)
%5 = load i32, i32* @TIOCGWINSZ
%6 = call i32 @ioctl(i32 %4, i32 %5, %struct.winsize* %1)
%7 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i64 0, i32 0
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i64 0, i32 1
%10 = load i32, i32* %9
%11 = icmp slt i32 %8, 80
%12 = icmp slt i32 %10, 25
%13 = select i1 %11, i1 true, i1 %12
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 80, i32 25, i32 %8, i32 %10)
br label %17
17: ; preds = %0, %14
%18 = phi i32 [ -1, %14 ], [ 0, %0 ]
ret i32 %18
}