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

/* Variables and functions */
int O_NOCTTY;
int O_RDWR;
int open(char const *, int);
int /*<<< orphan*/ serial_setup_tio(int);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int serial_open(const char *fn, struct termios *tio_saved) {
  int fd;
  fd = open(fn, O_RDWR | O_NOCTTY);
  if (fd < 0)
    return fd;
  tcgetattr(fd, tio_saved);
  serial_setup_tio(fd);
  return fd;
}


x86 assembly (clang, -O0):
<serial_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
mov    0x2e84(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1173 <serial_open+0x43>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118d <serial_open+0x5d>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    -0x1c(%rbp),%edi
call   1030 <serial_setup_tio@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_open>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2eab(%rip),%rax
mov    0x2e94(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1164 <serial_open+0x34>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <tcgetattr@plt>
mov    %ebp,%edi
call   1030 <serial_setup_tio@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
define i32 @serial_open(i8* %0, %struct.termios* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.termios*
%6 = alloca i32
store i8* %0, i8** %4
store %struct.termios* %1, %struct.termios** %5
%7 = load i8*, i8** %4
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_NOCTTY
%10 = or i32 %8, %9
%11 = call i32 @open(i8* %7, i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* %6
store i32 %15, i32* %3
br label %23
16: ; preds = %2
%17 = load i32, i32* %6
%18 = load %struct.termios*, %struct.termios** %5
%19 = call i32 @tcgetattr(i32 %17, %struct.termios* %18)
%20 = load i32, i32* %6
%21 = call i32 @serial_setup_tio(i32 %20)
%22 = load i32, i32* %6
store i32 %22, i32* %3
br label %23
23: ; preds = %16, %14
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
define i32 @serial_open(i8* nocapture %0, %struct.termios* %1) {
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_NOCTTY
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @tcgetattr(i32 %6, %struct.termios* %1)
%10 = tail call i32 @serial_setup_tio(i32 %6)
br label %11
11: ; preds = %2, %8
ret i32 %6
}