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


x86 assembly (clang, -O0):
<term_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    114f <term_size+0x3f>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1168 <term_size+0x58>
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    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<term_size>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2eb7(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    $0x1,%edi
call   1030 <ioctl@plt>
test   %eax,%eax
js     1142 <term_size+0x32>
mov    (%rsp),%eax
mov    %eax,(%rbx)
mov    0x4(%rsp),%eax
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.winsize = type { i32, i32 }
@TIOCGWINSZ = global i32 0
define i32 @term_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 1, i32 %5, %struct.winsize* %3)
%7 = icmp slt i32 %6, 0
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 ], [ %6, %2 ]
ret i32 %14
}