#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;
scalar_t__ ioctl(int /*<<< orphan*/, int /*<<< orphan*/, struct winsize *);
int term_get_window_size(int *width, int *height) {
  struct winsize term_size;
  if (ioctl(STDIN_FILENO, TIOCGWINSZ, &term_size) < 0)
    return -1;
  *width = term_size.ws_col;
  *height = term_size.ws_row;
  return 0;
}


x86 assembly (clang, -O0):
<term_get_window_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2eb9(%rip),%rax
mov    (%rax),%edi
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1151 <term_get_window_size+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    116a <term_get_window_size+0x5a>
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<term_get_window_size>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2ebf(%rip),%rax
mov    (%rax),%edi
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
js     1149 <term_get_window_size+0x39>
mov    (%rsp),%eax
mov    %eax,(%rbx)
mov    0x4(%rsp),%eax
mov    %eax,(%r14)
xor    %eax,%eax
jmp    114e <term_get_window_size+0x3e>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.winsize = type { i32, i32 }
@STDIN_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
define i32 @term_get_window_size(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca %struct.winsize
store i32* %0, i32** %4
store i32* %1, i32** %5
%7 = load i32, i32* @STDIN_FILENO
%8 = load i32, i32* @TIOCGWINSZ
%9 = call i64 @ioctl(i32 %7, i32 %8, %struct.winsize* %6)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %19
12: ; preds = %2
%13 = getelementptr inbounds %struct.winsize, %struct.winsize* %6, i32 0, i32 0
%14 = load i32, i32* %13
%15 = load i32*, i32** %4
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.winsize, %struct.winsize* %6, i32 0, i32 1
%17 = load i32, i32* %16
%18 = load i32*, i32** %5
store i32 %17, i32* %18
store i32 0, i32* %3
br label %19
19: ; preds = %12, %11
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
%struct.winsize = type { i32, i32 }
@STDIN_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
define i32 @term_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* @STDIN_FILENO
%6 = load i32, i32* @TIOCGWINSZ
%7 = call i64 @ioctl(i32 %5, i32 %6, %struct.winsize* %3)
%8 = icmp slt i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 0
%11 = load i32, i32* %10
store i32 %11, i32* %0
%12 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 1
%13 = load i32, i32* %12
store i32 %13, i32* %1
br label %14
14: ; preds = %2, %9
%15 = phi i32 [ 0, %9 ], [ -1, %2 ]
ret i32 %15
}