#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*/ O_RDWR;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int CommOpen(const char *devname) {
  int fd_com = open(devname, O_RDWR);
  if (fd_com < 0) {
    perror("open com dev\n");
    return -1;
  }
  struct termios opt;
  memset(&opt, 0, sizeof(struct termios));
  tcgetattr(fd_com, &opt);
  cfmakeraw(&opt);
  return fd_com;
}


x86 assembly (clang, -O0):
<CommOpen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1193 <CommOpen+0x43>
lea    0xe7e(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <CommOpen+0x6e>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <tcgetattr@plt>
lea    -0x18(%rbp),%rdi
call   1040 <cfmakeraw@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CommOpen>:
push   %r14
push   %rbx
push   %rax
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     1196 <CommOpen+0x46>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    %r14,%rdi
call   1040 <cfmakeraw@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe63(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%ebx
jmp    118c <CommOpen+0x3c>

LLVM IR (-O0):
%struct.termios = type { i32 }
@O_RDWR = global i32 0
@.str = [14 x i8] c"open com dev\0A\00"
define i32 @CommOpen(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.termios
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %19
13: ; preds = %1
%14 = call i32 @memset(%struct.termios* %5, i32 0, i32 4)
%15 = load i32, i32* %4
%16 = call i32 @tcgetattr(i32 %15, %struct.termios* %5)
%17 = call i32 @cfmakeraw(%struct.termios* %5)
%18 = load i32, i32* %4
store i32 %18, i32* %2
br label %19
19: ; preds = %13, %11
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@O_RDWR = global i32 0
@.str = [14 x i8] c"open com dev\0A\00"
define i32 @CommOpen(i8* nocapture %0) {
%2 = alloca %struct.termios
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %13
8: ; preds = %1
%9 = bitcast %struct.termios* %2 to i8*
%10 = call i32 @memset(%struct.termios* %2, i32 0, i32 4)
%11 = call i32 @tcgetattr(i32 %4, %struct.termios* %2)
%12 = call i32 @cfmakeraw(%struct.termios* %2)
br label %13
13: ; preds = %8, %6
%14 = phi i32 [ -1, %6 ], [ %4, %8 ]
ret i32 %14
}