#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*/ TIOCSWINSZ;
int ioctl(int const, int /*<<< orphan*/, struct winsize const *);
int write(int const, char *, int);
int resize_tty(const int tty, const struct winsize *size) {
  if (-1 == ioctl(tty, TIOCSWINSZ, size))
    return -1;
  if (-1 == ((1 == write(tty, "\f", 1)) ? 0 : -1))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<resize_tty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eaf(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    115f <resize_tty+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a6 <resize_tty+0x86>
mov    -0x8(%rbp),%edi
lea    0xe97(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,%esi
mov    $0x1,%edx
mov    $0xffffffff,%ecx
xor    %eax,%eax
cmp    %esi,%edx
cmove  %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    119f <resize_tty+0x7f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a6 <resize_tty+0x86>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resize_tty>:
push   %rbx
mov    %rsi,%rdx
mov    %edi,%ebx
mov    0x2ebb(%rip),%rax
mov    (%rax),%esi
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     115a <resize_tty+0x3a>
lea    0xec0(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
setne  %al
neg    %eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.winsize = type { i32 }
@TIOCSWINSZ = global i32 0
@.str = [2 x i8] c"\0C\00"
define i32 @resize_tty(i32 %0, %struct.winsize* %1) {
%3 = load i32, i32* @TIOCSWINSZ
%4 = tail call i32 @ioctl(i32 %0, i32 %3, %struct.winsize* %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%8 = icmp ne i32 %7, 1
%9 = sext i1 %8 to i32
br label %10
10: ; preds = %6, %2
%11 = phi i32 [ -1, %2 ], [ %9, %6 ]
ret i32 %11
}