#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*/ TIOCGWINSZ;
int ioctl(int, int /*<<< orphan*/, struct winsize *);
int get_winsize(int *row, int *col) {
  struct winsize w;
  int n;
  n = ioctl(1, TIOCGWINSZ, &w);
  if (n < 0 || w.ws_col == 0) {
    return 1;
  }
  *row = w.ws_row;
  *col = w.ws_col;
  return 0;
}


x86 assembly (clang, -O0):
<get_winsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     114e <get_winsize+0x3e>
cmpl   $0x0,-0x20(%rbp)
jne    115a <get_winsize+0x4a>
movl   $0x1,-0x4(%rbp)
jmp    1173 <get_winsize+0x63>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_winsize>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2eb3(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%ebp
lea    0x8(%rsp),%rdx
mov    $0x1,%edi
call   1030 <ioctl@plt>
test   %eax,%eax
js     1152 <get_winsize+0x42>
mov    0x8(%rsp),%eax
test   %eax,%eax
je     1152 <get_winsize+0x42>
mov    0xc(%rsp),%ecx
mov    %ecx,(%rbx)
mov    %eax,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.winsize = type { i32, i32 }
@TIOCGWINSZ = global i32 0
define i32 @get_winsize(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca %struct.winsize
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = load i32, i32* @TIOCGWINSZ
%9 = call i32 @ioctl(i32 1, i32 %8, %struct.winsize* %6)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = getelementptr inbounds %struct.winsize, %struct.winsize* %6, i32 0, i32 0
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12, %2
store i32 1, i32* %3
br label %24
17: ; preds = %12
%18 = getelementptr inbounds %struct.winsize, %struct.winsize* %6, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load i32*, i32** %4
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.winsize, %struct.winsize* %6, i32 0, i32 0
%22 = load i32, i32* %21
%23 = load i32*, i32** %5
store i32 %22, i32* %23
store i32 0, i32* %3
br label %24
24: ; preds = %17, %16
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.winsize = type { i32, i32 }
@TIOCGWINSZ = global i32 0
define i32 @get_winsize(i32* nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = alloca %struct.winsize
%4 = bitcast %struct.winsize* %3 to i8*
%5 = load i32, i32* @TIOCGWINSZ
%6 = call i32 @ioctl(i32 1, i32 %5, %struct.winsize* %3)
%7 = icmp slt i32 %6, 0
%8 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, 0
%11 = select i1 %7, i1 true, i1 %10
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 1
%14 = load i32, i32* %13
store i32 %14, i32* %0
store i32 %9, i32* %1
br label %15
15: ; preds = %2, %12
%16 = phi i32 [ 0, %12 ], [ 1, %2 ]
ret i32 %16
}