#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 */

/* Variables and functions */
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int open(char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int obd_serial_open(void) {
  int fd = -1;
  fd = open("/dev/pts/4", O_RDWR | O_NOCTTY);
  if (fd == -1) {
    fprintf(stderr, "%s: %s\n", "Error opening serial connection",
            strerror(errno));
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<obd_serial_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffffffff,-0x8(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
mov    0x2e89(%rip),%rax
or     (%rax),%esi
lea    0xea8(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11a9 <obd_serial_open+0x79>
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%rcx
lea    0xe7a(%rip),%rsi
lea    0xe7b(%rip),%rdx
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <obd_serial_open+0x7f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<obd_serial_open>:
push   %rbp
push   %rbx
push   %rax
mov    0x2eae(%rip),%rax
mov    0x2e97(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeb4(%rip),%rdi
call   1040 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1187 <obd_serial_open+0x57>
mov    0x2e71(%rip),%rax
mov    (%rax),%ebp
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe95(%rip),%rsi
lea    0xe96(%rip),%rdx
mov    %ebp,%edi
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/pts/4\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@stderr = global i32 0
@.str.1 = [8 x i8] c"%s: %s\0A\00"
@.str.2 = [32 x i8] c"Error opening serial connection\00"
@errno = global i32 0
define i32 @obd_serial_open() {
%1 = alloca i32
%2 = alloca i32
store i32 -1, i32* %2
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_NOCTTY
%5 = or i32 %3, %4
%6 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %12)
store i32 -1, i32* %1
br label %16
14: ; preds = %0
%15 = load i32, i32* %2
store i32 %15, i32* %1
br label %16
16: ; preds = %14, %9
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/pts/4\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@stderr = global i32 0
@.str.1 = [8 x i8] c"%s: %s\0A\00"
@.str.2 = [32 x i8] c"Error opening serial connection\00"
@errno = global i32 0
define i32 @obd_serial_open() {
%1 = load i32, i32* @O_RDWR
%2 = load i32, i32* @O_NOCTTY
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %0, %6
ret i32 %4
}