#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 */
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ stdin;
main() {
  char *frase = NULL;
  size_t espaco = 0;
  int n = getline(&frase, &espaco, stdin);
  if (frase[n - 1] == '\n') {
    frase[n - 1] = '\0';
    n--;
  }
  printf("A frase \"%s\" tem comprimento %d.\n", frase, n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <getline@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    118c <main+0x6c>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2eab(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <getline@plt>
mov    0x8(%rsp),%rsi
movslq %eax,%rcx
cmpb   $0xa,-0x1(%rsi,%rcx,1)
jne    116c <main+0x4c>
add    $0xffffffffffffffff,%rcx
movb   $0x0,(%rsi,%rcx,1)
mov    0x8(%rsp),%rsi
mov    %ecx,%eax
lea    0xe8d(%rip),%rdi
mov    %eax,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [34 x i8] c"A frase \22%s\22 tem comprimento %d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %2
store i64 0, i64* %3
%5 = load i32, i32* @stdin
%6 = call i32 @getline(i8** %2, i64* %3, i32 %5)
store i32 %6, i32* %4
%7 = load i8*, i8** %2
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 10
br i1 %14, label %15, label %23
15: ; preds = %0
%16 = load i8*, i8** %2
%17 = load i32, i32* %4
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
store i8 0, i8* %20
%21 = load i32, i32* %4
%22 = add nsw i32 %21, -1
store i32 %22, i32* %4
br label %23
23: ; preds = %15, %0
%24 = load i8*, i8** %2
%25 = load i32, i32* %4
%26 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %24, i32 %25)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [34 x i8] c"A frase \22%s\22 tem comprimento %d.\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i64
%3 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = load i32, i32* @stdin
%6 = call i32 @getline(i8** %1, i64* %2, i32 %5)
%7 = load i8*, i8** %1
%8 = add nsw i32 %6, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 10
br i1 %12, label %13, label %15
13: ; preds = %0
store i8 0, i8* %10
%14 = load i8*, i8** %1
br label %15
15: ; preds = %13, %0
%16 = phi i8* [ %14, %13 ], [ %7, %0 ]
%17 = phi i32 [ %8, %13 ], [ %6, %0 ]
%18 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %17)
ret i32 0
}