#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  FILE *serial_port = fopen("/dev/ttyUSB1", "r+");
  if (serial_port == NULL) {
    printf("Error opening port");
    return 1;
  }
  char c, s[1000];
  int inteiro;
  printf("ENTRADA  -> ");
  scanf(" %[^\n]s%*c", s);
  fprintf(serial_port, "%s\n", s);
  fscanf(serial_port, "%s%*c", s);
  printf("RESPOSTA -> %s\n", s);
  fclose(serial_port);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ae <main+0x4e>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1222 <main+0xc2>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x400(%rbp),%rsi
lea    0xe66(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x400(%rbp),%rdx
lea    0xe6c(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x400(%rbp),%rdx
lea    0xe43(%rip),%rsi
call   1050 <fscanf@plt>
lea    -0x400(%rbp),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3f0,%rsp
lea    0xe8e(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e8 <main+0x88>
mov    %rax,%rbx
lea    0xe96(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe92(%rip),%rdi
mov    %rsp,%rbp
mov    %rbp,%rsi
call   1070 <scanf@plt>
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1060 <fprintf@plt>
lea    0xe79(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1050 <fscanf@plt>
lea    0xe6d(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11fc <main+0x9c>
lea    0xe21(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyUSB1\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [19 x i8] c"Error opening port\00"
@.str.3 = [13 x i8] c"ENTRADA -> \00"
@.str.4 = [11 x i8] c" %[^\0A]s%*c\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [6 x i8] c"%s%*c\00"
@.str.7 = [16 x i8] c"RESPOSTA -> %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
%4 = alloca [1000 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %25
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%14 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%15 = load i32*, i32** %2
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%17 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %16)
%18 = load i32*, i32** %2
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%20 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %21)
%23 = load i32*, i32** %2
%24 = call i32 @fclose(i32* %23)
store i32 0, i32* %1
br label %25
25: ; preds = %11, %9
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyUSB1\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [19 x i8] c"Error opening port\00"
@.str.3 = [13 x i8] c"ENTRADA -> \00"
@.str.4 = [11 x i8] c" %[^\0A]s%*c\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [6 x i8] c"%s%*c\00"
@.str.7 = [16 x i8] c"RESPOSTA -> %s\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %14
6: ; preds = %0
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%10 = call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%11 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %7)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %7)
%13 = call i32 @fclose(i32* %2)
br label %14
14: ; preds = %6, %4
%15 = phi i32 [ 1, %4 ], [ 0, %6 ]
ret i32 %15
}