#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*/ termios_new;
struct termios {
  int c_cflag;
  int *c_cc;
};

/* Variables and functions */
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CS8;
int CSIZE;
int CSTOPB;
int PARENB;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ bzero(struct termios *, int);
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void init_tty(int fd) {
  struct termios termios_new;
  bzero(&termios_new, sizeof(termios_new));
  cfmakeraw(&termios_new);
  cfsetispeed(&termios_new, B9600);
  cfsetospeed(&termios_new, B9600);
  termios_new.c_cflag |= CLOCAL | CREAD;
  termios_new.c_cflag &= ~CSIZE;
  termios_new.c_cflag |= CS8;
  termios_new.c_cflag &= ~PARENB;
  termios_new.c_cflag &= ~CSTOPB;
  termios_new.c_cc[VTIME] = 0;
  termios_new.c_cc[VMIN] = 1;
  tcflush(fd, TCIFLUSH);
  if (tcsetattr(fd, TCSANOW, &termios_new))
    printf("Setting the serial1 failed!\n");
}


x86 assembly (clang, -O0):
<init_tty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x10,%esi
call   1090 <bzero@plt>
lea    -0x18(%rbp),%rdi
call   1060 <cfmakeraw@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    0x2e0a(%rip),%rcx
or     (%rcx),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d82(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    0x2d8d(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x4(%rbp),%edi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0x0,%rax
je     1279 <init_tty+0x109>
lea    0xd8c(%rip),%rdi
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_tty>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x10,%esi
call   1090 <bzero@plt>
mov    %r14,%rdi
call   1060 <cfmakeraw@plt>
mov    0x2e3f(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1080 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <cfsetospeed@plt>
mov    0x2dd4(%rip),%rax
mov    0x2e15(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2def(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
mov    0x2df2(%rip),%rcx
or     (%rcx),%eax
mov    0x2e09(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2da8(%rip),%rdx
or     (%rdx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,(%rsp)
mov    0x8(%rsp),%rax
mov    0x2da3(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2db2(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2d89(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1050 <tcflush@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1070 <tcsetattr@plt>
test   %rax,%rax
je     124c <init_tty+0xdc>
lea    0xdb9(%rip),%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32* }
@B9600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@.str = [29 x i8] c"Setting the serial1 failed!\0A\00"
define void @init_tty(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = call i32 @bzero(%struct.termios* %3, i32 16)
%5 = call i32 @cfmakeraw(%struct.termios* %3)
%6 = load i32, i32* @B9600
%7 = call i32 @cfsetispeed(%struct.termios* %3, i32 %6)
%8 = load i32, i32* @B9600
%9 = call i32 @cfsetospeed(%struct.termios* %3, i32 %8)
%10 = load i32, i32* @CLOCAL
%11 = load i32, i32* @CREAD
%12 = or i32 %10, %11
%13 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%14 = load i32, i32* %13
%15 = or i32 %14, %12
store i32 %15, i32* %13
%16 = load i32, i32* @CSIZE
%17 = xor i32 %16, -1
%18 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%19 = load i32, i32* %18
%20 = and i32 %19, %17
store i32 %20, i32* %18
%21 = load i32, i32* @CS8
%22 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%23 = load i32, i32* %22
%24 = or i32 %23, %21
store i32 %24, i32* %22
%25 = load i32, i32* @PARENB
%26 = xor i32 %25, -1
%27 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%28 = load i32, i32* %27
%29 = and i32 %28, %26
store i32 %29, i32* %27
%30 = load i32, i32* @CSTOPB
%31 = xor i32 %30, -1
%32 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%33 = load i32, i32* %32
%34 = and i32 %33, %31
store i32 %34, i32* %32
%35 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%36 = load i32*, i32** %35
%37 = load i64, i64* @VTIME
%38 = getelementptr inbounds i32, i32* %36, i64 %37
store i32 0, i32* %38
%39 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%40 = load i32*, i32** %39
%41 = load i64, i64* @VMIN
%42 = getelementptr inbounds i32, i32* %40, i64 %41
store i32 1, i32* %42
%43 = load i32, i32* %2
%44 = load i32, i32* @TCIFLUSH
%45 = call i32 @tcflush(i32 %43, i32 %44)
%46 = load i32, i32* %2
%47 = load i32, i32* @TCSANOW
%48 = call i64 @tcsetattr(i32 %46, i32 %47, %struct.termios* %3)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %1
%51 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %52
52: ; preds = %50, %1
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32* }
@B9600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@str = [28 x i8] c"Setting the serial1 failed!\00"
define void @init_tty(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @bzero(%struct.termios* %2, i32 16)
%5 = call i32 @cfmakeraw(%struct.termios* %2)
%6 = load i32, i32* @B9600
%7 = call i32 @cfsetispeed(%struct.termios* %2, i32 %6)
%8 = load i32, i32* @B9600
%9 = call i32 @cfsetospeed(%struct.termios* %2, i32 %8)
%10 = load i32, i32* @CLOCAL
%11 = load i32, i32* @CREAD
%12 = or i32 %11, %10
%13 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%14 = load i32, i32* %13
%15 = or i32 %12, %14
%16 = load i32, i32* @CSIZE
%17 = xor i32 %16, -1
%18 = and i32 %15, %17
%19 = load i32, i32* @CS8
%20 = or i32 %19, %18
%21 = load i32, i32* @PARENB
%22 = load i32, i32* @CSTOPB
%23 = or i32 %21, %22
%24 = xor i32 %23, -1
%25 = and i32 %20, %24
store i32 %25, i32* %13
%26 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%27 = load i32*, i32** %26
%28 = load i64, i64* @VTIME
%29 = getelementptr inbounds i32, i32* %27, i64 %28
store i32 0, i32* %29
%30 = load i64, i64* @VMIN
%31 = getelementptr inbounds i32, i32* %27, i64 %30
store i32 1, i32* %31
%32 = load i32, i32* @TCIFLUSH
%33 = call i32 @tcflush(i32 %0, i32 %32)
%34 = load i32, i32* @TCSANOW
%35 = call i64 @tcsetattr(i32 %0, i32 %34, %struct.termios* %2)
%36 = icmp eq i64 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %1
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %39
39: ; preds = %37, %1
ret void
}