#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;
};

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ TIOCGWINSZ;
int ioctl(int /*<<< orphan*/, int /*<<< orphan*/, struct winsize *);
int /*<<< orphan*/ isatty(int /*<<< orphan*/);
int check_window_size(void) {
  struct winsize winsize;
  if (!isatty(STDOUT_FILENO))
    return 0;
  if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize) == -1)
    return -1;
  if (winsize.ws_col >= 80)
    return 0;
  return -1;
}


x86 assembly (clang, -O0):
<check_window_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ec1(%rip),%rax
mov    (%rax),%edi
call   1030 <isatty@plt>
cmp    $0x0,%eax
jne    114b <check_window_size+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    1198 <check_window_size+0x78>
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    117b <check_window_size+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1198 <check_window_size+0x78>
cmpl   $0x50,-0x8(%rbp)
jl     1191 <check_window_size+0x71>
movl   $0x0,-0x4(%rbp)
jmp    1198 <check_window_size+0x78>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_window_size>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ec4(%rip),%rbx
mov    (%rbx),%edi
call   1030 <isatty@plt>
test   %eax,%eax
je     115f <check_window_size+0x3f>
mov    (%rbx),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1163 <check_window_size+0x43>
xor    %eax,%eax
cmpl   $0x50,0x8(%rsp)
setl   %al
neg    %eax
jmp    1168 <check_window_size+0x48>
xor    %eax,%eax
jmp    1168 <check_window_size+0x48>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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