#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;
  int c_lflag;
  int *c_cc;
  int /*<<< orphan*/ c_oflag;
};
typedef int /*<<< orphan*/ opt;

/* Variables and functions */
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int ICANON;
int ISIG;
int /*<<< orphan*/ OPOST;
int PARENB;
int /*<<< orphan*/ TCIOFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ bzero(struct termios *, int);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int uart_init_taximeter(int fd) {
  int ret;
  struct termios opt;
  bzero(&opt, sizeof(opt));
  tcgetattr(fd, &opt);
  opt.c_cflag |= (CLOCAL | CREAD);
  opt.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  opt.c_oflag &= ~OPOST;
  cfsetispeed(&opt, B9600);
  cfsetospeed(&opt, B9600);
  opt.c_cflag &= ~CSIZE;
  opt.c_cflag |= CS8;
  opt.c_cflag &= ~PARENB;
  opt.c_cflag &= ~CSTOPB;
  opt.c_cc[VTIME] = 150;
  opt.c_cc[VMIN] = 0;
  tcflush(fd, TCIOFLUSH);
  ret = tcsetattr(fd, TCSANOW, &opt);
  if (ret != 0) {
    printf("tc set attr failed: %s\n", strerror(errno));
    return -1;
  }
  tcflush(fd, TCIOFLUSH);
  return 0;
}


x86 assembly (clang, -O0):
<uart_init_taximeter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0x18,%esi
call   1090 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    0x2dfb(%rip),%rcx
or     (%rcx),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    0x2e03(%rip),%rcx
or     (%rcx),%eax
mov    0x2df2(%rip),%rcx
or     (%rcx),%eax
mov    0x2de1(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d06(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2d08(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x96,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2d1b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x8(%rbp),%edi
mov    0x2ce7(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x8(%rbp),%edi
mov    0x2d2e(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     12eb <uart_init_taximeter+0x16b>
mov    0x2cbf(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xd26(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <uart_init_taximeter+0x183>
mov    -0x8(%rbp),%edi
mov    0x2c8b(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_init_taximeter>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x18,%esi
call   1090 <bzero@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1060 <tcgetattr@plt>
mov    0x2dab(%rip),%rax
mov    0x2dfc(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     %ecx,(%rsp)
mov    0x2dae(%rip),%rax
mov    0x2e07(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2df4(%rip),%rax
or     (%rax),%ecx
mov    0x2de3(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x10(%rsp)
mov    0x2dbd(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1080 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%eax
not    %eax
and    (%rsp),%eax
mov    0x2d84(%rip),%rcx
or     (%rcx),%eax
mov    0x2db3(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d2a(%rip),%rdx
or     (%rdx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,(%rsp)
mov    0x8(%rsp),%rax
mov    0x2d2d(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x96,(%rax,%rcx,4)
mov    0x2d44(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d13(%rip),%r15
mov    (%r15),%esi
mov    %ebp,%edi
call   1040 <tcflush@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1070 <tcsetattr@plt>
test   %eax,%eax
je     12b2 <uart_init_taximeter+0x132>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd5d(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    $0xffffffff,%eax
jmp    12be <uart_init_taximeter+0x13e>
mov    (%r15),%esi
mov    %ebp,%edi
call   1040 <tcflush@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32*, i32 }
@CLOCAL = global i32 0
@CREAD = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@B9600 = 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
@TCIOFLUSH = global i32 0
@TCSANOW = global i32 0
@.str = [24 x i8] c"tc set attr failed: %s\0A\00"
@errno = global i32 0
define i32 @uart_init_taximeter(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.termios
store i32 %0, i32* %3
%6 = call i32 @bzero(%struct.termios* %5, i32 24)
%7 = load i32, i32* %3
%8 = call i32 @tcgetattr(i32 %7, %struct.termios* %5)
%9 = load i32, i32* @CLOCAL
%10 = load i32, i32* @CREAD
%11 = or i32 %9, %10
%12 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%13 = load i32, i32* %12
%14 = or i32 %13, %11
store i32 %14, i32* %12
%15 = load i32, i32* @ICANON
%16 = load i32, i32* @ECHO
%17 = or i32 %15, %16
%18 = load i32, i32* @ECHOE
%19 = or i32 %17, %18
%20 = load i32, i32* @ISIG
%21 = or i32 %19, %20
%22 = xor i32 %21, -1
%23 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 1
%24 = load i32, i32* %23
%25 = and i32 %24, %22
store i32 %25, i32* %23
%26 = load i32, i32* @OPOST
%27 = xor i32 %26, -1
%28 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 3
%29 = load i32, i32* %28
%30 = and i32 %29, %27
store i32 %30, i32* %28
%31 = load i32, i32* @B9600
%32 = call i32 @cfsetispeed(%struct.termios* %5, i32 %31)
%33 = load i32, i32* @B9600
%34 = call i32 @cfsetospeed(%struct.termios* %5, i32 %33)
%35 = load i32, i32* @CSIZE
%36 = xor i32 %35, -1
%37 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%38 = load i32, i32* %37
%39 = and i32 %38, %36
store i32 %39, i32* %37
%40 = load i32, i32* @CS8
%41 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%42 = load i32, i32* %41
%43 = or i32 %42, %40
store i32 %43, i32* %41
%44 = load i32, i32* @PARENB
%45 = xor i32 %44, -1
%46 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%47 = load i32, i32* %46
%48 = and i32 %47, %45
store i32 %48, i32* %46
%49 = load i32, i32* @CSTOPB
%50 = xor i32 %49, -1
%51 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%52 = load i32, i32* %51
%53 = and i32 %52, %50
store i32 %53, i32* %51
%54 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 2
%55 = load i32*, i32** %54
%56 = load i64, i64* @VTIME
%57 = getelementptr inbounds i32, i32* %55, i64 %56
store i32 150, i32* %57
%58 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 2
%59 = load i32*, i32** %58
%60 = load i64, i64* @VMIN
%61 = getelementptr inbounds i32, i32* %59, i64 %60
store i32 0, i32* %61
%62 = load i32, i32* %3
%63 = load i32, i32* @TCIOFLUSH
%64 = call i32 @tcflush(i32 %62, i32 %63)
%65 = load i32, i32* %3
%66 = load i32, i32* @TCSANOW
%67 = call i32 @tcsetattr(i32 %65, i32 %66, %struct.termios* %5)
store i32 %67, i32* %4
%68 = load i32, i32* %4
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %1
%71 = load i32, i32* @errno
%72 = call i8* @strerror(i32 %71)
%73 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %72)
store i32 -1, i32* %2
br label %78
74: ; preds = %1
%75 = load i32, i32* %3
%76 = load i32, i32* @TCIOFLUSH
%77 = call i32 @tcflush(i32 %75, i32 %76)
store i32 0, i32* %2
br label %78
78: ; preds = %74, %70
%79 = load i32, i32* %2
ret i32 %79
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32*, i32 }
@CLOCAL = global i32 0
@CREAD = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@B9600 = 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
@TCIOFLUSH = global i32 0
@TCSANOW = global i32 0
@.str = [24 x i8] c"tc set attr failed: %s\0A\00"
@errno = global i32 0
define i32 @uart_init_taximeter(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @bzero(%struct.termios* %2, i32 24)
%5 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%6 = load i32, i32* @CLOCAL
%7 = load i32, i32* @CREAD
%8 = or i32 %7, %6
%9 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = or i32 %8, %10
store i32 %11, i32* %9
%12 = load i32, i32* @ICANON
%13 = load i32, i32* @ECHO
%14 = or i32 %13, %12
%15 = load i32, i32* @ECHOE
%16 = or i32 %14, %15
%17 = load i32, i32* @ISIG
%18 = or i32 %16, %17
%19 = xor i32 %18, -1
%20 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%21 = load i32, i32* %20
%22 = and i32 %21, %19
store i32 %22, i32* %20
%23 = load i32, i32* @OPOST
%24 = xor i32 %23, -1
%25 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%26 = load i32, i32* %25
%27 = and i32 %26, %24
store i32 %27, i32* %25
%28 = load i32, i32* @B9600
%29 = call i32 @cfsetispeed(%struct.termios* %2, i32 %28)
%30 = load i32, i32* @B9600
%31 = call i32 @cfsetospeed(%struct.termios* %2, i32 %30)
%32 = load i32, i32* @CSIZE
%33 = xor i32 %32, -1
%34 = load i32, i32* %9
%35 = and i32 %34, %33
%36 = load i32, i32* @CS8
%37 = or i32 %36, %35
%38 = load i32, i32* @PARENB
%39 = load i32, i32* @CSTOPB
%40 = or i32 %38, %39
%41 = xor i32 %40, -1
%42 = and i32 %37, %41
store i32 %42, i32* %9
%43 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%44 = load i32*, i32** %43
%45 = load i64, i64* @VTIME
%46 = getelementptr inbounds i32, i32* %44, i64 %45
store i32 150, i32* %46
%47 = load i64, i64* @VMIN
%48 = getelementptr inbounds i32, i32* %44, i64 %47
store i32 0, i32* %48
%49 = load i32, i32* @TCIOFLUSH
%50 = call i32 @tcflush(i32 %0, i32 %49)
%51 = load i32, i32* @TCSANOW
%52 = call i32 @tcsetattr(i32 %0, i32 %51, %struct.termios* %2)
%53 = icmp eq i32 %52, 0
br i1 %53, label %58, label %54
54: ; preds = %1
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %56)
br label %61
58: ; preds = %1
%59 = load i32, i32* @TCIOFLUSH
%60 = call i32 @tcflush(i32 %0, i32 %59)
br label %61
61: ; preds = %58, %54
%62 = phi i32 [ -1, %54 ], [ 0, %58 ]
ret i32 %62
}