#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 *c_cc;
  int /*<<< orphan*/ c_cflag;
};

/* Variables and functions */
int /*<<< orphan*/ B9600;
int /*<<< orphan*/ CS8;
int /*<<< orphan*/ CSIZE;
int /*<<< orphan*/ CSTOPB;
int /*<<< orphan*/ INPCK;
int /*<<< orphan*/ PARENB;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int set_com_config(int sfd, struct termios *config) {
  cfmakeraw(config);
  config->c_cflag &= ~CSIZE;
  config->c_cflag &= ~CSTOPB;
  config->c_cflag &= ~PARENB;
  config->c_cflag &= ~INPCK;
  config->c_cflag |= CS8;
  cfsetispeed(config, B9600);
  cfsetospeed(config, B9600);
  config->c_cc[VTIME] = 0;
  config->c_cc[VMIN] = 1;
  tcflush(sfd, TCIFLUSH);
  if ((tcsetattr(sfd, TCSANOW, config) != 0)) {
    perror("sfd set:");
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<set_com_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <cfmakeraw@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x10(%rbp),%rax
and    0x8(%rax),%ecx
mov    %ecx,0x8(%rax)
mov    0x2deb(%rip),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x10(%rbp),%rax
and    0x8(%rax),%ecx
mov    %ecx,0x8(%rax)
mov    0x2e2d(%rip),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x10(%rbp),%rax
and    0x8(%rax),%ecx
mov    %ecx,0x8(%rax)
mov    0x2dd7(%rip),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x10(%rbp),%rax
and    0x8(%rax),%ecx
mov    %ecx,0x8(%rax)
mov    0x2de9(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
or     0x8(%rax),%ecx
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rdi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
call   1070 <cfsetispeed@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
call   1030 <cfsetospeed@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2d7b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2d8b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%edi
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x8(%rbp),%edi
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
je     128d <set_com_config+0x11d>
lea    0xd82(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_com_config>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
call   1050 <cfmakeraw@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    0x2dfe(%rip),%rcx
or     (%rcx),%eax
mov    0x2e4d(%rip),%rcx
or     (%rcx),%eax
mov    0x2e04(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    0x8(%rbx),%eax
mov    0x2e1e(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x8(%rbx)
mov    0x2e1a(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1070 <cfsetispeed@plt>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1030 <cfsetospeed@plt>
mov    (%rbx),%rax
mov    0x2dc2(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2dd9(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1040 <tcflush@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1060 <tcsetattr@plt>
test   %rax,%rax
jne    1228 <set_com_config+0xb8>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdd1(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32*, i32 }
@CSIZE = global i32 0
@CSTOPB = global i32 0
@PARENB = global i32 0
@INPCK = global i32 0
@CS8 = global i32 0
@B9600 = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@.str = [9 x i8] c"sfd set:\00"
define i32 @set_com_config(i32 %0, %struct.termios* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.termios*
store i32 %0, i32* %4
store %struct.termios* %1, %struct.termios** %5
%6 = load %struct.termios*, %struct.termios** %5
%7 = call i32 @cfmakeraw(%struct.termios* %6)
%8 = load i32, i32* @CSIZE
%9 = xor i32 %8, -1
%10 = load %struct.termios*, %struct.termios** %5
%11 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 1
%12 = load i32, i32* %11
%13 = and i32 %12, %9
store i32 %13, i32* %11
%14 = load i32, i32* @CSTOPB
%15 = xor i32 %14, -1
%16 = load %struct.termios*, %struct.termios** %5
%17 = getelementptr inbounds %struct.termios, %struct.termios* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = and i32 %18, %15
store i32 %19, i32* %17
%20 = load i32, i32* @PARENB
%21 = xor i32 %20, -1
%22 = load %struct.termios*, %struct.termios** %5
%23 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = and i32 %24, %21
store i32 %25, i32* %23
%26 = load i32, i32* @INPCK
%27 = xor i32 %26, -1
%28 = load %struct.termios*, %struct.termios** %5
%29 = getelementptr inbounds %struct.termios, %struct.termios* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = and i32 %30, %27
store i32 %31, i32* %29
%32 = load i32, i32* @CS8
%33 = load %struct.termios*, %struct.termios** %5
%34 = getelementptr inbounds %struct.termios, %struct.termios* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = or i32 %35, %32
store i32 %36, i32* %34
%37 = load %struct.termios*, %struct.termios** %5
%38 = load i32, i32* @B9600
%39 = call i32 @cfsetispeed(%struct.termios* %37, i32 %38)
%40 = load %struct.termios*, %struct.termios** %5
%41 = load i32, i32* @B9600
%42 = call i32 @cfsetospeed(%struct.termios* %40, i32 %41)
%43 = load %struct.termios*, %struct.termios** %5
%44 = getelementptr inbounds %struct.termios, %struct.termios* %43, i32 0, i32 0
%45 = load i32*, i32** %44
%46 = load i64, i64* @VTIME
%47 = getelementptr inbounds i32, i32* %45, i64 %46
store i32 0, i32* %47
%48 = load %struct.termios*, %struct.termios** %5
%49 = getelementptr inbounds %struct.termios, %struct.termios* %48, i32 0, i32 0
%50 = load i32*, i32** %49
%51 = load i64, i64* @VMIN
%52 = getelementptr inbounds i32, i32* %50, i64 %51
store i32 1, i32* %52
%53 = load i32, i32* %4
%54 = load i32, i32* @TCIFLUSH
%55 = call i32 @tcflush(i32 %53, i32 %54)
%56 = load i32, i32* %4
%57 = load i32, i32* @TCSANOW
%58 = load %struct.termios*, %struct.termios** %5
%59 = call i64 @tcsetattr(i32 %56, i32 %57, %struct.termios* %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %2
%62 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%63 = call i32 @exit(i32 -1)
unreachable
64: ; preds = %2
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
%struct.termios = type { i32*, i32 }
@CSIZE = global i32 0
@CSTOPB = global i32 0
@PARENB = global i32 0
@INPCK = global i32 0
@CS8 = global i32 0
@B9600 = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@.str = [9 x i8] c"sfd set:\00"
define i32 @set_com_config(i32 %0, %struct.termios* %1) {
%3 = tail call i32 @cfmakeraw(%struct.termios* %1)
%4 = load i32, i32* @CSIZE
%5 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 1
%6 = load i32, i32* %5
%7 = load i32, i32* @CSTOPB
%8 = or i32 %4, %7
%9 = load i32, i32* @PARENB
%10 = or i32 %8, %9
%11 = load i32, i32* @INPCK
%12 = or i32 %10, %11
%13 = xor i32 %12, -1
%14 = and i32 %6, %13
%15 = load i32, i32* @CS8
%16 = or i32 %15, %14
store i32 %16, i32* %5
%17 = load i32, i32* @B9600
%18 = tail call i32 @cfsetispeed(%struct.termios* %1, i32 %17)
%19 = load i32, i32* @B9600
%20 = tail call i32 @cfsetospeed(%struct.termios* %1, i32 %19)
%21 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%22 = load i32*, i32** %21
%23 = load i64, i64* @VTIME
%24 = getelementptr inbounds i32, i32* %22, i64 %23
store i32 0, i32* %24
%25 = load i64, i64* @VMIN
%26 = getelementptr inbounds i32, i32* %22, i64 %25
store i32 1, i32* %26
%27 = load i32, i32* @TCIFLUSH
%28 = tail call i32 @tcflush(i32 %0, i32 %27)
%29 = load i32, i32* @TCSANOW
%30 = tail call i64 @tcsetattr(i32 %0, i32 %29, %struct.termios* %1)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %2
%33 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%34 = tail call i32 @exit(i32 -1)
unreachable
35: ; preds = %2
ret i32 undef
}