#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_col;
  int ws_row;
};

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TIOCGWINSZ;
int ioctl(int /*<<< orphan*/, int /*<<< orphan*/, struct winsize *);
int /*<<< orphan*/ memset(struct winsize *, int /*<<< orphan*/, int);
void get_terminal_size(int *w, int *h) {
  (*w) = 80;
  (*h) = 24;
  struct winsize ws;
  memset(&ws, 0, sizeof(struct winsize));
  if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) {
    return;
  }
  (*w) = ws.ws_col;
  (*h) = ws.ws_row;
}


x86 assembly (clang, -O0):
<get_terminal_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x50,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x18,(%rax)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    117d <get_terminal_size+0x5d>
jmp    118f <get_terminal_size+0x6f>
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_terminal_size>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x50,(%rdi)
movl   $0x18,(%rsi)
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     117b <get_terminal_size+0x5b>
mov    0x8(%rsp),%eax
mov    %eax,(%rbx)
mov    0xc(%rsp),%eax
mov    %eax,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.winsize = type { i32, i32 }
@STDIN_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
define void @get_terminal_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** %3
store i32 80, i32* %6
%7 = load i32*, i32** %4
store i32 24, i32* %7
%8 = call i32 @memset(%struct.winsize* %5, i32 0, i32 8)
%9 = load i32, i32* @STDIN_FILENO
%10 = load i32, i32* @TIOCGWINSZ
%11 = call i32 @ioctl(i32 %9, i32 %10, %struct.winsize* %5)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %2
br label %21
14: ; preds = %2
%15 = getelementptr inbounds %struct.winsize, %struct.winsize* %5, i32 0, i32 0
%16 = load i32, i32* %15
%17 = load i32*, i32** %3
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.winsize, %struct.winsize* %5, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load i32*, i32** %4
store i32 %19, i32* %20
br label %21
21: ; preds = %14, %13
ret void
}

LLVM IR (-O2):
%struct.winsize = type { i32, i32 }
@STDIN_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
define void @get_terminal_size(i32* nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = alloca %struct.winsize
store i32 80, i32* %0
store i32 24, i32* %1
%4 = bitcast %struct.winsize* %3 to i8*
%5 = call i32 @memset(%struct.winsize* %3, i32 0, i32 8)
%6 = load i32, i32* @STDIN_FILENO
%7 = load i32, i32* @TIOCGWINSZ
%8 = call i32 @ioctl(i32 %6, i32 %7, %struct.winsize* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 0
%12 = load i32, i32* %11
store i32 %12, i32* %0
%13 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 1
%14 = load i32, i32* %13
store i32 %14, i32* %1
br label %15
15: ; preds = %2, %10
ret void
}