#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*/ TIOCGWINSZ;
int /*<<< orphan*/ err_sys(char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int, int);
void pr_winsize(int fd) {
  struct winsize size;
  if (ioctl(fd, TIOCGWINSZ, (char *)&size) < 0)
    err_sys("TIOCGWINSZ error");
  printf("%d rows, %d columns\n", size.ws_row, size.ws_col);
}


x86 assembly (clang, -O0):
<pr_winsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1166 <pr_winsize+0x36>
lea    0xe9f(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe9e(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pr_winsize>:
push   %rax
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1050 <ioctl@plt>
test   %rax,%rax
jns    1153 <pr_winsize+0x23>
lea    0xeb2(%rip),%rdi
call   1030 <err_sys@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xeb0(%rip),%rdi
call   1040 <printf@plt>
pop    %rax
ret

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

LLVM IR (-O2):
%struct.winsize = type { i32, i32 }
@TIOCGWINSZ = global i32 0
@.str = [17 x i8] c"TIOCGWINSZ error\00"
@.str.1 = [21 x i8] c"%d rows, %d columns\0A\00"
define void @pr_winsize(i32 %0) {
%2 = alloca %struct.winsize
%3 = bitcast %struct.winsize* %2 to i8*
%4 = load i32, i32* @TIOCGWINSZ
%5 = call i64 @ioctl(i32 %0, i32 %4, i8* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @err_sys(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.winsize, %struct.winsize* %2, i64 0, i32 1
%13 = load i32, i32* %12
%14 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %13)
ret void
}