#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 /*<<< orphan*/ ws_row;
  int /*<<< orphan*/ ws_col;
};

/* Variables and functions */
int /*<<< orphan*/ COLS;
int /*<<< orphan*/ LINES;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ TIOCGWINSZ;
int /*<<< orphan*/ clear();
int ioctl(int, int /*<<< orphan*/, struct winsize *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ refresh();
char *ttyname(int /*<<< orphan*/);
int /*<<< orphan*/ var_init();
void handle_sigwinch(int s) {
  char *tty = NULL;
  int fd = 0;
  int result = 0;
  struct winsize win;
  tty = ttyname(0);
  if (!tty)
    return;
  fd = open(tty, O_RDWR);
  if (fd == -1)
    return;
  result = ioctl(fd, TIOCGWINSZ, &win);
  if (result == -1)
    return;
  COLS = win.ws_col;
  LINES = win.ws_row;
  var_init();
  clear();
  refresh();
}


x86 assembly (clang, -O0):
<handle_sigwinch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %edi,%edi
call   1040 <ttyname@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119c <handle_sigwinch+0x3c>
jmp    1214 <handle_sigwinch+0xb4>
mov    -0x10(%rbp),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c0 <handle_sigwinch+0x60>
jmp    1214 <handle_sigwinch+0xb4>
mov    -0x14(%rbp),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11e7 <handle_sigwinch+0x87>
jmp    1214 <handle_sigwinch+0xb4>
mov    -0x1c(%rbp),%ecx
mov    0x2de7(%rip),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%ecx
mov    0x2de3(%rip),%rax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1080 <var_init@plt>
mov    $0x0,%al
call   1070 <clear@plt>
mov    $0x0,%al
call   1050 <refresh@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_sigwinch>:
push   %rax
xor    %edi,%edi
call   1040 <ttyname@plt>
test   %rax,%rax
je     11c9 <handle_sigwinch+0x69>
mov    0x2e74(%rip),%rcx
mov    (%rcx),%esi
mov    %rax,%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11c9 <handle_sigwinch+0x69>
mov    0x2e36(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11c9 <handle_sigwinch+0x69>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
mov    0x2e2f(%rip),%rdx
mov    %ecx,(%rdx)
mov    0x2e2e(%rip),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
call   1080 <var_init@plt>
xor    %eax,%eax
call   1070 <clear@plt>
xor    %eax,%eax
call   1050 <refresh@plt>
pop    %rax
ret

LLVM IR (-O0):
%struct.winsize = type { i32, i32 }
@O_RDWR = global i32 0
@TIOCGWINSZ = global i32 0
@COLS = global i32 0
@LINES = global i32 0
define void @handle_sigwinch(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.winsize
store i32 %0, i32* %2
store i8* null, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
%7 = call i8* @ttyname(i32 0)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
br label %33
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %11
br label %33
18: ; preds = %11
%19 = load i32, i32* %4
%20 = load i32, i32* @TIOCGWINSZ
%21 = call i32 @ioctl(i32 %19, i32 %20, %struct.winsize* %6)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %25
24: ; preds = %18
br label %33
25: ; preds = %18
%26 = getelementptr inbounds %struct.winsize, %struct.winsize* %6, i32 0, i32 1
%27 = load i32, i32* %26
store i32 %27, i32* @COLS
%28 = getelementptr inbounds %struct.winsize, %struct.winsize* %6, i32 0, i32 0
%29 = load i32, i32* %28
store i32 %29, i32* @LINES
%30 = call i32 (...) @var_init()
%31 = call i32 (...) @clear()
%32 = call i32 (...) @refresh()
br label %33
33: ; preds = %25, %24, %17, %10
ret void
}

LLVM IR (-O2):
%struct.winsize = type { i32, i32 }
@O_RDWR = global i32 0
@TIOCGWINSZ = global i32 0
@COLS = global i32 0
@LINES = global i32 0
define void @handle_sigwinch(i32 %0) {
%2 = alloca %struct.winsize
%3 = bitcast %struct.winsize* %2 to i8*
%4 = tail call i8* @ttyname(i32 0)
%5 = icmp eq i8* %4, null
br i1 %5, label %22, label %6
6: ; preds = %1
%7 = load i32, i32* @O_RDWR
%8 = tail call i32 @open(i8* %4, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %22, label %10
10: ; preds = %6
%11 = load i32, i32* @TIOCGWINSZ
%12 = call i32 @ioctl(i32 %8, i32 %11, %struct.winsize* %2)
%13 = icmp eq i32 %12, -1
br i1 %13, label %22, label %14
14: ; preds = %10
%15 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i64 0, i32 1
%16 = load i32, i32* %15
store i32 %16, i32* @COLS
%17 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i64 0, i32 0
%18 = load i32, i32* %17
store i32 %18, i32* @LINES
%19 = call i32 (...) @var_init()
%20 = call i32 (...) @clear()
%21 = call i32 (...) @refresh()
br label %22
22: ; preds = %10, %6, %1, %14
ret void
}