#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 getchar();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int input;
  float chars = 0.0f;
  float words = 1.0f;
  printf("Enter a sentence: ");
  while ((input = getchar()) != '\n') {
    switch (input) {
    case ' ':
      words++;
      break;
    default:
      chars++;
      break;
    }
  }
  printf("Average characters per word: %.1f\n", chars / words);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  0xec1(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xa,%eax
je     11a4 <main+0x84>
mov    -0x8(%rbp),%eax
sub    $0x20,%eax
jne    118d <main+0x6d>
jmp    1176 <main+0x56>
movss  0xe82(%rip),%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    119f <main+0x7f>
movss  0xe6b(%rip),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1152 <main+0x32>
movss  -0xc(%rbp),%xmm0
divss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe5e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xedc(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movss  0xec9(%rip),%xmm1
xorps  %xmm0,%xmm0
movss  %xmm0,(%rsp)
movss  %xmm1,0x4(%rsp)
jmp    1164 <main+0x44>
nopw   0x0(%rax,%rax,1)
movss  0x4(%rsp),%xmm0
addss  0xea2(%rip),%xmm0
movss  %xmm0,0x4(%rsp)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0x20,%eax
je     1150 <main+0x30>
cmp    $0xa,%eax
je     1189 <main+0x69>
movss  (%rsp),%xmm0
addss  0xe7e(%rip),%xmm0
movss  %xmm0,(%rsp)
jmp    1164 <main+0x44>
movss  (%rsp),%xmm0
divss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe78(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Enter a sentence: \00"
@.str.1 = [35 x i8] c"Average characters per word: %.1f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
store i32 0, i32* %1
store float 0.000000e+00, float* %3
store float 1.000000e+00, float* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %17, %0
%7 = call i32 (...) @getchar()
store i32 %7, i32* %2
%8 = icmp ne i32 %7, 10
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = load i32, i32* %2
switch i32 %10, label %14 [
i32 32, label %11
]
11: ; preds = %9
%12 = load float, float* %4
%13 = fadd float %12, 1.000000e+00
store float %13, float* %4
br label %17
14: ; preds = %9
%15 = load float, float* %3
%16 = fadd float %15, 1.000000e+00
store float %16, float* %3
br label %17
17: ; preds = %14, %11
br label %6
18: ; preds = %6
%19 = load float, float* %3
%20 = load float, float* %4
%21 = fdiv float %19, %20
%22 = fpext float %21 to double
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), double %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Enter a sentence: \00"
@.str.1 = [35 x i8] c"Average characters per word: %.1f\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %2
2: ; preds = %10, %0
%3 = phi float [ %11, %10 ], [ 0.000000e+00, %0 ]
%4 = phi float [ %6, %10 ], [ 1.000000e+00, %0 ]
br label %5
5: ; preds = %2, %8
%6 = phi float [ %9, %8 ], [ %4, %2 ]
%7 = tail call i32 (...) @getchar()
switch i32 %7, label %10 [
i32 10, label %12
i32 32, label %8
]
8: ; preds = %5
%9 = fadd float %6, 1.000000e+00
br label %5
10: ; preds = %5
%11 = fadd float %3, 1.000000e+00
br label %2
12: ; preds = %5
%13 = fdiv float %3, %6
%14 = fpext float %13 to double
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), double %14)
ret i32 0
}