#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*/ EINVAL;
#define TCSADRAIN 130
#define TCSAFLUSH 129
#define TCSANOW 128
int TCSETS;
int TCSETSF;
int TCSETSW;
int /*<<< orphan*/ errno;
int ioctl(int, int, struct termios const *);
int tcsetattr(int fd, int optional_action, const struct termios *termios_p) {
  int request = 0;
  switch (optional_action) {
  case TCSANOW:
    request = TCSETS;
    break;
  case TCSADRAIN:
    request = TCSETSW;
    break;
  case TCSAFLUSH:
    request = TCSETSF;
    break;
  default:
    errno = -EINVAL;
    return -1;
  }
  return ioctl(fd, request, termios_p);
}


x86 assembly (clang, -O0):
<tcsetattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x80,%eax
je     1165 <tcsetattr+0x55>
jmp    113f <tcsetattr+0x2f>
mov    -0x20(%rbp),%eax
sub    $0x81,%eax
je     1187 <tcsetattr+0x77>
jmp    1152 <tcsetattr+0x42>
mov    -0x20(%rbp),%eax
sub    $0x82,%eax
je     1176 <tcsetattr+0x66>
jmp    1198 <tcsetattr+0x88>
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    11b8 <tcsetattr+0xa8>
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    11b8 <tcsetattr+0xa8>
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    11b8 <tcsetattr+0xa8>
xor    %ecx,%ecx
mov    0x2e2f(%rip),%rax
sub    (%rax),%ecx
mov    0x2e2e(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <tcsetattr+0xba>
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcsetattr>:
add    $0xffffff80,%esi
cmp    $0x3,%esi
jae    112d <tcsetattr+0x1d>
movslq %esi,%rax
lea    0x2cd6(%rip),%rcx
mov    (%rcx,%rax,8),%rax
mov    (%rax),%esi
jmp    1030 <ioctl@plt>
mov    0x2ea4(%rip),%rax
xor    %ecx,%ecx
sub    (%rax),%ecx
mov    0x2ea1(%rip),%rax
mov    %ecx,(%rax)
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@TCSETS = global i32 0
@TCSETSW = global i32 0
@TCSETSF = global i32 0
@EINVAL = global i32 0
@errno = global i32 0
define i32 @tcsetattr(i32 %0, i32 %1, %struct.termios* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.termios*
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store %struct.termios* %2, %struct.termios** %7
store i32 0, i32* %8
%9 = load i32, i32* %6
switch i32 %9, label %16 [
i32 128, label %10
i32 130, label %12
i32 129, label %14
]
10: ; preds = %3
%11 = load i32, i32* @TCSETS
store i32 %11, i32* %8
br label %19
12: ; preds = %3
%13 = load i32, i32* @TCSETSW
store i32 %13, i32* %8
br label %19
14: ; preds = %3
%15 = load i32, i32* @TCSETSF
store i32 %15, i32* %8
br label %19
16: ; preds = %3
%17 = load i32, i32* @EINVAL
%18 = sub nsw i32 0, %17
store i32 %18, i32* @errno
store i32 -1, i32* %4
br label %24
19: ; preds = %14, %12, %10
%20 = load i32, i32* %5
%21 = load i32, i32* %8
%22 = load %struct.termios*, %struct.termios** %7
%23 = call i32 @ioctl(i32 %20, i32 %21, %struct.termios* %22)
store i32 %23, i32* %4
br label %24
24: ; preds = %19, %16
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@TCSETS = global i32 0
@TCSETSW = global i32 0
@TCSETSF = global i32 0
@EINVAL = global i32 0
@errno = global i32 0
@switch.table.tcsetattr = [3 x i32*] [i32* @TCSETS, i32* @TCSETSF, i32* @TCSETSW]
define i32 @tcsetattr(i32 %0, i32 %1, %struct.termios* %2) {
%4 = add i32 %1, -128
%5 = icmp ult i32 %4, 3
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = load i32, i32* @EINVAL
%8 = sub nsw i32 0, %7
store i32 %8, i32* @errno
br label %15
9: ; preds = %3
%10 = sext i32 %4 to i64
%11 = getelementptr inbounds [3 x i32*], [3 x i32*]* @switch.table.tcsetattr, i64 0, i64 %10
%12 = load i32*, i32** %11
%13 = load i32, i32* %12
%14 = tail call i32 @ioctl(i32 %0, i32 %13, %struct.termios* %2)
br label %15
15: ; preds = %9, %6
%16 = phi i32 [ -1, %6 ], [ %14, %9 ]
ret i32 %16
}