#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 */
typedef int tcflag_t;
struct termios {
  int c_cflag;
};

/* Variables and functions */
int CS5;
int CS6;
int CS7;
int CS8;
int CSIZE;
int /*<<< orphan*/ TCSADRAIN;
int /*<<< orphan*/ UnixLogPortSettings(struct termios *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void SetPortDataSize(int PortFd, unsigned char DataSize) {
  struct termios PortSettings;
  tcflag_t PDataSize;
  switch (DataSize) {
  case 5:
    PDataSize = CS5;
    break;
  case 6:
    PDataSize = CS6;
    break;
  case 7:
    PDataSize = CS7;
    break;
  case 8:
    PDataSize = CS8;
    break;
  default:
    PDataSize = CS8;
    break;
  }
  tcgetattr(PortFd, &PortSettings);
  PortSettings.c_cflag &= ~CSIZE;
  PortSettings.c_cflag |= PDataSize & CSIZE;
  tcsetattr(PortFd, TCSADRAIN, &PortSettings);
  UnixLogPortSettings(&PortSettings);
}


x86 assembly (clang, -O0):
<SetPortDataSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
add    $0xfffffffb,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     11af <SetPortDataSize+0x7f>
mov    -0x20(%rbp),%rax
lea    0xe9e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    11bb <SetPortDataSize+0x8b>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    11bb <SetPortDataSize+0x8b>
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    11bb <SetPortDataSize+0x8b>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    11bb <SetPortDataSize+0x8b>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1030 <tcgetattr@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2df5(%rip),%rcx
and    (%rcx),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <tcsetattr@plt>
lea    -0x10(%rbp),%rdi
call   1050 <UnixLogPortSettings@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetPortDataSize>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
add    $0xfb,%sil
cmp    $0x3,%sil
ja     1155 <SetPortDataSize+0x25>
movsbq %sil,%rax
lea    0x2c99(%rip),%rcx
mov    (%rcx,%rax,8),%rax
jmp    115c <SetPortDataSize+0x2c>
mov    0x2e8c(%rip),%rax
mov    (%rax),%ebp
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <tcgetattr@plt>
mov    0x2e6c(%rip),%rax
mov    0x8(%rsp),%ecx
xor    %ecx,%ebp
and    (%rax),%ebp
xor    %ecx,%ebp
mov    %ebp,0x8(%rsp)
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1040 <tcsetattr@plt>
mov    %r14,%rdi
call   1050 <UnixLogPortSettings@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@CS5 = global i32 0
@CS6 = global i32 0
@CS7 = global i32 0
@CS8 = global i32 0
@CSIZE = global i32 0
@TCSADRAIN = global i32 0
define void @SetPortDataSize(i32 %0, i8 zeroext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca %struct.termios
%6 = alloca i32
store i32 %0, i32* %3
store i8 %1, i8* %4
%7 = load i8, i8* %4
%8 = zext i8 %7 to i32
switch i32 %8, label %17 [
i32 5, label %9
i32 6, label %11
i32 7, label %13
i32 8, label %15
]
9: ; preds = %2
%10 = load i32, i32* @CS5
store i32 %10, i32* %6
br label %19
11: ; preds = %2
%12 = load i32, i32* @CS6
store i32 %12, i32* %6
br label %19
13: ; preds = %2
%14 = load i32, i32* @CS7
store i32 %14, i32* %6
br label %19
15: ; preds = %2
%16 = load i32, i32* @CS8
store i32 %16, i32* %6
br label %19
17: ; preds = %2
%18 = load i32, i32* @CS8
store i32 %18, i32* %6
br label %19
19: ; preds = %17, %15, %13, %11, %9
%20 = load i32, i32* %3
%21 = call i32 @tcgetattr(i32 %20, %struct.termios* %5)
%22 = load i32, i32* @CSIZE
%23 = xor i32 %22, -1
%24 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%25 = load i32, i32* %24
%26 = and i32 %25, %23
store i32 %26, i32* %24
%27 = load i32, i32* %6
%28 = load i32, i32* @CSIZE
%29 = and i32 %27, %28
%30 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%31 = load i32, i32* %30
%32 = or i32 %31, %29
store i32 %32, i32* %30
%33 = load i32, i32* %3
%34 = load i32, i32* @TCSADRAIN
%35 = call i32 @tcsetattr(i32 %33, i32 %34, %struct.termios* %5)
%36 = call i32 @UnixLogPortSettings(%struct.termios* %5)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@CS5 = global i32 0
@CS6 = global i32 0
@CS7 = global i32 0
@CS8 = global i32 0
@CSIZE = global i32 0
@TCSADRAIN = global i32 0
@switch.table.SetPortDataSize = [4 x i32*] [i32* @CS5, i32* @CS6, i32* @CS7, i32* @CS8]
define void @SetPortDataSize(i32 %0, i8 zeroext %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = add i8 %1, -5
%6 = icmp ult i8 %5, 4
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = sext i8 %5 to i64
%9 = getelementptr inbounds [4 x i32*], [4 x i32*]* @switch.table.SetPortDataSize, i64 0, i64 %8
%10 = load i32*, i32** %9
br label %11
11: ; preds = %2, %7
%12 = phi i32* [ %10, %7 ], [ @CS8, %2 ]
%13 = load i32, i32* %12
%14 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%15 = load i32, i32* @CSIZE
%16 = xor i32 %15, -1
%17 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%18 = load i32, i32* %17
%19 = and i32 %18, %16
%20 = and i32 %15, %13
%21 = or i32 %19, %20
store i32 %21, i32* %17
%22 = load i32, i32* @TCSADRAIN
%23 = call i32 @tcsetattr(i32 %0, i32 %22, %struct.termios* %3)
%24 = call i32 @UnixLogPortSettings(%struct.termios* %3)
ret void
}