#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 /*<<< orphan*/ c_cflag;
};
struct serial_struct {
  int /*<<< orphan*/ type;
};

/* Variables and functions */
int /*<<< orphan*/ CRTSCTS;
int /*<<< orphan*/ PORT_8250;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ TIOCGSERIAL;
int /*<<< orphan*/ TIOCSSERIAL;
int drv_generic_serial_open(char const *, char const *, unsigned int const);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct serial_struct *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int drv_generic_serial_open_handshake(const char *section, const char *driver,
                                      const unsigned int flags) {
  int fd;
  struct termios portset;
  struct serial_struct serinfo;
  fd = drv_generic_serial_open(section, driver, flags);
  tcgetattr(fd, &portset);
  portset.c_cflag |= CRTSCTS;
  tcsetattr(fd, TCSANOW, &portset);
  ioctl(fd, TIOCGSERIAL, &serinfo);
  serinfo.type = PORT_8250;
  ioctl(fd, TIOCSSERIAL, &serinfo);
  return fd;
}


x86 assembly (clang, -O0):
<drv_generic_serial_open_handshake>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <drv_generic_serial_open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    -0x18(%rbp),%edi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1030 <ioctl@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1030 <ioctl@plt>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drv_generic_serial_open_handshake>:
push   %r14
push   %rbx
sub    $0x18,%rsp
call   1060 <drv_generic_serial_open@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
call   1040 <tcgetattr@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
or     %eax,0x10(%rsp)
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
%struct.serial_struct = type { i32 }
@CRTSCTS = global i32 0
@TCSANOW = global i32 0
@TIOCGSERIAL = global i32 0
@PORT_8250 = global i32 0
@TIOCSSERIAL = global i32 0
define i32 @drv_generic_serial_open_handshake(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.termios
%9 = alloca %struct.serial_struct
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = call i32 @drv_generic_serial_open(i8* %10, i8* %11, i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = call i32 @tcgetattr(i32 %14, %struct.termios* %8)
%16 = load i32, i32* @CRTSCTS
%17 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%18 = load i32, i32* %17
%19 = or i32 %18, %16
store i32 %19, i32* %17
%20 = load i32, i32* %7
%21 = load i32, i32* @TCSANOW
%22 = call i32 @tcsetattr(i32 %20, i32 %21, %struct.termios* %8)
%23 = load i32, i32* %7
%24 = load i32, i32* @TIOCGSERIAL
%25 = call i32 @ioctl(i32 %23, i32 %24, %struct.serial_struct* %9)
%26 = load i32, i32* @PORT_8250
%27 = getelementptr inbounds %struct.serial_struct, %struct.serial_struct* %9, i32 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* %7
%29 = load i32, i32* @TIOCSSERIAL
%30 = call i32 @ioctl(i32 %28, i32 %29, %struct.serial_struct* %9)
%31 = load i32, i32* %7
ret i32 %31
}

LLVM IR (-O2):
%struct.termios = type { i32 }
%struct.serial_struct = type { i32 }
@CRTSCTS = global i32 0
@TCSANOW = global i32 0
@TIOCGSERIAL = global i32 0
@PORT_8250 = global i32 0
@TIOCSSERIAL = global i32 0
define i32 @drv_generic_serial_open_handshake(i8* %0, i8* %1, i32 %2) {
%4 = alloca %struct.termios
%5 = alloca %struct.serial_struct
%6 = bitcast %struct.termios* %4 to i8*
%7 = bitcast %struct.serial_struct* %5 to i8*
%8 = tail call i32 @drv_generic_serial_open(i8* %0, i8* %1, i32 %2)
%9 = call i32 @tcgetattr(i32 %8, %struct.termios* %4)
%10 = load i32, i32* @CRTSCTS
%11 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%12 = load i32, i32* %11
%13 = or i32 %12, %10
store i32 %13, i32* %11
%14 = load i32, i32* @TCSANOW
%15 = call i32 @tcsetattr(i32 %8, i32 %14, %struct.termios* %4)
%16 = load i32, i32* @TIOCGSERIAL
%17 = call i32 @ioctl(i32 %8, i32 %16, %struct.serial_struct* %5)
%18 = load i32, i32* @PORT_8250
%19 = getelementptr inbounds %struct.serial_struct, %struct.serial_struct* %5, i64 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* @TIOCSSERIAL
%21 = call i32 @ioctl(i32 %8, i32 %20, %struct.serial_struct* %5)
ret i32 %8
}