#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 /*<<< orphan*/ ioctl(int const, int /*<<< orphan*/, struct winsize *);
void termsize(const int fd, int *const w, int *const h) {
  struct winsize ws;
  ioctl(fd, TIOCGWINSZ, &ws);
  if (w)
    *w = ws.ws_col;
  if (h)
    *h = ws.ws_row;
}


x86 assembly (clang, -O0):
<termsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
cmpq   $0x0,-0x10(%rbp)
je     114c <termsize+0x3c>
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     1160 <termsize+0x50>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<termsize>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    0x2eb7(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
test   %rbx,%rbx
je     1135 <termsize+0x25>
mov    (%rsp),%eax
mov    %eax,(%rbx)
test   %r14,%r14
je     1141 <termsize+0x31>
mov    0x4(%rsp),%eax
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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