#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*/ TIOCGWINSZ;
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int ioctl(int /*<<< orphan*/, int /*<<< orphan*/, struct winsize *);
int /*<<< orphan*/ stdout;
int getttywidth(void) {
  struct winsize winsize;
  if (ioctl(fileno(stdout), TIOCGWINSZ, &winsize) != -1)
    return (winsize.ws_col ? winsize.ws_col : 80);
  else
    return (80);
}


x86 assembly (clang, -O0):
<getttywidth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
call   1040 <fileno@plt>
mov    %eax,%edi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1180 <getttywidth+0x60>
cmpl   $0x0,-0x8(%rbp)
je     1168 <getttywidth+0x48>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1175 <getttywidth+0x55>
mov    $0x50,%eax
mov    %eax,-0xc(%rbp)
jmp    1175 <getttywidth+0x55>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1187 <getttywidth+0x67>
movl   $0x50,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getttywidth>:
push   %rax
mov    0x2eb8(%rip),%rax
mov    (%rax),%edi
call   1040 <fileno@plt>
mov    0x2e9a(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1030 <ioctl@plt>
mov    (%rsp),%ecx
test   %ecx,%ecx
mov    $0x50,%edx
cmove  %edx,%ecx
cmp    $0xffffffff,%eax
cmove  %edx,%ecx
mov    %ecx,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
%struct.winsize = type { i32 }
@stdout = global i32 0
@TIOCGWINSZ = global i32 0
define i32 @getttywidth() {
%1 = alloca %struct.winsize
%2 = bitcast %struct.winsize* %1 to i8*
%3 = load i32, i32* @stdout
%4 = tail call i32 @fileno(i32 %3)
%5 = load i32, i32* @TIOCGWINSZ
%6 = call i32 @ioctl(i32 %4, i32 %5, %struct.winsize* %1)
%7 = icmp eq i32 %6, -1
%8 = getelementptr inbounds %struct.winsize, %struct.winsize* %1, i64 0, i32 0
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, 0
%11 = select i1 %7, i1 true, i1 %10
%12 = select i1 %11, i32 80, i32 %9
ret i32 %12
}