#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ realloc(char *, int);
int scanf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main() {
  char c, *max, *p;
  int n = 0, l = 0, i = 0;
  printf("Frase? ");
  max = (char *)malloc(sizeof(char));
  p = (char *)malloc(sizeof(char));
  while (scanf("%c", &c) == 1) {
    if (c == ' ' || c == '\n') {
      if (strlen(p) > strlen(max)) {
        max = (char *)realloc(max, sizeof(char) * strlen(p));
        strcpy(max, p);
      }
      n++;
      i = 0;
      if (c == '\n')
        break;
    } else {
      p = (char *)realloc(p, sizeof(char) * (i + 1));
      p[i] = c;
      l++;
      i++;
    }
  }
  printf("Numero de palavras: %d\n", n);
  printf("Palavra maior: %s\n", max);
  printf("Comprimento medio: %.1f\n", (float)l / (float)n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe53(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1080 <scanf@plt>
cmp    $0x1,%eax
jne    129d <main+0x13d>
movsbl -0x5(%rbp),%eax
cmp    $0x20,%eax
je     11e1 <main+0x81>
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    125d <main+0xfd>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jle    1236 <main+0xd6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    1258 <main+0xf8>
jmp    129d <main+0x13d>
jmp    1298 <main+0x138>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x5(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ae <main+0x4e>
mov    -0x1c(%rbp),%esi
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cvtsi2ssl -0x20(%rbp),%xmm0
cvtsi2ssl -0x1c(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd5d(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe8e(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
lea    0xe6b(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1080 <scanf@plt>
mov    $0x0,%ebp
cmp    $0x1,%eax
jne    124c <main+0xec>
xor    %r12d,%r12d
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    11fc <main+0x9c>
nop
lea    0x1(%r12),%ebx
mov    %r13,%rdi
mov    %ebx,%esi
call   1070 <realloc@plt>
mov    %rax,%r13
movzbl 0x7(%rsp),%eax
movslq %r12d,%rcx
mov    %al,0x0(%r13,%rcx,1)
add    $0x1,%r15d
mov    %ebx,%r12d
lea    0xe1b(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1080 <scanf@plt>
cmp    $0x1,%eax
jne    124c <main+0xec>
movzbl 0x7(%rsp),%eax
cmp    $0x20,%al
je     1209 <main+0xa9>
cmp    $0xa,%al
jne    11c0 <main+0x60>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebx
jle    123f <main+0xdf>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
add    $0x1,%ebp
xor    %r12d,%r12d
cmpb   $0xa,0x7(%rsp)
jne    11e6 <main+0x86>
lea    0xdb8(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdc0(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cvtsi2ss %r15d,%xmm0
cvtsi2ss %ebp,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdb1(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"Frase? \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [24 x i8] c"Numero de palavras: %d\0A\00"
@.str.3 = [19 x i8] c"Palavra maior: %s\0A\00"
@.str.4 = [25 x i8] c"Comprimento medio: %.1f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = call i64 @malloc(i32 1)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %3
%11 = call i64 @malloc(i32 1)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %4
br label %13
13: ; preds = %68, %0
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %69
16: ; preds = %13
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 32
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = load i8, i8* %2
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %50
24: ; preds = %20, %16
%25 = load i8*, i8** %4
%26 = call i32 @strlen(i8* %25)
%27 = load i8*, i8** %3
%28 = call i32 @strlen(i8* %27)
%29 = icmp sgt i32 %26, %28
br i1 %29, label %30, label %42
30: ; preds = %24
%31 = load i8*, i8** %3
%32 = load i8*, i8** %4
%33 = call i32 @strlen(i8* %32)
%34 = sext i32 %33 to i64
%35 = mul i64 1, %34
%36 = trunc i64 %35 to i32
%37 = call i64 @realloc(i8* %31, i32 %36)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %3
%39 = load i8*, i8** %3
%40 = load i8*, i8** %4
%41 = call i32 @strcpy(i8* %39, i8* %40)
br label %42
42: ; preds = %30, %24
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
store i32 0, i32* %7
%45 = load i8, i8* %2
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 10
br i1 %47, label %48, label %49
48: ; preds = %42
br label %69
49: ; preds = %42
br label %68
50: ; preds = %20
%51 = load i8*, i8** %4
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = mul i64 1, %54
%56 = trunc i64 %55 to i32
%57 = call i64 @realloc(i8* %51, i32 %56)
%58 = inttoptr i64 %57 to i8*
store i8* %58, i8** %4
%59 = load i8, i8* %2
%60 = load i8*, i8** %4
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
store i8 %59, i8* %63
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %68
68: ; preds = %50, %49
br label %13
69: ; preds = %48, %13
%70 = load i32, i32* %5
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %70)
%72 = load i8*, i8** %3
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %72)
%74 = load i32, i32* %6
%75 = sitofp i32 %74 to float
%76 = load i32, i32* %5
%77 = sitofp i32 %76 to float
%78 = fdiv float %75, %77
%79 = fpext float %78 to double
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), double %79)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"Frase? \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [24 x i8] c"Numero de palavras: %d\0A\00"
@.str.3 = [19 x i8] c"Palavra maior: %s\0A\00"
@.str.4 = [25 x i8] c"Comprimento medio: %.1f\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%3 = tail call i64 @malloc(i32 1)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i64 @malloc(i32 1)
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %47
8: ; preds = %0
%9 = inttoptr i64 %5 to i8*
br label %10
10: ; preds = %8, %39
%11 = phi i32 [ %44, %39 ], [ 0, %8 ]
%12 = phi i32 [ %43, %39 ], [ 0, %8 ]
%13 = phi i32 [ %42, %39 ], [ 0, %8 ]
%14 = phi i8* [ %41, %39 ], [ %9, %8 ]
%15 = phi i8* [ %40, %39 ], [ %4, %8 ]
%16 = load i8, i8* %1
switch i8 %16, label %31 [
i8 32, label %17
i8 10, label %17
]
17: ; preds = %10, %10
%18 = call i32 @strlen(i8* %14)
%19 = call i32 @strlen(i8* %15)
%20 = icmp sgt i32 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = call i32 @strlen(i8* %14)
%23 = call i64 @realloc(i8* %15, i32 %22)
%24 = inttoptr i64 %23 to i8*
%25 = call i32 @strcpy(i8* %24, i8* %14)
br label %26
26: ; preds = %21, %17
%27 = phi i8* [ %24, %21 ], [ %15, %17 ]
%28 = add nsw i32 %13, 1
%29 = load i8, i8* %1
%30 = icmp eq i8 %29, 10
br i1 %30, label %47, label %39
31: ; preds = %10
%32 = add nsw i32 %11, 1
%33 = call i64 @realloc(i8* %14, i32 %32)
%34 = inttoptr i64 %33 to i8*
%35 = load i8, i8* %1
%36 = sext i32 %11 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 %35, i8* %37
%38 = add nsw i32 %12, 1
br label %39
39: ; preds = %26, %31
%40 = phi i8* [ %27, %26 ], [ %15, %31 ]
%41 = phi i8* [ %14, %26 ], [ %34, %31 ]
%42 = phi i32 [ %28, %26 ], [ %13, %31 ]
%43 = phi i32 [ %12, %26 ], [ %38, %31 ]
%44 = phi i32 [ 0, %26 ], [ %32, %31 ]
%45 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%46 = icmp eq i32 %45, 1
br i1 %46, label %10, label %47
47: ; preds = %39, %26, %0
%48 = phi i32 [ 0, %0 ], [ %12, %26 ], [ %43, %39 ]
%49 = phi i8* [ %4, %0 ], [ %27, %26 ], [ %40, %39 ]
%50 = phi i32 [ 0, %0 ], [ %28, %26 ], [ %42, %39 ]
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %49)
%53 = sitofp i32 %48 to float
%54 = sitofp i32 %50 to float
%55 = fdiv float %53, %54
%56 = fpext float %55 to double
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), double %56)
ret i32 0
}