#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*/ STDOUT_FILENO;
int /*<<< orphan*/ TIOCGWINSZ;
int /*<<< orphan*/ ioctl(int /*<<< orphan*/, int /*<<< orphan*/,
                         struct winsize *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ sleep(int);
int main(void) {
  struct winsize ws;
  while (1) {
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
    printf("WIDTH = %d    HEIGHT = %d\n", ws.ws_col, ws.ws_row);
    sleep(2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%edi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1050 <sleep@plt>
jmp    113f <main+0xf>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2eb1(%rip),%r15
mov    0x2e8a(%rip),%r12
mov    %rsp,%r14
lea    0xeb0(%rip),%rbx
mov    (%r15),%edi
mov    (%r12),%esi
mov    %r14,%rdx
call   1040 <ioctl@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1050 <sleep@plt>
jmp    1150 <main+0x20>

LLVM IR (-O0):
%struct.winsize = type { i32, i32 }
@STDOUT_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
@.str = [27 x i8] c"WIDTH = %d HEIGHT = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.winsize
store i32 0, i32* %1
br label %3
3: ; preds = %0, %3
%4 = load i32, i32* @STDOUT_FILENO
%5 = load i32, i32* @TIOCGWINSZ
%6 = call i32 @ioctl(i32 %4, i32 %5, %struct.winsize* %2)
%7 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i32 0, i32 0
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i32 0, i32 1
%10 = load i32, i32* %9
%11 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %10)
%12 = call i32 @sleep(i32 2)
br label %3
}

LLVM IR (-O2):
%struct.winsize = type { i32, i32 }
@STDOUT_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
@.str = [27 x i8] c"WIDTH = %d HEIGHT = %d\0A\00"
define i32 @main() {
%1 = alloca %struct.winsize
%2 = bitcast %struct.winsize* %1 to i8*
%3 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i64 0, i32 0
%4 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i64 0, i32 1
br label %5
5: ; preds = %5, %0
%6 = load i32, i32* @STDOUT_FILENO
%7 = load i32, i32* @TIOCGWINSZ
%8 = call i32 @ioctl(i32 %6, i32 %7, %struct.winsize* %1)
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
%12 = call i32 @sleep(i32 2)
br label %5
}