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

/* Variables and functions */
int /*<<< orphan*/ TIOCMGET;
int TIOCM_CTS;
int TIOCM_DSR;
unsigned char Termios2TncomInFlow(struct termios *);
unsigned char Termios2TncomOutFlow(struct termios *);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
unsigned char GetPortFlowControl(int PortFd, unsigned char Which) {
  struct termios PortSettings;
  int MLines;
  tcgetattr(PortFd, &PortSettings);
  ioctl(PortFd, TIOCMGET, &MLines);
  switch (Which) {
  case ((unsigned char)7):
    if (MLines & TIOCM_DSR)
      return ((unsigned char)8);
    else
      return ((unsigned char)9);
    break;
  case ((unsigned char)10):
    if (MLines & TIOCM_CTS)
      return ((unsigned char)11);
    else
      return ((unsigned char)12);
    break;
  case ((unsigned char)13):
    return Termios2TncomInFlow(&PortSettings);
    break;
  case ((unsigned char)0):
  default:
    return Termios2TncomOutFlow(&PortSettings);
    break;
  }
}


x86 assembly (clang, -O0):
<GetPortFlowControl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    -0x8(%rbp),%edi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdx
call   1040 <ioctl@plt>
movzbl -0x9(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0xd,%rax
ja     11fc <GetPortFlowControl+0xbc>
mov    -0x20(%rbp),%rax
lea    0xe71(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x14(%rbp),%eax
mov    0x2e46(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11b6 <GetPortFlowControl+0x76>
movb   $0x8,-0x1(%rbp)
jmp    1208 <GetPortFlowControl+0xc8>
movb   $0x9,-0x1(%rbp)
jmp    1208 <GetPortFlowControl+0xc8>
mov    -0x14(%rbp),%eax
mov    0x2e07(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11dd <GetPortFlowControl+0x9d>
movb   $0xb,-0x1(%rbp)
jmp    1208 <GetPortFlowControl+0xc8>
movb   $0xc,-0x1(%rbp)
jmp    1208 <GetPortFlowControl+0xc8>
lea    -0x10(%rbp),%rdi
call   1030 <Termios2TncomInFlow@plt>
mov    %al,-0x1(%rbp)
jmp    1208 <GetPortFlowControl+0xc8>
jmp    11fc <GetPortFlowControl+0xbc>
lea    -0x10(%rbp),%rdi
call   1060 <Termios2TncomOutFlow@plt>
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetPortFlowControl>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
mov    %rsp,%rsi
call   1050 <tcgetattr@plt>
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
cmp    $0xd,%bl
je     1187 <GetPortFlowControl+0x47>
cmp    $0xa,%bl
je     1191 <GetPortFlowControl+0x51>
cmp    $0x7,%bl
jne    11a7 <GetPortFlowControl+0x67>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
test   %eax,0x4(%rsp)
sete   %al
or     $0x8,%al
jmp    11af <GetPortFlowControl+0x6f>
mov    %rsp,%rdi
call   1030 <Termios2TncomInFlow@plt>
jmp    11af <GetPortFlowControl+0x6f>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
and    0x4(%rsp),%eax
cmp    $0x1,%eax
mov    $0xb,%al
adc    $0x0,%al
jmp    11af <GetPortFlowControl+0x6f>
mov    %rsp,%rdi
call   1060 <Termios2TncomOutFlow@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@TIOCMGET = global i32 0
@TIOCM_DSR = global i32 0
@TIOCM_CTS = global i32 0
define zeroext i8 @GetPortFlowControl(i32 %0, i8 zeroext %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca i8
%6 = alloca %struct.termios
%7 = alloca i32
store i32 %0, i32* %4
store i8 %1, i8* %5
%8 = load i32, i32* %4
%9 = call i32 @tcgetattr(i32 %8, %struct.termios* %6)
%10 = load i32, i32* %4
%11 = load i32, i32* @TIOCMGET
%12 = call i32 @ioctl(i32 %10, i32 %11, i32* %7)
%13 = load i8, i8* %5
%14 = zext i8 %13 to i32
switch i32 %14, label %32 [
i32 7, label %15
i32 10, label %22
i32 13, label %29
i32 0, label %31
]
15: ; preds = %2
%16 = load i32, i32* %7
%17 = load i32, i32* @TIOCM_DSR
%18 = and i32 %16, %17
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i8 8, i8* %3
br label %34
21: ; preds = %15
store i8 9, i8* %3
br label %34
22: ; preds = %2
%23 = load i32, i32* %7
%24 = load i32, i32* @TIOCM_CTS
%25 = and i32 %23, %24
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i8 11, i8* %3
br label %34
28: ; preds = %22
store i8 12, i8* %3
br label %34
29: ; preds = %2
%30 = call zeroext i8 @Termios2TncomInFlow(%struct.termios* %6)
store i8 %30, i8* %3
br label %34
31: ; preds = %2
br label %32
32: ; preds = %2, %31
%33 = call zeroext i8 @Termios2TncomOutFlow(%struct.termios* %6)
store i8 %33, i8* %3
br label %34
34: ; preds = %32, %29, %28, %27, %21, %20
%35 = load i8, i8* %3
ret i8 %35
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@TIOCMGET = global i32 0
@TIOCM_DSR = global i32 0
@TIOCM_CTS = global i32 0
define zeroext i8 @GetPortFlowControl(i32 %0, i8 zeroext %1) {
%3 = alloca %struct.termios
%4 = alloca i32
%5 = bitcast %struct.termios* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%8 = load i32, i32* @TIOCMGET
%9 = call i32 @ioctl(i32 %0, i32 %8, i32* %4)
switch i8 %1, label %24 [
i8 7, label %10
i8 10, label %16
i8 13, label %22
]
10: ; preds = %2
%11 = load i32, i32* %4
%12 = load i32, i32* @TIOCM_DSR
%13 = and i32 %12, %11
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i8 9, i8 8
br label %26
16: ; preds = %2
%17 = load i32, i32* %4
%18 = load i32, i32* @TIOCM_CTS
%19 = and i32 %18, %17
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i8 12, i8 11
br label %26
22: ; preds = %2
%23 = call zeroext i8 @Termios2TncomInFlow(%struct.termios* %3)
br label %26
24: ; preds = %2
%25 = call zeroext i8 @Termios2TncomOutFlow(%struct.termios* %3)
br label %26
26: ; preds = %16, %10, %24, %22
%27 = phi i8 [ %25, %24 ], [ %23, %22 ], [ %15, %10 ], [ %21, %16 ]
ret i8 %27
}