#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;
  int ws_xpixel;
  int ws_ypixel;
};

/* Variables and functions */
int /*<<< orphan*/ TIOCGWINSZ;
int ioctl(int /*<<< orphan*/, int /*<<< orphan*/, struct winsize *);
int /*<<< orphan*/ printf(char *, int, int);
int main(int argc, char *argv[]) {
  struct winsize wbuf;
  if (ioctl(0, TIOCGWINSZ, &wbuf) != -1) {
    printf("%d rows x %d cols\n", wbuf.ws_row, wbuf.ws_col);
    printf("%d wide x %d tall\n", wbuf.ws_xpixel, wbuf.ws_ypixel);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1177 <main+0x57>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
mov    0x2ead(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1166 <main+0x46>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
lea    0xeb2(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
%struct.winsize = type { i32, i32, i32, i32 }
@TIOCGWINSZ = global i32 0
@.str = [19 x i8] c"%d rows x %d cols\0A\00"
@.str.1 = [19 x i8] c"%d wide x %d tall\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.winsize
%4 = bitcast %struct.winsize* %3 to i8*
%5 = load i32, i32* @TIOCGWINSZ
%6 = call i32 @ioctl(i32 0, i32 %5, %struct.winsize* %3)
%7 = icmp eq i32 %6, -1
br i1 %7, label %19, label %8
8: ; preds = %2
%9 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 1
%12 = load i32, i32* %11
%13 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %12)
%14 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 2
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 3
%17 = load i32, i32* %16
%18 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %17)
br label %19
19: ; preds = %8, %2
ret i32 0
}