#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*/ CSTOPB;
int EINVAL;
int tty_set_stopbits(struct termios *tty, char *stopbits) {
  switch (*stopbits) {
  case '1':
    tty->c_cflag &= ~CSTOPB;
    break;
  case '2':
    tty->c_cflag |= CSTOPB;
    break;
  default:
    return -EINVAL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<tty_set_stopbits>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x31,%eax
je     1135 <tty_set_stopbits+0x35>
jmp    1124 <tty_set_stopbits+0x24>
mov    -0x1c(%rbp),%eax
sub    $0x32,%eax
je     114e <tty_set_stopbits+0x4e>
jmp    1164 <tty_set_stopbits+0x64>
mov    0x2e94(%rip),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x10(%rbp),%rax
and    (%rax),%ecx
mov    %ecx,(%rax)
jmp    1177 <tty_set_stopbits+0x77>
mov    0x2e7b(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
jmp    1177 <tty_set_stopbits+0x77>
xor    %eax,%eax
mov    0x2e73(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    117e <tty_set_stopbits+0x7e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_set_stopbits>:
movsbl (%rsi),%eax
cmp    $0x32,%eax
je     111d <tty_set_stopbits+0x1d>
cmp    $0x31,%eax
jne    112b <tty_set_stopbits+0x2b>
mov    0x2ebc(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,(%rdi)
xor    %eax,%eax
ret
mov    0x2eac(%rip),%rax
mov    (%rax),%eax
or     %eax,(%rdi)
xor    %eax,%eax
ret
mov    0x2eae(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@CSTOPB = global i32 0
@EINVAL = global i32 0
define i32 @tty_set_stopbits(%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 i8*, i8** %5
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
switch i32 %8, label %22 [
i32 49, label %9
i32 50, label %16
]
9: ; preds = %2
%10 = load i32, i32* @CSTOPB
%11 = xor i32 %10, -1
%12 = load %struct.termios*, %struct.termios** %4
%13 = getelementptr inbounds %struct.termios, %struct.termios* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = and i32 %14, %11
store i32 %15, i32* %13
br label %25
16: ; preds = %2
%17 = load i32, i32* @CSTOPB
%18 = load %struct.termios*, %struct.termios** %4
%19 = getelementptr inbounds %struct.termios, %struct.termios* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = or i32 %20, %17
store i32 %21, i32* %19
br label %25
22: ; preds = %2
%23 = load i32, i32* @EINVAL
%24 = sub nsw i32 0, %23
store i32 %24, i32* %3
br label %26
25: ; preds = %16, %9
store i32 0, i32* %3
br label %26
26: ; preds = %25, %22
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@CSTOPB = global i32 0
@EINVAL = global i32 0
define i32 @tty_set_stopbits(%struct.termios* nocapture %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = sext i8 %3 to i32
switch i32 %4, label %16 [
i32 49, label %5
i32 50, label %11
]
5: ; preds = %2
%6 = load i32, i32* @CSTOPB
%7 = xor i32 %6, -1
%8 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 0
%9 = load i32, i32* %8
%10 = and i32 %9, %7
store i32 %10, i32* %8
br label %19
11: ; preds = %2
%12 = load i32, i32* @CSTOPB
%13 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 0
%14 = load i32, i32* %13
%15 = or i32 %14, %12
store i32 %15, i32* %13
br label %19
16: ; preds = %2
%17 = load i32, i32* @EINVAL
%18 = sub nsw i32 0, %17
br label %19
19: ; preds = %5, %11, %16
%20 = phi i32 [ %18, %16 ], [ 0, %11 ], [ 0, %5 ]
ret i32 %20
}