#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 scalar_t__ int32_t;

/* Variables and functions */
int O_NOCTTY;
int O_RDWR;
int O_SYNC;
scalar_t__ open(char *, int);
scalar_t__ serial_convertBaudRateToFlag(scalar_t__);
int /*<<< orphan*/ serial_set_interface(scalar_t__, scalar_t__, scalar_t__,
                                        scalar_t__, scalar_t__);
int32_t serial_setup(char *device, int32_t speed, int32_t parity,
                     int32_t rtscts, int32_t nbstop) {
  int32_t fd;
  int32_t speedFlags;
  fd = open(device, O_RDWR | O_NOCTTY | O_SYNC);
  if (fd >= 0) {
    speedFlags = serial_convertBaudRateToFlag(speed);
    serial_set_interface(fd, speedFlags, parity, rtscts, nbstop);
  }
  return fd;
}


x86 assembly (clang, -O0):
<serial_setup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
mov    0x2e70(%rip),%rax
or     (%rax),%esi
mov    0x2e77(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jl     11a5 <serial_setup+0x75>
mov    -0x10(%rbp),%rdi
call   1040 <serial_convertBaudRateToFlag@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1030 <serial_set_interface@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_setup>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    0x2ea8(%rip),%rbx
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
or     (%rbx),%eax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    0x2e82(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
call   1050 <open@plt>
mov    %rax,%rbx
test   %rax,%rax
js     118b <serial_setup+0x5b>
mov    %r13,%rdi
call   1040 <serial_convertBaudRateToFlag@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1030 <serial_set_interface@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_SYNC = global i32 0
define i64 @serial_setup(i8* %0, i64 %1, i64 %2, i64 %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i64 %3, i64* %9
store i64 %4, i64* %10
%13 = load i8*, i8** %6
%14 = load i32, i32* @O_RDWR
%15 = load i32, i32* @O_NOCTTY
%16 = or i32 %14, %15
%17 = load i32, i32* @O_SYNC
%18 = or i32 %16, %17
%19 = call i64 @open(i8* %13, i32 %18)
store i64 %19, i64* %11
%20 = load i64, i64* %11
%21 = icmp sge i64 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %5
%23 = load i64, i64* %7
%24 = call i64 @serial_convertBaudRateToFlag(i64 %23)
store i64 %24, i64* %12
%25 = load i64, i64* %11
%26 = load i64, i64* %12
%27 = load i64, i64* %8
%28 = load i64, i64* %9
%29 = load i64, i64* %10
%30 = call i32 @serial_set_interface(i64 %25, i64 %26, i64 %27, i64 %28, i64 %29)
br label %31
31: ; preds = %22, %5
%32 = load i64, i64* %11
ret i64 %32
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_SYNC = global i32 0
define i64 @serial_setup(i8* nocapture %0, i64 %1, i64 %2, i64 %3, i64 %4) {
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_NOCTTY
%8 = or i32 %7, %6
%9 = load i32, i32* @O_SYNC
%10 = or i32 %8, %9
%11 = tail call i64 @open(i8* %0, i32 %10)
%12 = icmp sgt i64 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %5
%14 = tail call i64 @serial_convertBaudRateToFlag(i64 %1)
%15 = tail call i32 @serial_set_interface(i64 %11, i64 %14, i64 %2, i64 %3, i64 %4)
br label %16
16: ; preds = %13, %5
ret i64 %11
}