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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ TIOCGWINSZ;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ ioctl(int /*<<< orphan*/, int /*<<< orphan*/, struct winsize *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
void set_tty_screen(struct winsize *ws) {
  if (ioctl(0, TIOCGWINSZ, ws) < 0) {
    perror("Could not get tty size...\n");
    exit(EXIT_FAILURE);
  }
  printf("\033[2J");
  printf("\033[%d;%dH", 1, 1);
}


x86 assembly (clang, -O0):
<set_tty_screen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rdx
xor    %edi,%edi
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1184 <set_tty_screen+0x44>
lea    0xe8f(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe87(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_tty_screen>:
push   %rax
mov    %rdi,%rdx
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     1180 <set_tty_screen+0x40>
lea    0xebb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb2(%rip),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
xor    %eax,%eax
pop    %rcx
jmp    1030 <printf@plt>
lea    0xe79(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.winsize = type { i32 }
@TIOCGWINSZ = global i32 0
@.str = [27 x i8] c"Could not get tty size...\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"\1B[2J\00"
@.str.2 = [9 x i8] c"\1B[%d;%dH\00"
define void @set_tty_screen(%struct.winsize* %0) {
%2 = alloca %struct.winsize*
store %struct.winsize* %0, %struct.winsize** %2
%3 = load i32, i32* @TIOCGWINSZ
%4 = load %struct.winsize*, %struct.winsize** %2
%5 = call i64 @ioctl(i32 0, i32 %3, %struct.winsize* %4)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 1)
ret void
}

LLVM IR (-O2):
%struct.winsize = type { i32 }
@TIOCGWINSZ = global i32 0
@.str = [27 x i8] c"Could not get tty size...\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"\1B[2J\00"
@.str.2 = [9 x i8] c"\1B[%d;%dH\00"
define void @set_tty_screen(%struct.winsize* %0) {
%2 = load i32, i32* @TIOCGWINSZ
%3 = tail call i64 @ioctl(i32 0, i32 %2, %struct.winsize* %0)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 1)
ret void
}