#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 /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
char *strchr(char const *, char);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void setup_term(int fd, const char *termtype) {
  char *x;
  struct termios tt;
  tcgetattr(fd, &tt);
  if ((x = strchr(termtype, '/')) != NULL) {
    *x++ = '\0';
    cfsetispeed(&tt, atoi(x));
    cfsetospeed(&tt, atoi(x));
  }
  tcsetattr(fd, TCSAFLUSH, &tt);
}


x86 assembly (clang, -O0):
<setup_term>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11d1 <setup_term+0x71>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%esi
lea    -0x20(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    -0x18(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%esi
lea    -0x20(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x4(%rbp),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1060 <tcsetattr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_term>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x8(%rsp),%rsi
call   1050 <tcgetattr@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11bc <setup_term+0x5c>
mov    %rax,%rbx
add    $0x1,%rbx
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1080 <atoi@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1070 <cfsetispeed@plt>
mov    %rbx,%rdi
call   1080 <atoi@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <cfsetospeed@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1060 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@TCSAFLUSH = global i32 0
define void @setup_term(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.termios
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i32, i32* %3
%8 = call i32 @tcgetattr(i32 %7, %struct.termios* %6)
%9 = load i8*, i8** %4
%10 = call i8* @strchr(i8* %9, i8 signext 47)
store i8* %10, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %5
store i8 0, i8* %13
%15 = load i8*, i8** %5
%16 = call i32 @atoi(i8* %15)
%17 = call i32 @cfsetispeed(%struct.termios* %6, i32 %16)
%18 = load i8*, i8** %5
%19 = call i32 @atoi(i8* %18)
%20 = call i32 @cfsetospeed(%struct.termios* %6, i32 %19)
br label %21
21: ; preds = %12, %2
%22 = load i32, i32* %3
%23 = load i32, i32* @TCSAFLUSH
%24 = call i32 @tcsetattr(i32 %22, i32 %23, %struct.termios* %6)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@TCSAFLUSH = global i32 0
define void @setup_term(i32 %0, i8* %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%6 = call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 47)
%7 = icmp eq i8* %6, null
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %6, i64 1
store i8 0, i8* %6
%10 = call i32 @atoi(i8* %9)
%11 = call i32 @cfsetispeed(%struct.termios* %3, i32 %10)
%12 = call i32 @atoi(i8* %9)
%13 = call i32 @cfsetospeed(%struct.termios* %3, i32 %12)
br label %14
14: ; preds = %8, %2
%15 = load i32, i32* @TCSAFLUSH
%16 = call i32 @tcsetattr(i32 %0, i32 %15, %struct.termios* %3)
ret void
}