#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 /*<<< orphan*/ c_cflag;
};

/* Variables and functions */
int /*<<< orphan*/ CS5;
int /*<<< orphan*/ CS6;
int /*<<< orphan*/ CS7;
int /*<<< orphan*/ CS8;
int /*<<< orphan*/ CSIZE;
int EINVAL;
int tty_set_databits(struct termios *tty, char *databits) {
  tty->c_cflag &= ~CSIZE;
  switch (*databits) {
  case '5':
    tty->c_cflag |= CS5;
    break;
  case '6':
    tty->c_cflag |= CS6;
    break;
  case '7':
    tty->c_cflag |= CS7;
    break;
  case '8':
    tty->c_cflag |= CS8;
    break;
  default:
    return -EINVAL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<tty_set_databits>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ec5(%rip),%rax
mov    (%rax),%edx
not    %edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
and    %edx,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffcb,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     11a6 <tty_set_databits+0xa6>
mov    -0x20(%rbp),%rax
lea    0xebb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e63(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
jmp    11b9 <tty_set_databits+0xb9>
mov    0x2e7d(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
jmp    11b9 <tty_set_databits+0xb9>
mov    0x2e2f(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
jmp    11b9 <tty_set_databits+0xb9>
mov    0x2e49(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
jmp    11b9 <tty_set_databits+0xb9>
xor    %eax,%eax
mov    0x2e19(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11c0 <tty_set_databits+0xc0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_set_databits>:
mov    0x2ed1(%rip),%rax
mov    (%rax),%eax
not    %eax
and    (%rdi),%eax
mov    %eax,(%rdi)
movsbl (%rsi),%ecx
add    $0xffffffcb,%ecx
cmp    $0x3,%ecx
ja     1133 <tty_set_databits+0x33>
lea    0xedf(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    0x2e87(%rip),%rcx
jmp    1158 <tty_set_databits+0x58>
mov    0x2e8e(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
ret
mov    0x2ea2(%rip),%rcx
jmp    1158 <tty_set_databits+0x58>
mov    0x2e61(%rip),%rcx
jmp    1158 <tty_set_databits+0x58>
mov    0x2e88(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rdi)
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@CSIZE = global i32 0
@CS5 = global i32 0
@CS6 = global i32 0
@CS7 = global i32 0
@CS8 = global i32 0
@EINVAL = global i32 0
define i32 @tty_set_databits(%struct.termios* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.termios*
%5 = alloca i8*
store %struct.termios* %0, %struct.termios** %4
store i8* %1, i8** %5
%6 = load i32, i32* @CSIZE
%7 = xor i32 %6, -1
%8 = load %struct.termios*, %struct.termios** %4
%9 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = and i32 %10, %7
store i32 %11, i32* %9
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
switch i32 %14, label %39 [
i32 53, label %15
i32 54, label %21
i32 55, label %27
i32 56, label %33
]
15: ; preds = %2
%16 = load i32, i32* @CS5
%17 = load %struct.termios*, %struct.termios** %4
%18 = getelementptr inbounds %struct.termios, %struct.termios* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = or i32 %19, %16
store i32 %20, i32* %18
br label %42
21: ; preds = %2
%22 = load i32, i32* @CS6
%23 = load %struct.termios*, %struct.termios** %4
%24 = getelementptr inbounds %struct.termios, %struct.termios* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = or i32 %25, %22
store i32 %26, i32* %24
br label %42
27: ; preds = %2
%28 = load i32, i32* @CS7
%29 = load %struct.termios*, %struct.termios** %4
%30 = getelementptr inbounds %struct.termios, %struct.termios* %29, i32 0, i32 0
%31 = load i32, i32* %30
%32 = or i32 %31, %28
store i32 %32, i32* %30
br label %42
33: ; preds = %2
%34 = load i32, i32* @CS8
%35 = load %struct.termios*, %struct.termios** %4
%36 = getelementptr inbounds %struct.termios, %struct.termios* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = or i32 %37, %34
store i32 %38, i32* %36
br label %42
39: ; preds = %2
%40 = load i32, i32* @EINVAL
%41 = sub nsw i32 0, %40
store i32 %41, i32* %3
br label %43
42: ; preds = %33, %27, %21, %15
store i32 0, i32* %3
br label %43
43: ; preds = %42, %39
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@CSIZE = global i32 0
@CS5 = global i32 0
@CS6 = global i32 0
@CS7 = global i32 0
@CS8 = global i32 0
@EINVAL = global i32 0
define i32 @tty_set_databits(%struct.termios* nocapture %0, i8* nocapture %1) {
%3 = load i32, i32* @CSIZE
%4 = xor i32 %3, -1
%5 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = and i32 %6, %4
store i32 %7, i32* %5
%8 = load i8, i8* %1
%9 = sext i8 %8 to i32
switch i32 %9, label %22 [
i32 53, label %10
i32 54, label %13
i32 55, label %16
i32 56, label %19
]
10: ; preds = %2
%11 = load i32, i32* @CS5
%12 = or i32 %11, %7
store i32 %12, i32* %5
br label %25
13: ; preds = %2
%14 = load i32, i32* @CS6
%15 = or i32 %14, %7
store i32 %15, i32* %5
br label %25
16: ; preds = %2
%17 = load i32, i32* @CS7
%18 = or i32 %17, %7
store i32 %18, i32* %5
br label %25
19: ; preds = %2
%20 = load i32, i32* @CS8
%21 = or i32 %20, %7
store i32 %21, i32* %5
br label %25
22: ; preds = %2
%23 = load i32, i32* @EINVAL
%24 = sub nsw i32 0, %23
br label %25
25: ; preds = %10, %13, %16, %19, %22
%26 = phi i32 [ %24, %22 ], [ 0, %19 ], [ 0, %16 ], [ 0, %13 ], [ 0, %10 ]
ret i32 %26
}