#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 /*<<< orphan*/ TIOCSWINSZ;
int /*<<< orphan*/ exit(int);
int ioctl(int, int /*<<< orphan*/, struct winsize *);
int /*<<< orphan*/ set_cooked();
void set_window_size(int w, int h) {
  struct winsize ws;
  if (ioctl(1, TIOCGWINSZ, &ws) == -1) {
    set_cooked();
    exit(13);
  }
  ws.ws_col = w;
  ws.ws_row = h;
  if (ioctl(1, TIOCSWINSZ, &ws) == -1) {
    set_cooked();
    exit(14);
  }
}


x86 assembly (clang, -O0):
<set_window_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    116f <set_window_size+0x3f>
mov    $0x0,%al
call   1030 <set_cooked@plt>
mov    $0xd,%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11ac <set_window_size+0x7c>
mov    $0x0,%al
call   1030 <set_cooked@plt>
mov    $0xe,%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_window_size>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    $0x1,%edi
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     117b <set_window_size+0x4b>
mov    %ebp,(%rsp)
mov    %ebx,0x4(%rsp)
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    $0x1,%edi
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     118c <set_window_size+0x5c>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
call   1030 <set_cooked@plt>
mov    $0xd,%edi
call   1050 <exit@plt>
xor    %eax,%eax
call   1030 <set_cooked@plt>
mov    $0xe,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
%struct.winsize = type { i32, i32 }
@TIOCGWINSZ = global i32 0
@TIOCSWINSZ = global i32 0
define void @set_window_size(i32 %0, i32 %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 eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = call i32 (...) @set_cooked()
%10 = call i32 @exit(i32 13)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 0
store i32 %0, i32* %12
%13 = getelementptr inbounds %struct.winsize, %struct.winsize* %3, i64 0, i32 1
store i32 %1, i32* %13
%14 = load i32, i32* @TIOCSWINSZ
%15 = call i32 @ioctl(i32 1, i32 %14, %struct.winsize* %3)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = call i32 (...) @set_cooked()
%19 = call i32 @exit(i32 14)
unreachable
20: ; preds = %11
ret void
}