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

/* Variables and functions */
int CBAUD;
int tty_find_speed(char const *);
int tty_set_speed(struct termios *tty, const char *speed) {
  int code;
  if ((code = tty_find_speed(speed)) < 0)
    return code;
  tty->c_cflag &= ~CBAUD;
  tty->c_cflag |= code;
  return 0;
}


x86 assembly (clang, -O0):
<tty_set_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <tty_find_speed@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1140 <tty_set_speed+0x30>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1166 <tty_set_speed+0x56>
mov    0x2e91(%rip),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x10(%rbp),%rax
and    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_set_speed>:
push   %rbx
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <tty_find_speed@plt>
test   %eax,%eax
js     1133 <tty_set_speed+0x23>
mov    0x2eb1(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    (%rbx),%ecx
or     %eax,%ecx
mov    %ecx,(%rbx)
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@CBAUD = global i32 0
define i32 @tty_set_speed(%struct.termios* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.termios*
%5 = alloca i8*
%6 = alloca i32
store %struct.termios* %0, %struct.termios** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 @tty_find_speed(i8* %7)
store i32 %8, i32* %6
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i32, i32* %6
store i32 %11, i32* %3
br label %24
12: ; preds = %2
%13 = load i32, i32* @CBAUD
%14 = xor i32 %13, -1
%15 = load %struct.termios*, %struct.termios** %4
%16 = getelementptr inbounds %struct.termios, %struct.termios* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = and i32 %17, %14
store i32 %18, i32* %16
%19 = load i32, i32* %6
%20 = load %struct.termios*, %struct.termios** %4
%21 = getelementptr inbounds %struct.termios, %struct.termios* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = or i32 %22, %19
store i32 %23, i32* %21
store i32 0, i32* %3
br label %24
24: ; preds = %12, %10
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@CBAUD = global i32 0
define i32 @tty_set_speed(%struct.termios* nocapture %0, i8* %1) {
%3 = tail call i32 @tty_find_speed(i8* %1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = load i32, i32* @CBAUD
%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
%11 = or i32 %10, %3
store i32 %11, i32* %8
br label %12
12: ; preds = %2, %5
%13 = phi i32 [ 0, %5 ], [ %3, %2 ]
ret i32 %13
}