#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*/ TIOCGWINSZ;
int ioctl(int /*<<< orphan*/, int /*<<< orphan*/, struct winsize *);
int term_get_size(int *w, int *h) {
  struct winsize ws;
  if (ioctl(0, TIOCGWINSZ, &ws) != -1) {
    *w = ws.ws_col;
    *h = ws.ws_row;
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<term_get_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     115b <term_get_size+0x4b>
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)
jmp    1162 <term_get_size+0x52>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<term_get_size>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2eb2(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     114b <term_get_size+0x3b>
mov    0x8(%rsp),%eax
mov    %eax,(%r15)
mov    0xc(%rsp),%eax
mov    %eax,(%r14)
jmp    1150 <term_get_size+0x40>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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