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

/* Variables and functions */
int ECHO;
int ECHOE;
int ICANON;
int ISIG;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int tcflush(int, int /*<<< orphan*/);
int tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int obd_serial_config(int fd) {
  struct termios options;
  if (tcgetattr(fd, &options) == -1) {
    fprintf(stderr, "%s: %s\n", "Error obtaining serial connection parameters",
            strerror(errno));
    return -1;
  }
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  if (tcflush(fd, TCIFLUSH) == -1) {
    fprintf(stderr, "%s: %s\n", "Error flushing serial connection input buffer",
            strerror(errno));
    return -1;
  }
  if (tcsetattr(fd, TCSANOW, &options) == -1) {
    fprintf(stderr, "%s: %s\n", "Error setting serial connection parameters",
            strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<obd_serial_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    11af <obd_serial_config+0x5f>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rcx
lea    0xe69(%rip),%rsi
lea    0xe6a(%rip),%rdx
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <obd_serial_config+0x149>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
mov    0x2e21(%rip),%rcx
or     (%rcx),%eax
mov    0x2e10(%rip),%rcx
or     (%rcx),%eax
mov    0x2dff(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
cmp    $0xffffffff,%eax
jne    1235 <obd_serial_config+0xe5>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rcx
lea    0xde3(%rip),%rsi
lea    0xe11(%rip),%rdx
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <obd_serial_config+0x149>
mov    -0x8(%rbp),%edi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    1292 <obd_serial_config+0x142>
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rcx
lea    0xd86(%rip),%rsi
lea    0xde2(%rip),%rdx
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <obd_serial_config+0x149>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<obd_serial_config>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %rsp,%rsi
call   1050 <tcgetattr@plt>
cmp    $0xffffffff,%eax
je     11c5 <obd_serial_config+0x75>
mov    0x2e3f(%rip),%rax
mov    0x2e70(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e5d(%rip),%rax
or     (%rax),%ecx
mov    0x2e4c(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,(%rsp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1030 <tcflush@plt>
cmp    $0xffffffff,%eax
je     11ce <obd_serial_config+0x7e>
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1060 <tcsetattr@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1205 <obd_serial_config+0xb5>
lea    0xea0(%rip),%rbx
jmp    11d5 <obd_serial_config+0x85>
lea    0xe3c(%rip),%rbx
jmp    11d5 <obd_serial_config+0x85>
lea    0xe60(%rip),%rbx
mov    0x2ddc(%rip),%rax
mov    (%rax),%ebp
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe0d(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@stderr = global i32 0
@.str = [8 x i8] c"%s: %s\0A\00"
@.str.1 = [45 x i8] c"Error obtaining serial connection parameters\00"
@errno = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@TCIFLUSH = global i32 0
@.str.2 = [46 x i8] c"Error flushing serial connection input buffer\00"
@TCSANOW = global i32 0
@.str.3 = [43 x i8] c"Error setting serial connection parameters\00"
define i32 @obd_serial_config(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.termios
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @tcgetattr(i32 %5, %struct.termios* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %11)
store i32 -1, i32* %2
br label %45
13: ; preds = %1
%14 = load i32, i32* @ICANON
%15 = load i32, i32* @ECHO
%16 = or i32 %14, %15
%17 = load i32, i32* @ECHOE
%18 = or i32 %16, %17
%19 = load i32, i32* @ISIG
%20 = or i32 %18, %19
%21 = xor i32 %20, -1
%22 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%23 = load i32, i32* %22
%24 = and i32 %23, %21
store i32 %24, i32* %22
%25 = load i32, i32* %3
%26 = load i32, i32* @TCIFLUSH
%27 = call i32 @tcflush(i32 %25, i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %34
29: ; preds = %13
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* %32)
store i32 -1, i32* %2
br label %45
34: ; preds = %13
%35 = load i32, i32* %3
%36 = load i32, i32* @TCSANOW
%37 = call i32 @tcsetattr(i32 %35, i32 %36, %struct.termios* %4)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i8* %42)
store i32 -1, i32* %2
br label %45
44: ; preds = %34
store i32 0, i32* %2
br label %45
45: ; preds = %44, %39, %29, %8
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@stderr = global i32 0
@.str = [8 x i8] c"%s: %s\0A\00"
@.str.1 = [45 x i8] c"Error obtaining serial connection parameters\00"
@errno = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@TCIFLUSH = global i32 0
@.str.2 = [46 x i8] c"Error flushing serial connection input buffer\00"
@TCSANOW = global i32 0
@.str.3 = [43 x i8] c"Error setting serial connection parameters\00"
define i32 @obd_serial_config(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %25, label %6
6: ; preds = %1
%7 = load i32, i32* @ICANON
%8 = load i32, i32* @ECHO
%9 = or i32 %8, %7
%10 = load i32, i32* @ECHOE
%11 = or i32 %9, %10
%12 = load i32, i32* @ISIG
%13 = or i32 %11, %12
%14 = xor i32 %13, -1
%15 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%16 = load i32, i32* %15
%17 = and i32 %16, %14
store i32 %17, i32* %15
%18 = load i32, i32* @TCIFLUSH
%19 = call i32 @tcflush(i32 %0, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %25, label %21
21: ; preds = %6
%22 = load i32, i32* @TCSANOW
%23 = call i32 @tcsetattr(i32 %0, i32 %22, %struct.termios* %2)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %31
25: ; preds = %21, %6, %1
%26 = phi i8* [ getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), %1 ], [ getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), %6 ], [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), %21 ]
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %26, i8* %29)
br label %31
31: ; preds = %25, %21
%32 = phi i32 [ 0, %21 ], [ -1, %25 ]
ret i32 %32
}