#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 {
  unsigned short ws_col;
  unsigned short ws_row;
};

/* Variables and functions */
int /*<<< orphan*/ TIOCSWINSZ;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct winsize *);
int /*<<< orphan*/ perror(char *);
int set_terminal_size(int fd, unsigned short width, unsigned short height) {
  struct winsize ws;
  ws.ws_col = width;
  ws.ws_row = height;
  if (ioctl(fd, TIOCSWINSZ, &ws) != 0) {
    perror("TIOCSWINSZ");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_terminal_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dx,%ax
mov    %si,%cx
mov    %edi,-0x8(%rbp)
mov    %cx,-0xa(%rbp)
mov    %ax,-0xc(%rbp)
mov    -0xa(%rbp),%ax
mov    %ax,-0x10(%rbp)
mov    -0xc(%rbp),%ax
mov    %ax,-0xe(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
je     1180 <set_terminal_size+0x60>
lea    0xe91(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1187 <set_terminal_size+0x67>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_terminal_size>:
push   %rax
mov    %si,(%rsp)
mov    %dx,0x2(%rsp)
mov    0x2eb7(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1147 <set_terminal_size+0x27>
pop    %rcx
ret
lea    0xeb2(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.winsize = type { i16, i16 }
@TIOCSWINSZ = global i32 0
@.str = [11 x i8] c"TIOCSWINSZ\00"
define i32 @set_terminal_size(i32 %0, i16 zeroext %1, i16 zeroext %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i16
%7 = alloca i16
%8 = alloca %struct.winsize
store i32 %0, i32* %5
store i16 %1, i16* %6
store i16 %2, i16* %7
%9 = load i16, i16* %6
%10 = getelementptr inbounds %struct.winsize, %struct.winsize* %8, i32 0, i32 0
store i16 %9, i16* %10
%11 = load i16, i16* %7
%12 = getelementptr inbounds %struct.winsize, %struct.winsize* %8, i32 0, i32 1
store i16 %11, i16* %12
%13 = load i32, i32* %5
%14 = load i32, i32* @TIOCSWINSZ
%15 = call i64 @ioctl(i32 %13, i32 %14, %struct.winsize* %8)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %20
19: ; preds = %3
store i32 0, i32* %4
br label %20
20: ; preds = %19, %17
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
%struct.winsize = type { i16, i16 }
@TIOCSWINSZ = global i32 0
@.str = [11 x i8] c"TIOCSWINSZ\00"
define i32 @set_terminal_size(i32 %0, i16 zeroext %1, i16 zeroext %2) {
%4 = alloca %struct.winsize
%5 = bitcast %struct.winsize* %4 to i8*
%6 = getelementptr inbounds %struct.winsize, %struct.winsize* %4, i64 0, i32 0
store i16 %1, i16* %6
%7 = getelementptr inbounds %struct.winsize, %struct.winsize* %4, i64 0, i32 1
store i16 %2, i16* %7
%8 = load i32, i32* @TIOCSWINSZ
%9 = call i64 @ioctl(i32 %0, i32 %8, %struct.winsize* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %3
%12 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %3, %11
%14 = phi i32 [ -1, %11 ], [ 0, %3 ]
ret i32 %14
}