#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 */

/* Variables and functions */
void *atoi(char *);
int /*<<< orphan*/ cerrarSerial();
int /*<<< orphan*/ cerrarSocket();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ initSerial(char *, int);
int /*<<< orphan*/ initSocket(unsigned short);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  char buffWrite[110];
  unsigned short socketPort;
  char *serialport;
  int baud;
  if (argc != 4) {
    fprintf(stderr, "Uso: %s <Socket Port> <Serial Port> <baud>\n", argv[0]);
    exit(1);
  }
  socketPort = atoi(argv[1]);
  serialport = argv[2];
  baud = atoi(argv[3]);
  initSocket(socketPort);
  initSerial(serialport, baud);
  while (1) {
    fflush(stdout);
    fgets(buffWrite, 110, stdin);
    buffWrite[strlen(buffWrite) - 1] = '\0';
    if (strcmp("FIN", buffWrite) == 0)
      break;
  }
  cerrarSerial();
  cerrarSocket();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11f9 <main+0x49>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe16(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %ax,-0x82(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x90(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x94(%rbp)
movzwl -0x82(%rbp),%edi
call   1040 <initSocket@plt>
mov    -0x90(%rbp),%rdi
mov    -0x94(%rbp),%esi
call   1070 <initSerial@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
lea    -0x80(%rbp),%rdi
mov    0x2d82(%rip),%rax
mov    (%rax),%edx
mov    $0x6e,%esi
call   1080 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xd9c(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12a4 <main+0xf4>
jmp    12a9 <main+0xf9>
jmp    124d <main+0x9d>
mov    $0x0,%al
call   1030 <cerrarSerial@plt>
mov    $0x0,%al
call   1060 <cerrarSocket@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    1264 <main+0xb4>
mov    0x8(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %rax,%r14
mov    0x10(%rbx),%r15
mov    0x18(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %rax,%rbx
movzwl %r14w,%edi
call   1040 <initSocket@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1070 <initSerial@plt>
mov    0x2dd3(%rip),%r15
mov    0x2de4(%rip),%r12
mov    %rsp,%rbx
lea    0xe1e(%rip),%r14
xchg   %ax,%ax
mov    (%r15),%edi
call   10b0 <fflush@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x6e,%esi
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    1210 <main+0x60>
xor    %eax,%eax
call   1030 <cerrarSerial@plt>
xor    %eax,%eax
call   1060 <cerrarSocket@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd89(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"Uso: %s <Socket Port> <Serial Port> <baud>\0A\00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [4 x i8] c"FIN\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [110 x i8]
%7 = alloca i16
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 4
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i8* @atoi(i8* %22)
%24 = ptrtoint i8* %23 to i16
store i16 %24, i16* %7
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
store i8* %27, i8** %8
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 3
%30 = load i8*, i8** %29
%31 = call i8* @atoi(i8* %30)
%32 = ptrtoint i8* %31 to i32
store i32 %32, i32* %9
%33 = load i16, i16* %7
%34 = call i32 @initSocket(i16 zeroext %33)
%35 = load i8*, i8** %8
%36 = load i32, i32* %9
%37 = call i32 @initSerial(i8* %35, i32 %36)
br label %38
38: ; preds = %19, %53
%39 = load i32, i32* @stdout
%40 = call i32 @fflush(i32 %39)
%41 = getelementptr inbounds [110 x i8], [110 x i8]* %6, i64 0, i64 0
%42 = load i32, i32* @stdin
%43 = call i32 @fgets(i8* %41, i32 110, i32 %42)
%44 = getelementptr inbounds [110 x i8], [110 x i8]* %6, i64 0, i64 0
%45 = call i32 @strlen(i8* %44)
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [110 x i8], [110 x i8]* %6, i64 0, i64 %47
store i8 0, i8* %48
%49 = getelementptr inbounds [110 x i8], [110 x i8]* %6, i64 0, i64 0
%50 = call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %38
br label %54
53: ; preds = %38
br label %38
54: ; preds = %52
%55 = call i32 (...) @cerrarSerial()
%56 = call i32 (...) @cerrarSocket()
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"Uso: %s <Socket Port> <Serial Port> <baud>\0A\00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [4 x i8] c"FIN\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [110 x i8]
%4 = getelementptr inbounds [110 x i8], [110 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 4
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i8* @atoi(i8* %13)
%15 = ptrtoint i8* %14 to i64
%16 = trunc i64 %15 to i16
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = tail call i8* @atoi(i8* %20)
%22 = ptrtoint i8* %21 to i64
%23 = trunc i64 %22 to i32
%24 = tail call i32 @initSocket(i16 zeroext %16)
%25 = tail call i32 @initSerial(i8* %18, i32 %23)
br label %26
26: ; preds = %26, %11
%27 = load i32, i32* @stdout
%28 = call i32 @fflush(i32 %27)
%29 = load i32, i32* @stdin
%30 = call i32 @fgets(i8* %4, i32 110, i32 %29)
%31 = call i32 @strlen(i8* %4)
%32 = add nsw i32 %31, -1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [110 x i8], [110 x i8]* %3, i64 0, i64 %33
store i8 0, i8* %34
%35 = call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %26
37: ; preds = %26
%38 = call i32 (...) @cerrarSerial()
%39 = call i32 (...) @cerrarSocket()
ret i32 0
}