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

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ TIOCGWINSZ;
int /*<<< orphan*/ exit(int);
scalar_t__ ioctl(int /*<<< orphan*/, int /*<<< orphan*/, struct winsize *);
int /*<<< orphan*/ perror(char *);
bool get_window_size(int *rows, int *cols) {
  struct winsize ws;
  if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) != 0) {
    perror("Failed to query terminal size");
    exit(1);
  }
  *rows = ws.ws_row;
  *cols = ws.ws_col;
  return true;
}


x86 assembly (clang, -O0):
<get_window_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
je     117b <get_window_size+0x4b>
lea    0xe94(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_window_size>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2eaf(%rip),%rax
mov    (%rax),%edi
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
jne    1172 <get_window_size+0x42>
mov    (%rsp),%eax
mov    %eax,(%rbx)
mov    0x4(%rsp),%eax
mov    %eax,(%r14)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe87(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.winsize = type { i32, i32 }
@STDOUT_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
@.str = [30 x i8] c"Failed to query terminal size\00"
define i32 @get_window_size(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca %struct.winsize
store i32* %0, i32** %3
store i32* %1, i32** %4
%6 = load i32, i32* @STDOUT_FILENO
%7 = load i32, i32* @TIOCGWINSZ
%8 = call i64 @ioctl(i32 %6, i32 %7, %struct.winsize* %5)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds %struct.winsize, %struct.winsize* %5, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i32*, i32** %3
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.winsize, %struct.winsize* %5, i32 0, i32 1
%18 = load i32, i32* %17
%19 = load i32*, i32** %4
store i32 %18, i32* %19
ret i32 1
}

LLVM IR (-O2):
%struct.winsize = type { i32, i32 }
@STDOUT_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
@.str = [30 x i8] c"Failed to query terminal size\00"
define i32 @get_window_size(i32* nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = alloca %struct.winsize
%4 = bitcast %struct.winsize* %3 to i8*
%5 = load i32, i32* @STDOUT_FILENO
%6 = load i32, i32* @TIOCGWINSZ
%7 = call i64 @ioctl(i32 %5, i32 %6, %struct.winsize* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 0
%14 = load i32, i32* %13
store i32 %14, i32* %0
%15 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 1
%16 = load i32, i32* %15
store i32 %16, i32* %1
ret i32 1
}