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

/* Variables and functions */
int /*<<< orphan*/ B115200;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ ICRNL;
int /*<<< orphan*/ INLCR;
int /*<<< orphan*/ OCRNL;
int /*<<< orphan*/ ONLCR;
int PARENB;
int PARODD;
int /*<<< orphan*/ TCIOFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int configure_tty(int tty_fd) {
  struct termios ttyio;
  memset(&ttyio, 0, sizeof(ttyio));
  fcntl(tty_fd, F_SETFL, 0);
  tcgetattr(tty_fd, &ttyio);
  cfsetispeed(&ttyio, B115200);
  cfsetospeed(&ttyio, B115200);
  ttyio.c_cflag |= (CLOCAL | CREAD);
  cfmakeraw(&ttyio);
  ttyio.c_cflag &= ~CSTOPB;
  ttyio.c_cflag &= ~(PARENB | PARODD);
  ttyio.c_cflag &= ~CSIZE;
  ttyio.c_cflag &= ~CRTSCTS;
  ttyio.c_cflag |= CS8;
  ttyio.c_iflag &= ~ICRNL;
  ttyio.c_iflag &= ~INLCR;
  ttyio.c_oflag &= ~OCRNL;
  ttyio.c_oflag &= ~ONLCR;
  ttyio.c_lflag &= ~ICANON;
  ttyio.c_lflag &= ~ECHO;
  ttyio.c_cc[VMIN] = 1;
  ttyio.c_cc[VTIME] = 5;
  tcflush(tty_fd, TCIOFLUSH);
  tcsetattr(tty_fd, TCSANOW, &ttyio);
  return 0;
}


x86 assembly (clang, -O0):
<configure_tty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    -0x4(%rbp),%edi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1080 <tcgetattr@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   10a0 <cfsetispeed@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    0x2dc2(%rip),%rcx
or     (%rcx),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
call   1070 <cfmakeraw@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    0x2d97(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d0b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d66(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2cd4(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2cb2(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d00(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2cca(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2c7d(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
mov    0x2c81(%rip),%rax
mov    (%rax),%esi
call   1050 <tcflush@plt>
mov    -0x4(%rbp),%edi
mov    0x2cb8(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1090 <tcsetattr@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<configure_tty>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1080 <tcgetattr@plt>
mov    0x2db9(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   10a0 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d66(%rip),%rax
mov    0x2dcf(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     %ecx,(%rsp)
mov    %r14,%rdi
call   1070 <cfmakeraw@plt>
mov    0x2d51(%rip),%rax
mov    0x2dd2(%rip),%rcx
mov    0x2db3(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
or     (%rax),%edx
mov    0x2d86(%rip),%rax
or     (%rax),%edx
mov    0x2d35(%rip),%rax
or     (%rax),%edx
not    %edx
and    (%rsp),%edx
mov    0x2d7f(%rip),%rax
or     (%rax),%edx
mov    %edx,(%rsp)
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    0x2d9a(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    %eax,0x18(%rsp)
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    0x2d1a(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    %eax,0x14(%rsp)
mov    0x2cfb(%rip),%rax
mov    (%rax),%eax
mov    0x2d52(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    %eax,0x10(%rsp)
mov    0x8(%rsp),%rax
mov    0x2d1e(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2cd5(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2cdc(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1050 <tcflush@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1090 <tcsetattr@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32*, i32, i32, i32 }
@F_SETFL = global i32 0
@B115200 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSTOPB = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSIZE = global i32 0
@CRTSCTS = global i32 0
@CS8 = global i32 0
@ICRNL = global i32 0
@INLCR = global i32 0
@OCRNL = global i32 0
@ONLCR = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCIOFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @configure_tty(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = call i32 @memset(%struct.termios* %3, i32 0, i32 32)
%5 = load i32, i32* %2
%6 = load i32, i32* @F_SETFL
%7 = call i32 @fcntl(i32 %5, i32 %6, i32 0)
%8 = load i32, i32* %2
%9 = call i32 @tcgetattr(i32 %8, %struct.termios* %3)
%10 = load i32, i32* @B115200
%11 = call i32 @cfsetispeed(%struct.termios* %3, i32 %10)
%12 = load i32, i32* @B115200
%13 = call i32 @cfsetospeed(%struct.termios* %3, i32 %12)
%14 = load i32, i32* @CLOCAL
%15 = load i32, i32* @CREAD
%16 = or i32 %14, %15
%17 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%18 = load i32, i32* %17
%19 = or i32 %18, %16
store i32 %19, i32* %17
%20 = call i32 @cfmakeraw(%struct.termios* %3)
%21 = load i32, i32* @CSTOPB
%22 = xor i32 %21, -1
%23 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%24 = load i32, i32* %23
%25 = and i32 %24, %22
store i32 %25, i32* %23
%26 = load i32, i32* @PARENB
%27 = load i32, i32* @PARODD
%28 = or i32 %26, %27
%29 = xor i32 %28, -1
%30 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%31 = load i32, i32* %30
%32 = and i32 %31, %29
store i32 %32, i32* %30
%33 = load i32, i32* @CSIZE
%34 = xor i32 %33, -1
%35 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%36 = load i32, i32* %35
%37 = and i32 %36, %34
store i32 %37, i32* %35
%38 = load i32, i32* @CRTSCTS
%39 = xor i32 %38, -1
%40 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%41 = load i32, i32* %40
%42 = and i32 %41, %39
store i32 %42, i32* %40
%43 = load i32, i32* @CS8
%44 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%45 = load i32, i32* %44
%46 = or i32 %45, %43
store i32 %46, i32* %44
%47 = load i32, i32* @ICRNL
%48 = xor i32 %47, -1
%49 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 4
%50 = load i32, i32* %49
%51 = and i32 %50, %48
store i32 %51, i32* %49
%52 = load i32, i32* @INLCR
%53 = xor i32 %52, -1
%54 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 4
%55 = load i32, i32* %54
%56 = and i32 %55, %53
store i32 %56, i32* %54
%57 = load i32, i32* @OCRNL
%58 = xor i32 %57, -1
%59 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%60 = load i32, i32* %59
%61 = and i32 %60, %58
store i32 %61, i32* %59
%62 = load i32, i32* @ONLCR
%63 = xor i32 %62, -1
%64 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%65 = load i32, i32* %64
%66 = and i32 %65, %63
store i32 %66, i32* %64
%67 = load i32, i32* @ICANON
%68 = xor i32 %67, -1
%69 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%70 = load i32, i32* %69
%71 = and i32 %70, %68
store i32 %71, i32* %69
%72 = load i32, i32* @ECHO
%73 = xor i32 %72, -1
%74 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%75 = load i32, i32* %74
%76 = and i32 %75, %73
store i32 %76, i32* %74
%77 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%78 = load i32*, i32** %77
%79 = load i64, i64* @VMIN
%80 = getelementptr inbounds i32, i32* %78, i64 %79
store i32 1, i32* %80
%81 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%82 = load i32*, i32** %81
%83 = load i64, i64* @VTIME
%84 = getelementptr inbounds i32, i32* %82, i64 %83
store i32 5, i32* %84
%85 = load i32, i32* %2
%86 = load i32, i32* @TCIOFLUSH
%87 = call i32 @tcflush(i32 %85, i32 %86)
%88 = load i32, i32* %2
%89 = load i32, i32* @TCSANOW
%90 = call i32 @tcsetattr(i32 %88, i32 %89, %struct.termios* %3)
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32, i32*, i32, i32, i32 }
@F_SETFL = global i32 0
@B115200 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSTOPB = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSIZE = global i32 0
@CRTSCTS = global i32 0
@CS8 = global i32 0
@ICRNL = global i32 0
@INLCR = global i32 0
@OCRNL = global i32 0
@ONLCR = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCIOFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @configure_tty(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @memset(%struct.termios* %2, i32 0, i32 32)
%5 = load i32, i32* @F_SETFL
%6 = call i32 @fcntl(i32 %0, i32 %5, i32 0)
%7 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%8 = load i32, i32* @B115200
%9 = call i32 @cfsetispeed(%struct.termios* %2, i32 %8)
%10 = load i32, i32* @B115200
%11 = call i32 @cfsetospeed(%struct.termios* %2, i32 %10)
%12 = load i32, i32* @CLOCAL
%13 = load i32, i32* @CREAD
%14 = or i32 %13, %12
%15 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%16 = load i32, i32* %15
%17 = or i32 %14, %16
store i32 %17, i32* %15
%18 = call i32 @cfmakeraw(%struct.termios* %2)
%19 = load i32, i32* @CSTOPB
%20 = load i32, i32* %15
%21 = load i32, i32* @PARENB
%22 = load i32, i32* @PARODD
%23 = or i32 %22, %21
%24 = or i32 %19, %23
%25 = load i32, i32* @CSIZE
%26 = or i32 %24, %25
%27 = load i32, i32* @CRTSCTS
%28 = or i32 %26, %27
%29 = xor i32 %28, -1
%30 = and i32 %20, %29
%31 = load i32, i32* @CS8
%32 = or i32 %31, %30
store i32 %32, i32* %15
%33 = load i32, i32* @ICRNL
%34 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 4
%35 = load i32, i32* %34
%36 = load i32, i32* @INLCR
%37 = or i32 %33, %36
%38 = xor i32 %37, -1
%39 = and i32 %35, %38
store i32 %39, i32* %34
%40 = load i32, i32* @OCRNL
%41 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%42 = load i32, i32* %41
%43 = load i32, i32* @ONLCR
%44 = or i32 %40, %43
%45 = xor i32 %44, -1
%46 = and i32 %42, %45
store i32 %46, i32* %41
%47 = load i32, i32* @ICANON
%48 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%49 = load i32, i32* %48
%50 = load i32, i32* @ECHO
%51 = or i32 %47, %50
%52 = xor i32 %51, -1
%53 = and i32 %49, %52
store i32 %53, i32* %48
%54 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%55 = load i32*, i32** %54
%56 = load i64, i64* @VMIN
%57 = getelementptr inbounds i32, i32* %55, i64 %56
store i32 1, i32* %57
%58 = load i64, i64* @VTIME
%59 = getelementptr inbounds i32, i32* %55, i64 %58
store i32 5, i32* %59
%60 = load i32, i32* @TCIOFLUSH
%61 = call i32 @tcflush(i32 %0, i32 %60)
%62 = load i32, i32* @TCSANOW
%63 = call i32 @tcsetattr(i32 %0, i32 %62, %struct.termios* %2)
ret i32 0
}