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

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ TIOCGWINSZ;
int /*<<< orphan*/ ioctl(int /*<<< orphan*/, int /*<<< orphan*/,
                         struct winsize *);
int /*<<< orphan*/ system(char *);
void get_terminal_dim_noncurses(int *width, int *lines) {
  struct winsize dim;
  ioctl(STDOUT_FILENO, TIOCGWINSZ, &dim);
  *lines = (int)dim.ws_row;
  *width = (int)dim.ws_col;
  system("clear");
}


x86 assembly (clang, -O0):
<get_terminal_dim_noncurses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2eb9(%rip),%rax
mov    (%rax),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
lea    0xe96(%rip),%rdi
call   1030 <system@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_terminal_dim_noncurses>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2ebc(%rip),%rax
mov    (%rax),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1040 <ioctl@plt>
mov    0x10(%rsp),%eax
mov    %eax,(%rbx)
mov    0x8(%rsp),%eax
mov    %eax,(%r14)
lea    0xea3(%rip),%rdi
call   1030 <system@plt>
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
@.str = [6 x i8] c"clear\00"
define void @get_terminal_dim_noncurses(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca %struct.winsize
store i32* %0, i32** %3
store i32* %1, i32** %4
%6 = load i32, i32* @STDOUT_FILENO
%7 = load i32, i32* @TIOCGWINSZ
%8 = call i32 @ioctl(i32 %6, i32 %7, %struct.winsize* %5)
%9 = getelementptr inbounds %struct.winsize, %struct.winsize* %5, i32 0, i32 1
%10 = load i64, i64* %9
%11 = trunc i64 %10 to i32
%12 = load i32*, i32** %4
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.winsize, %struct.winsize* %5, i32 0, i32 0
%14 = load i64, i64* %13
%15 = trunc i64 %14 to i32
%16 = load i32*, i32** %3
store i32 %15, i32* %16
%17 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.winsize = type { i64, i64 }
@STDOUT_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
@.str = [6 x i8] c"clear\00"
define void @get_terminal_dim_noncurses(i32* nocapture writeonly %0, i32* nocapture writeonly %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 1
%9 = load i64, i64* %8
%10 = trunc i64 %9 to i32
store i32 %10, i32* %1
%11 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 0
%12 = load i64, i64* %11
%13 = trunc i64 %12 to i32
store i32 %13, i32* %0
%14 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
ret void
}