#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 */

/* Variables and functions */
int /*<<< orphan*/ TIOCMGET;
int TIOCM_CTS;
int TIOCM_DSR;
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ tty_clear(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ tty_set(int, int, int /*<<< orphan*/);
int is_it_is_it_huh(int port) {
  int j;
  tty_clear(port, 1, 0);
  ioctl(port, TIOCMGET, &j);
  if ((j & TIOCM_CTS) || (j & TIOCM_DSR)) {
    return 0;
  }
  tty_set(port, 1, 0);
  ioctl(port, TIOCMGET, &j);
  if ((!(j & TIOCM_CTS)) || (j & TIOCM_DSR)) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<is_it_is_it_huh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <tty_clear@plt>
mov    -0x8(%rbp),%edi
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0xc(%rbp),%eax
mov    0x2e67(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1189 <is_it_is_it_huh+0x59>
mov    -0xc(%rbp),%eax
mov    0x2e6a(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1195 <is_it_is_it_huh+0x65>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <is_it_is_it_huh+0xc6>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1050 <tty_set@plt>
mov    -0x8(%rbp),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0xc(%rbp),%eax
mov    0x2e0d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11e3 <is_it_is_it_huh+0xb3>
mov    -0xc(%rbp),%eax
mov    0x2e10(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11ef <is_it_is_it_huh+0xbf>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <is_it_is_it_huh+0xc6>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_it_is_it_huh>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
xor    %ebx,%ebx
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <tty_clear@plt>
mov    0x2e8d(%rip),%r15
mov    (%r15),%esi
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
mov    0xc(%rsp),%eax
mov    0x2e63(%rip),%r12
test   %eax,(%r12)
jne    11b0 <is_it_is_it_huh+0x80>
mov    0x2e6e(%rip),%r14
test   %eax,(%r14)
jne    11b0 <is_it_is_it_huh+0x80>
xor    %ebx,%ebx
mov    %ebp,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1050 <tty_set@plt>
mov    (%r15),%esi
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
mov    0xc(%rsp),%eax
test   %eax,(%r12)
je     11b0 <is_it_is_it_huh+0x80>
xor    %ebx,%ebx
test   %eax,(%r14)
sete   %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@TIOCMGET = global i32 0
@TIOCM_CTS = global i32 0
@TIOCM_DSR = global i32 0
define i32 @is_it_is_it_huh(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @tty_clear(i32 %5, i32 1, i32 0)
%7 = load i32, i32* %3
%8 = load i32, i32* @TIOCMGET
%9 = call i32 @ioctl(i32 %7, i32 %8, i32* %4)
%10 = load i32, i32* %4
%11 = load i32, i32* @TIOCM_CTS
%12 = and i32 %10, %11
%13 = icmp ne i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %1
%15 = load i32, i32* %4
%16 = load i32, i32* @TIOCM_DSR
%17 = and i32 %15, %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14, %1
store i32 0, i32* %2
br label %37
20: ; preds = %14
%21 = load i32, i32* %3
%22 = call i32 @tty_set(i32 %21, i32 1, i32 0)
%23 = load i32, i32* %3
%24 = load i32, i32* @TIOCMGET
%25 = call i32 @ioctl(i32 %23, i32 %24, i32* %4)
%26 = load i32, i32* %4
%27 = load i32, i32* @TIOCM_CTS
%28 = and i32 %26, %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %20
%31 = load i32, i32* %4
%32 = load i32, i32* @TIOCM_DSR
%33 = and i32 %31, %32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30, %20
store i32 0, i32* %2
br label %37
36: ; preds = %30
store i32 1, i32* %2
br label %37
37: ; preds = %36, %35, %19
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@TIOCMGET = global i32 0
@TIOCM_CTS = global i32 0
@TIOCM_DSR = global i32 0
define i32 @is_it_is_it_huh(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 @tty_clear(i32 %0, i32 1, i32 0)
%5 = load i32, i32* @TIOCMGET
%6 = call i32 @ioctl(i32 %0, i32 %5, i32* %2)
%7 = load i32, i32* %2
%8 = load i32, i32* @TIOCM_CTS
%9 = and i32 %8, %7
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %1
%12 = load i32, i32* @TIOCM_DSR
%13 = and i32 %12, %7
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = call i32 @tty_set(i32 %0, i32 1, i32 0)
%17 = load i32, i32* @TIOCMGET
%18 = call i32 @ioctl(i32 %0, i32 %17, i32* %2)
%19 = load i32, i32* %2
%20 = load i32, i32* @TIOCM_CTS
%21 = and i32 %20, %19
%22 = icmp eq i32 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %15
%24 = load i32, i32* @TIOCM_DSR
%25 = and i32 %24, %19
%26 = icmp eq i32 %25, 0
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %23, %15, %1, %11
%29 = phi i32 [ 0, %11 ], [ 0, %1 ], [ 0, %15 ], [ %27, %23 ]
ret i32 %29
}