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

/* Variables and functions */
int /*<<< orphan*/ B9600;
int /*<<< orphan*/ CRTSCTS;
int /*<<< orphan*/ CS8;
int /*<<< orphan*/ CSIZE;
int /*<<< orphan*/ CSTOPB;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ HUPCL;
int /*<<< orphan*/ ICANON;
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ PARENB;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int confPort(char *url) {
  int fd = 0;
  struct termios iniConfig, myConfig;
  fd = open(url, O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1) {
    printf("Erro ao abrir porta");
    close(fd);
    return fd;
  } else
    fcntl(fd, F_SETFL, 0);
  tcgetattr(fd, &iniConfig);
  tcgetattr(fd, &myConfig);
  cfsetispeed(&myConfig, B9600);
  cfsetospeed(&myConfig, B9600);
  myConfig.c_cflag &= ~PARENB;
  myConfig.c_cflag &= ~CSTOPB;
  myConfig.c_cflag &= ~CSIZE;
  myConfig.c_cflag |= CS8;
  myConfig.c_cflag &= ~HUPCL;
  myConfig.c_cflag &= ~CRTSCTS;
  myConfig.c_lflag = ICANON;
  tcsetattr(fd, TCSANOW, &myConfig);
  sleep(2);
  return (fd);
}


x86 assembly (clang, -O0):
<confPort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
mov    0x2df9(%rip),%rax
or     (%rax),%esi
mov    0x2de0(%rip),%rax
or     (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11f3 <confPort+0x63>
lea    0xe25(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12dc <confPort+0x14c>
mov    -0x14(%rbp),%edi
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1070 <tcgetattr@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1070 <tcgetattr@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   10a0 <cfsetispeed@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d1d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d49(%rip),%rax
mov    (%rax),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d0a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2ce0(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d17(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    $0x2,%edi
call   10b0 <sleep@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<confPort>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e48(%rip),%rax
mov    0x2e09(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dee(%rip),%rax
or     (%rax),%esi
call   1090 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     127b <confPort+0xeb>
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1070 <tcgetattr@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1070 <tcgetattr@plt>
mov    0x2dda(%rip),%r15
mov    (%r15),%esi
mov    %r14,%rdi
call   10a0 <cfsetispeed@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1040 <cfsetospeed@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    0x2d5c(%rip),%rcx
or     (%rcx),%eax
mov    0x2d9b(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    0x4(%rsp),%eax
mov    0x2d94(%rip),%rcx
or     (%rcx),%eax
mov    0x2d5b(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d3a(%rip),%rdx
or     (%rdx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,0x4(%rsp)
mov    0x2d39(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    0x2d75(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1080 <tcsetattr@plt>
mov    $0x2,%edi
call   10b0 <sleep@plt>
jmp    1291 <confPort+0x101>
lea    0xd7e(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <close@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str = [20 x i8] c"Erro ao abrir porta\00"
@F_SETFL = global i32 0
@B9600 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@HUPCL = global i32 0
@CRTSCTS = global i32 0
@ICANON = global i32 0
@TCSANOW = global i32 0
define i32 @confPort(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.termios
%6 = alloca %struct.termios
store i8* %0, i8** %3
store i32 0, i32* %4
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_NOCTTY
%10 = or i32 %8, %9
%11 = load i32, i32* @O_NDELAY
%12 = or i32 %10, %11
%13 = call i32 @open(i8* %7, i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %21
16: ; preds = %1
%17 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* %4
%19 = call i32 @close(i32 %18)
%20 = load i32, i32* %4
store i32 %20, i32* %2
br label %70
21: ; preds = %1
%22 = load i32, i32* %4
%23 = load i32, i32* @F_SETFL
%24 = call i32 @fcntl(i32 %22, i32 %23, i32 0)
br label %25
25: ; preds = %21
%26 = load i32, i32* %4
%27 = call i32 @tcgetattr(i32 %26, %struct.termios* %5)
%28 = load i32, i32* %4
%29 = call i32 @tcgetattr(i32 %28, %struct.termios* %6)
%30 = load i32, i32* @B9600
%31 = call i32 @cfsetispeed(%struct.termios* %6, i32 %30)
%32 = load i32, i32* @B9600
%33 = call i32 @cfsetospeed(%struct.termios* %6, i32 %32)
%34 = load i32, i32* @PARENB
%35 = xor i32 %34, -1
%36 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%37 = load i32, i32* %36
%38 = and i32 %37, %35
store i32 %38, i32* %36
%39 = load i32, i32* @CSTOPB
%40 = xor i32 %39, -1
%41 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%42 = load i32, i32* %41
%43 = and i32 %42, %40
store i32 %43, i32* %41
%44 = load i32, i32* @CSIZE
%45 = xor i32 %44, -1
%46 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%47 = load i32, i32* %46
%48 = and i32 %47, %45
store i32 %48, i32* %46
%49 = load i32, i32* @CS8
%50 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%51 = load i32, i32* %50
%52 = or i32 %51, %49
store i32 %52, i32* %50
%53 = load i32, i32* @HUPCL
%54 = xor i32 %53, -1
%55 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%56 = load i32, i32* %55
%57 = and i32 %56, %54
store i32 %57, i32* %55
%58 = load i32, i32* @CRTSCTS
%59 = xor i32 %58, -1
%60 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%61 = load i32, i32* %60
%62 = and i32 %61, %59
store i32 %62, i32* %60
%63 = load i32, i32* @ICANON
%64 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
store i32 %63, i32* %64
%65 = load i32, i32* %4
%66 = load i32, i32* @TCSANOW
%67 = call i32 @tcsetattr(i32 %65, i32 %66, %struct.termios* %6)
%68 = call i32 @sleep(i32 2)
%69 = load i32, i32* %4
store i32 %69, i32* %2
br label %70
70: ; preds = %25, %16
%71 = load i32, i32* %2
ret i32 %71
}

LLVM IR (-O2):
%struct.termios = type { i32, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str = [20 x i8] c"Erro ao abrir porta\00"
@F_SETFL = global i32 0
@B9600 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@HUPCL = global i32 0
@CRTSCTS = global i32 0
@ICANON = global i32 0
@TCSANOW = global i32 0
define i32 @confPort(i8* nocapture %0) {
%2 = alloca %struct.termios
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %2 to i8*
%5 = bitcast %struct.termios* %3 to i8*
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_NOCTTY
%8 = or i32 %7, %6
%9 = load i32, i32* @O_NDELAY
%10 = or i32 %8, %9
%11 = tail call i32 @open(i8* %0, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @close(i32 -1)
br label %46
16: ; preds = %1
%17 = load i32, i32* @F_SETFL
%18 = tail call i32 @fcntl(i32 %11, i32 %17, i32 0)
%19 = call i32 @tcgetattr(i32 %11, %struct.termios* %2)
%20 = call i32 @tcgetattr(i32 %11, %struct.termios* %3)
%21 = load i32, i32* @B9600
%22 = call i32 @cfsetispeed(%struct.termios* %3, i32 %21)
%23 = load i32, i32* @B9600
%24 = call i32 @cfsetospeed(%struct.termios* %3, i32 %23)
%25 = load i32, i32* @PARENB
%26 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%27 = load i32, i32* %26
%28 = load i32, i32* @CSTOPB
%29 = or i32 %25, %28
%30 = load i32, i32* @CSIZE
%31 = or i32 %29, %30
%32 = xor i32 %31, -1
%33 = and i32 %27, %32
%34 = load i32, i32* @CS8
%35 = or i32 %34, %33
%36 = load i32, i32* @HUPCL
%37 = load i32, i32* @CRTSCTS
%38 = or i32 %36, %37
%39 = xor i32 %38, -1
%40 = and i32 %35, %39
store i32 %40, i32* %26
%41 = load i32, i32* @ICANON
%42 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
store i32 %41, i32* %42
%43 = load i32, i32* @TCSANOW
%44 = call i32 @tcsetattr(i32 %11, i32 %43, %struct.termios* %3)
%45 = call i32 @sleep(i32 2)
br label %46
46: ; preds = %16, %13
ret i32 %11
}