#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 /*<<< orphan*/ tio;
struct termios {
  int c_cflag;
  int *c_cc;
  scalar_t__ c_lflag;
  scalar_t__ c_oflag;
  scalar_t__ c_iflag;
};

/* Variables and functions */
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void set_tty_speed(int tty) {
  struct termios tio;
  memset(&tio, 0, sizeof(tio));
  tio.c_iflag = 0;
  tio.c_oflag = 0;
  tio.c_cflag = CS8 | CREAD | CLOCAL;
  tio.c_lflag = 0;
  tio.c_cc[VMIN] = 1;
  tio.c_cc[VTIME] = 5;
  cfsetospeed(&tio, B9600);
  cfsetispeed(&tio, B9600);
  tcsetattr(tty, TCSANOW, &tio);
}


x86 assembly (clang, -O0):
<set_tty_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    0x2e5d(%rip),%rcx
or     (%rcx),%eax
mov    0x2e24(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e2c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2e07(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1060 <cfsetispeed@plt>
mov    -0x4(%rbp),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1050 <tcsetattr@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_tty_speed>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %edi,%r14d
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0x2e6a(%rip),%rax
mov    0x2e6b(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xorps  %xmm0,%xmm0
mov    0x2e2d(%rip),%rax
or     (%rax),%ecx
movups %xmm0,0x20(%rsp)
mov    %ecx,0x8(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2e2d(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2e0c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2e23(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1030 <cfsetospeed@plt>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1060 <cfsetispeed@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1050 <tcsetattr@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32*, i64, i64, i64 }
@CS8 = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@B9600 = global i32 0
@TCSANOW = global i32 0
define void @set_tty_speed(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = call i32 @memset(%struct.termios* %3, i32 0, i32 40)
%5 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 4
store i64 0, i64* %5
%6 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
store i64 0, i64* %6
%7 = load i32, i32* @CS8
%8 = load i32, i32* @CREAD
%9 = or i32 %7, %8
%10 = load i32, i32* @CLOCAL
%11 = or i32 %9, %10
%12 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
store i64 0, i64* %13
%14 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%15 = load i32*, i32** %14
%16 = load i64, i64* @VMIN
%17 = getelementptr inbounds i32, i32* %15, i64 %16
store i32 1, i32* %17
%18 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%19 = load i32*, i32** %18
%20 = load i64, i64* @VTIME
%21 = getelementptr inbounds i32, i32* %19, i64 %20
store i32 5, i32* %21
%22 = load i32, i32* @B9600
%23 = call i32 @cfsetospeed(%struct.termios* %3, i32 %22)
%24 = load i32, i32* @B9600
%25 = call i32 @cfsetispeed(%struct.termios* %3, i32 %24)
%26 = load i32, i32* %2
%27 = load i32, i32* @TCSANOW
%28 = call i32 @tcsetattr(i32 %26, i32 %27, %struct.termios* %3)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32*, i64, i64, i64 }
@CS8 = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@B9600 = global i32 0
@TCSANOW = global i32 0
define void @set_tty_speed(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @memset(%struct.termios* %2, i32 0, i32 40)
%5 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%6 = bitcast i64* %5 to i8*
%7 = load i32, i32* @CS8
%8 = load i32, i32* @CREAD
%9 = or i32 %8, %7
%10 = load i32, i32* @CLOCAL
%11 = or i32 %9, %10
%12 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
store i64 0, i64* %13
%14 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%15 = load i32*, i32** %14
%16 = load i64, i64* @VMIN
%17 = getelementptr inbounds i32, i32* %15, i64 %16
store i32 1, i32* %17
%18 = load i64, i64* @VTIME
%19 = getelementptr inbounds i32, i32* %15, i64 %18
store i32 5, i32* %19
%20 = load i32, i32* @B9600
%21 = call i32 @cfsetospeed(%struct.termios* %2, i32 %20)
%22 = load i32, i32* @B9600
%23 = call i32 @cfsetispeed(%struct.termios* %2, i32 %22)
%24 = load i32, i32* @TCSANOW
%25 = call i32 @tcsetattr(i32 %0, i32 %24, %struct.termios* %2)
ret void
}