#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_row;
  int ws_col;
};

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TIOCGWINSZ;
int /*<<< orphan*/ ioctl(int /*<<< orphan*/, int /*<<< orphan*/,
                         struct winsize *);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  struct winsize w;
  int r = 0, c = 0;
  for (;;) {
    ioctl(STDIN_FILENO, TIOCGWINSZ, &w);
    if (w.ws_row != r || w.ws_col != c) {
      r = w.ws_row;
      c = w.ws_col;
      printf("%d x %d\n", r, c);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1170 <main+0x50>
mov    -0xc(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     118e <main+0x6e>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
jmp    113d <main+0x1d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
mov    0x2e9b(%rip),%r13
mov    %rsp,%r15
xor    %r12d,%r12d
jmp    1160 <main+0x40>
lea    0xebc(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
mov    %ebp,%r14d
mov    %ebx,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%esi
mov    %r15,%rdx
call   1040 <ioctl@plt>
mov    (%rsp),%ebp
mov    0x4(%rsp),%ebx
cmp    %r14d,%ebp
jne    113d <main+0x1d>
cmp    %r12d,%ebx
je     1160 <main+0x40>
jmp    113d <main+0x1d>

LLVM IR (-O0):
%struct.winsize = type { i32, i32 }
@STDIN_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
@.str = [9 x i8] c"%d x %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.winsize
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %26, %0
%6 = load i32, i32* @STDIN_FILENO
%7 = load i32, i32* @TIOCGWINSZ
%8 = call i32 @ioctl(i32 %6, i32 %7, %struct.winsize* %2)
%9 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i32 0, i32 0
%10 = load i32, i32* %9
%11 = load i32, i32* %3
%12 = icmp ne i32 %10, %11
br i1 %12, label %18, label %13
13: ; preds = %5
%14 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i32 0, i32 1
%15 = load i32, i32* %14
%16 = load i32, i32* %4
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %13, %5
%19 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i32 0, i32 0
%20 = load i32, i32* %19
store i32 %20, i32* %3
%21 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i32 0, i32 1
%22 = load i32, i32* %21
store i32 %22, i32* %4
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %24)
br label %26
26: ; preds = %18, %13
br label %5
}

LLVM IR (-O2):
%struct.winsize = type { i32, i32 }
@STDIN_FILENO = global i32 0
@TIOCGWINSZ = global i32 0
@.str = [9 x i8] c"%d x %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 = %17, %0
%6 = phi i32 [ %12, %17 ], [ 0, %0 ]
%7 = phi i32 [ %14, %17 ], [ 0, %0 ]
br label %8
8: ; preds = %5, %8
%9 = load i32, i32* @STDIN_FILENO
%10 = load i32, i32* @TIOCGWINSZ
%11 = call i32 @ioctl(i32 %9, i32 %10, %struct.winsize* %1)
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, %6
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, %7
%16 = select i1 %13, i1 %15, i1 false
br i1 %16, label %8, label %17
17: ; preds = %8
%18 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %14)
br label %5
}