#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 O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit_smcnc();
int /*<<< orphan*/ *fdopen(int, char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ init_smcnc(int /*<<< orphan*/ *);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ smcnc_fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int main() {
  int fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY);
  assert(fd != -1);
  FILE *t = fdopen(fd, "w+");
  assert(t);
  init_smcnc(t);
  char *line;
  size_t n = 0;
  for (;;) {
    if (getline(&line, &n, stdin) == -1) {
      printf("Erro na leitura\n");
      break;
    }
    printf("Enviando a mensagem %s.\n", line);
    smcnc_fputs(line, t);
  }
  exit_smcnc();
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    0x2e21(%rip),%rax
or     (%rax),%esi
lea    0xe48(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%edi
lea    0xe32(%rip),%rsi
call   1070 <fdopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1050 <init_smcnc@plt>
movq   $0x0,-0x20(%rbp)
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10b0 <getline@plt>
cmp    $0xffffffff,%eax
jne    1232 <main+0xa2>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1256 <main+0xc6>
mov    -0x18(%rbp),%rsi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <smcnc_fputs@plt>
jmp    1200 <main+0x70>
mov    $0x0,%al
call   1090 <exit_smcnc@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e33(%rip),%rax
mov    0x2e14(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe39(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,%r14d
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1070 <assert@plt>
lea    0xe29(%rip),%rsi
mov    %r14d,%edi
call   1080 <fdopen@plt>
mov    %rax,%rbx
mov    %ebx,%edi
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1060 <init_smcnc@plt>
movq   $0x0,0x10(%rsp)
mov    0x2dd2(%rip),%r13
mov    0x0(%r13),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10c0 <getline@plt>
cmp    $0xffffffff,%eax
je     1270 <main+0xd0>
lea    0xde3(%rip),%r15
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1090 <smcnc_fputs@plt>
mov    0x0(%r13),%edx
mov    %r12,%rdi
mov    %rbp,%rsi
call   10c0 <getline@plt>
cmp    $0xffffffff,%eax
jne    1240 <main+0xa0>
lea    0xdb2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10a0 <exit_smcnc@plt>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyACM0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.1 = [3 x i8] c"w+\00"
@stdin = global i32 0
@.str.2 = [17 x i8] c"Erro na leitura\0A\00"
@.str.3 = [25 x i8] c"Enviando a mensagem %s.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
store i32 0, i32* %1
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_NOCTTY
%8 = or i32 %6, %7
%9 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, -1
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32, i32* %2
%15 = call i32* @fdopen(i32 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %3
%16 = load i32*, i32** %3
%17 = ptrtoint i32* %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32*, i32** %3
%20 = call i32 @init_smcnc(i32* %19)
store i64 0, i64* %5
br label %21
21: ; preds = %27, %0
%22 = load i32, i32* @stdin
%23 = call i32 @getline(i8** %4, i64* %5, i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %33
27: ; preds = %21
%28 = load i8*, i8** %4
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = load i8*, i8** %4
%31 = load i32*, i32** %3
%32 = call i32 @smcnc_fputs(i8* %30, i32* %31)
br label %21
33: ; preds = %25
%34 = call i32 (...) @exit_smcnc()
%35 = load i32, i32* %2
%36 = call i32 @close(i32 %35)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyACM0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.1 = [3 x i8] c"w+\00"
@stdin = global i32 0
@.str.3 = [25 x i8] c"Enviando a mensagem %s.\0A\00"
@str = [16 x i8] c"Erro na leitura\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i64
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_NOCTTY
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp ne i32 %6, -1
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32* @fdopen(i32 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = ptrtoint i32* %10 to i64
%12 = trunc i64 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i32 @init_smcnc(i32* %10)
%15 = bitcast i8** %1 to i8*
%16 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%17 = load i32, i32* @stdin
%18 = call i32 @getline(i8** %1, i64* %2, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %24, %0
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%22 = call i32 (...) @exit_smcnc()
%23 = call i32 @close(i32 %6)
ret i32 0
24: ; preds = %0, %24
%25 = load i8*, i8** %1
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %1
%28 = call i32 @smcnc_fputs(i8* %27, i32* %10)
%29 = load i32, i32* @stdin
%30 = call i32 @getline(i8** %1, i64* %2, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %20, label %24
}