#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 {
  size_t ws_row;
  size_t ws_col;
};

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ TIOCGWINSZ;
int /*<<< orphan*/ ioctl(int /*<<< orphan*/, int /*<<< orphan*/,
                         struct winsize *);
bool getTermSize(size_t *rows, size_t *cols) {
  struct winsize ws;
  ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
  if (ws.ws_row == *rows && ws.ws_col == *cols)
    return false;
  *rows = ws.ws_row;
  *cols = ws.ws_col;
  return true;
}


x86 assembly (clang, -O0):
<getTermSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ec9(%rip),%rax
mov    (%rax),%edi
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1030 <ioctl@plt>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jne    1169 <getTermSize+0x59>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jne    1169 <getTermSize+0x59>
movl   $0x0,-0x4(%rbp)
jmp    1186 <getTermSize+0x76>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getTermSize>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2ecc(%rip),%rax
mov    (%rax),%edi
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1030 <ioctl@plt>
mov    0x8(%rsp),%rcx
mov    0x10(%rsp),%rdx
cmp    (%rbx),%rcx
jne    114f <getTermSize+0x3f>
xor    %eax,%eax
cmp    (%r14),%rdx
je     115a <getTermSize+0x4a>
mov    %rcx,(%rbx)
mov    %rdx,(%r14)
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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