#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;
};
typedef int /*<<< orphan*/ speed_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int sopen(const char *name, speed_t speed) {
  struct termios tios;
  int f;
  f = open(name, O_RDWR);
  tcgetattr(f, &tios);
  cfmakeraw(&tios);
  cfsetispeed(&tios, speed);
  cfsetospeed(&tios, speed);
  tcsetattr(f, TCSANOW, &tios);
  return f;
}


x86 assembly (clang, -O0):
<sopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1050 <tcgetattr@plt>
lea    -0x10(%rbp),%rdi
call   1040 <cfmakeraw@plt>
mov    -0xc(%rbp),%esi
lea    -0x10(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    -0xc(%rbp),%esi
lea    -0x10(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x14(%rbp),%edi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sopen>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <tcgetattr@plt>
mov    %rbx,%rdi
call   1040 <cfmakeraw@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1080 <cfsetispeed@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <cfsetospeed@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1060 <tcsetattr@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@O_RDWR = global i32 0
@TCSANOW = global i32 0
define i32 @sopen(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.termios
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = call i32 @tcgetattr(i32 %10, %struct.termios* %5)
%12 = call i32 @cfmakeraw(%struct.termios* %5)
%13 = load i32, i32* %4
%14 = call i32 @cfsetispeed(%struct.termios* %5, i32 %13)
%15 = load i32, i32* %4
%16 = call i32 @cfsetospeed(%struct.termios* %5, i32 %15)
%17 = load i32, i32* %6
%18 = load i32, i32* @TCSANOW
%19 = call i32 @tcsetattr(i32 %17, i32 %18, %struct.termios* %5)
%20 = load i32, i32* %6
ret i32 %20
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@O_RDWR = global i32 0
@TCSANOW = global i32 0
define i32 @sopen(i8* nocapture %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = call i32 @tcgetattr(i32 %6, %struct.termios* %3)
%8 = call i32 @cfmakeraw(%struct.termios* %3)
%9 = call i32 @cfsetispeed(%struct.termios* %3, i32 %1)
%10 = call i32 @cfsetospeed(%struct.termios* %3, i32 %1)
%11 = load i32, i32* @TCSANOW
%12 = call i32 @tcsetattr(i32 %6, i32 %11, %struct.termios* %3)
ret i32 %6
}