#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 member_0;
  int member_1;
  int member_2;
  int member_3;
};

/* Variables and functions */
int /*<<< orphan*/ TIOCGWINSZ;
int /*<<< orphan*/ TIOCSWINSZ;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct winsize *);
int /*<<< orphan*/ stderr;
void resize_pty(int pty) {
  struct winsize sz;
  if (ioctl(0, TIOCGWINSZ, &sz) < 0) {
    struct winsize defaultsize = {30, 80, 640, 480};
    if (ioctl(pty, TIOCSWINSZ, &defaultsize) < 0) {
      fprintf(stderr, "Cannot set terminal size\n");
    }
    return;
  }
  ioctl(pty, TIOCSWINSZ, &sz);
}


x86 assembly (clang, -O0):
<resize_pty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1198 <resize_pty+0x78>
mov    0xeb0(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xead(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1193 <resize_pty+0x73>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11ad <resize_pty+0x8d>
mov    -0x4(%rbp),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resize_pty>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
xor    %edi,%edi
call   1030 <ioctl@plt>
test   %rax,%rax
js     1158 <resize_pty+0x38>
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
jmp    1190 <resize_pty+0x70>
movups 0xea1(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
test   %rax,%rax
jns    1190 <resize_pty+0x70>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.winsize = type { i32, i32, i32, i32 }
@TIOCGWINSZ = global i32 0
@__const.resize_pty.defaultsize = %struct.winsize { i32 30, i32 80, i32 640, i32 480 }
@TIOCSWINSZ = global i32 0
@stderr = global i32 0
@.str = [26 x i8] c"Cannot set terminal size\0A\00"
define void @resize_pty(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.winsize
%4 = alloca %struct.winsize
store i32 %0, i32* %2
%5 = load i32, i32* @TIOCGWINSZ
%6 = call i64 @ioctl(i32 0, i32 %5, %struct.winsize* %3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %1
%9 = bitcast %struct.winsize* %4 to i8*
%10 = load i32, i32* %2
%11 = load i32, i32* @TIOCSWINSZ
%12 = call i64 @ioctl(i32 %10, i32 %11, %struct.winsize* %4)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %14, %8
br label %22
18: ; preds = %1
%19 = load i32, i32* %2
%20 = load i32, i32* @TIOCSWINSZ
%21 = call i64 @ioctl(i32 %19, i32 %20, %struct.winsize* %3)
br label %22
22: ; preds = %18, %17
ret void
}

LLVM IR (-O2):
%struct.winsize = type { i32, i32, i32, i32 }
@TIOCGWINSZ = global i32 0
@__const.resize_pty.defaultsize = %struct.winsize { i32 30, i32 80, i32 640, i32 480 }
@TIOCSWINSZ = global i32 0
@stderr = global i32 0
@.str = [26 x i8] c"Cannot set terminal size\0A\00"
define void @resize_pty(i32 %0) {
%2 = alloca %struct.winsize
%3 = alloca %struct.winsize
%4 = bitcast %struct.winsize* %2 to i8*
%5 = load i32, i32* @TIOCGWINSZ
%6 = call i64 @ioctl(i32 0, i32 %5, %struct.winsize* %2)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = bitcast %struct.winsize* %3 to i8*
%10 = load i32, i32* @TIOCSWINSZ
%11 = call i64 @ioctl(i32 %0, i32 %10, %struct.winsize* %3)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %13, %8
br label %20
17: ; preds = %1
%18 = load i32, i32* @TIOCSWINSZ
%19 = call i64 @ioctl(i32 %0, i32 %18, %struct.winsize* %2)
br label %20
20: ; preds = %17, %16
ret void
}