#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 */
char EOF;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
char getchar();
scalar_t__ isalnum(char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(void) {
  char buffer[256] = {0};
  double avgWordLen = 0.0;
  size_t wordLen = 0;
  size_t wordCount = 0;
  printf("Please enter a sentence: ");
  if (!fgets(buffer, 256, stdin)) {
    return EXIT_FAILURE;
  }
  if (buffer[strlen(buffer) - 1] != '\n') {
    char c = '\0';
    while ((c = getchar()) != '\n' && c != EOF)
      continue;
  }
  char *pchar = buffer;
  while (*pchar != '\0') {
    if (isalnum(*pchar) && !isalnum(*(pchar + 1))) {
      *(pchar + 1) = '\0';
      ++pchar;
      ++wordCount;
    }
    ++pchar;
  }
  pchar = buffer;
  for (size_t i = 0; i < wordCount; ++i) {
    while (*pchar && !isalnum(*pchar))
      ++pchar;
    wordLen = strlen(pchar);
    avgWordLen += wordLen;
    pchar = &pchar[wordLen + 1];
  }
  avgWordLen /= (double)wordCount;
  printf("Average word length: %g\n", avgWordLen);
  getchar();
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x118(%rbp)
ff
movq   $0x0,-0x120(%rbp)
movq   $0x0,-0x128(%rbp)
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1070 <fgets@plt>
cmp    $0x0,%eax
jne    11e8 <main+0x88>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1483 <main+0x323>
lea    -0x110(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x110(%rbp,%rax,1),%eax
cmp    $0xa,%eax
je     126b <main+0x10b>
movb   $0x0,-0x129(%rbp)
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %al,-0x129(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x141(%rbp)
je     124e <main+0xee>
movsbl -0x129(%rbp),%eax
mov    0x2da0(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x141(%rbp)
mov    -0x141(%rbp),%al
test   $0x1,%al
jne    1261 <main+0x101>
jmp    1266 <main+0x106>
jmp    1211 <main+0xb1>
jmp    126b <main+0x10b>
lea    -0x110(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1305 <main+0x1a5>
mov    -0x138(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalnum@plt>
cmp    $0x0,%rax
je     12ee <main+0x18e>
mov    -0x138(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1050 <isalnum@plt>
cmp    $0x0,%rax
jne    12ee <main+0x18e>
mov    -0x138(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
mov    -0x128(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x128(%rbp)
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
jmp    1279 <main+0x119>
lea    -0x110(%rbp),%rax
mov    %rax,-0x138(%rbp)
movq   $0x0,-0x140(%rbp)
mov    -0x140(%rbp),%rax
cmp    -0x128(%rbp),%rax
jae    141c <main+0x2bc>
jmp    1337 <main+0x1d7>
mov    -0x138(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x142(%rbp)
je     1370 <main+0x210>
mov    -0x138(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalnum@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x142(%rbp)
mov    -0x142(%rbp),%al
test   $0x1,%al
jne    1383 <main+0x223>
jmp    139a <main+0x23a>
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
jmp    1337 <main+0x1d7>
mov    -0x138(%rbp),%rdi
call   1030 <strlen@plt>
cltq
mov    %rax,-0x120(%rbp)
movaps 0xc4a(%rip),%xmm1
movq   -0x120(%rbp),%xmm0
ff
punpckldq %xmm1,%xmm0
movapd 0xc46(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x118(%rbp),%xmm0
ff
movsd  %xmm0,-0x118(%rbp)
ff
mov    -0x138(%rbp),%rax
mov    -0x120(%rbp),%rcx
add    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x138(%rbp)
mov    -0x140(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x140(%rbp)
jmp    131e <main+0x1be>
movaps 0xbdd(%rip),%xmm0
movq   -0x128(%rbp),%xmm1
ff
punpckldq %xmm0,%xmm1
movapd 0xbd9(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x118(%rbp),%xmm0
ff
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x118(%rbp)
ff
movsd  -0x118(%rbp),%xmm0
ff
lea    0xbd1(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    0x2b4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x110,%rsp
xorpd  %xmm0,%xmm0
movapd %xmm0,0x100(%rsp)
movapd %xmm0,0xf0(%rsp)
movapd %xmm0,0xe0(%rsp)
movapd %xmm0,0xd0(%rsp)
movapd %xmm0,0xc0(%rsp)
movapd %xmm0,0xb0(%rsp)
movapd %xmm0,0xa0(%rsp)
movapd %xmm0,0x90(%rsp)
movapd %xmm0,0x80(%rsp)
movapd %xmm0,0x70(%rsp)
movapd %xmm0,0x60(%rsp)
movapd %xmm0,0x50(%rsp)
movapd %xmm0,0x40(%rsp)
movapd %xmm0,0x30(%rsp)
movapd %xmm0,0x20(%rsp)
movapd %xmm0,0x10(%rsp)
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1060 <fgets@plt>
test   %eax,%eax
je     133b <main+0x1eb>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
je     1240 <main+0xf0>
mov    0x2dbc(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
je     1240 <main+0xf0>
cmp    (%r14),%al
jne    1230 <main+0xe0>
mov    0x10(%rsp),%al
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %r14d,%r14d
test   %al,%al
jne    126c <main+0x11c>
jmp    1347 <main+0x1f7>
nopw   0x0(%rax,%rax,1)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1294 <main+0x144>
movsbl %al,%edi
call   1050 <isalnum@plt>
test   %rax,%rax
je     1260 <main+0x110>
movsbl 0x1(%rbx),%edi
call   1050 <isalnum@plt>
test   %rax,%rax
jne    1260 <main+0x110>
add    $0x1,%rbx
movb   $0x0,(%rbx)
add    $0x1,%r14
jmp    1260 <main+0x110>
test   %r14,%r14
je     1344 <main+0x1f4>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x10(%rsp),%rbx
xor    %r15d,%r15d
jmp    130b <main+0x1bb>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movq   %rax,%xmm0
punpckldq 0xd29(%rip),%xmm0
subpd  0xd31(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
add    %rax,%rbx
add    $0x1,%rbx
add    $0x1,%r15
cmp    %r14,%r15
je     1347 <main+0x1f7>
mov    (%rbx),%al
test   %al,%al
je     12c0 <main+0x170>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1050 <isalnum@plt>
test   %rax,%rax
jne    12c0 <main+0x170>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1320 <main+0x1d0>
jmp    12c0 <main+0x170>
mov    0x2c8e(%rip),%rax
jmp    138e <main+0x23e>
xor    %r14d,%r14d
movq   %r14,%xmm0
punpckldq 0xcac(%rip),%xmm0
subpd  0xcb4(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
lea    0xcc1(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2c3a(%rip),%rax
mov    (%rax),%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Please enter a sentence: \00"
@stdin = global i32 0
@EXIT_FAILURE = global i32 0
@EOF = global i8 0
@.str.1 = [25 x i8] c"Average word length: %g\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca double
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %1
%9 = bitcast [256 x i8]* %2 to i8*
store double 0.000000e+00, double* %3
store i64 0, i64* %4
store i64 0, i64* %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %11, i32 256, i32 %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %0
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %1
br label %116
17: ; preds = %0
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 10
br i1 %25, label %26, label %41
26: ; preds = %17
store i8 0, i8* %6
br label %27
27: ; preds = %39, %26
%28 = call signext i8 (...) @getchar()
store i8 %28, i8* %6
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 10
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = load i8, i8* %6
%33 = sext i8 %32 to i32
%34 = load i8, i8* @EOF
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %33, %35
br label %37
37: ; preds = %31, %27
%38 = phi i1 [ false, %27 ], [ %36, %31 ]
br i1 %38, label %39, label %40
39: ; preds = %37
br label %27
40: ; preds = %37
br label %41
41: ; preds = %40, %17
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
store i8* %42, i8** %7
br label %43
43: ; preds = %66, %41
%44 = load i8*, i8** %7
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %69
48: ; preds = %43
%49 = load i8*, i8** %7
%50 = load i8, i8* %49
%51 = call i64 @isalnum(i8 signext %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %66
53: ; preds = %48
%54 = load i8*, i8** %7
%55 = getelementptr inbounds i8, i8* %54, i64 1
%56 = load i8, i8* %55
%57 = call i64 @isalnum(i8 signext %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %66, label %59
59: ; preds = %53
%60 = load i8*, i8** %7
%61 = getelementptr inbounds i8, i8* %60, i64 1
store i8 0, i8* %61
%62 = load i8*, i8** %7
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %7
%64 = load i64, i64* %5
%65 = add i64 %64, 1
store i64 %65, i64* %5
br label %66
66: ; preds = %59, %53, %48
%67 = load i8*, i8** %7
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %7
br label %43
69: ; preds = %43
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
store i8* %70, i8** %7
store i64 0, i64* %8
br label %71
71: ; preds = %104, %69
%72 = load i64, i64* %8
%73 = load i64, i64* %5
%74 = icmp ult i64 %72, %73
br i1 %74, label %75, label %107
75: ; preds = %71
br label %76
76: ; preds = %89, %75
%77 = load i8*, i8** %7
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %87
81: ; preds = %76
%82 = load i8*, i8** %7
%83 = load i8, i8* %82
%84 = call i64 @isalnum(i8 signext %83)
%85 = icmp ne i64 %84, 0
%86 = xor i1 %85, true
br label %87
87: ; preds = %81, %76
%88 = phi i1 [ false, %76 ], [ %86, %81 ]
br i1 %88, label %89, label %92
89: ; preds = %87
%90 = load i8*, i8** %7
%91 = getelementptr inbounds i8, i8* %90, i32 1
store i8* %91, i8** %7
br label %76
92: ; preds = %87
%93 = load i8*, i8** %7
%94 = call i32 @strlen(i8* %93)
%95 = sext i32 %94 to i64
store i64 %95, i64* %4
%96 = load i64, i64* %4
%97 = uitofp i64 %96 to double
%98 = load double, double* %3
%99 = fadd double %98, %97
store double %99, double* %3
%100 = load i8*, i8** %7
%101 = load i64, i64* %4
%102 = add i64 %101, 1
%103 = getelementptr inbounds i8, i8* %100, i64 %102
store i8* %103, i8** %7
br label %104
104: ; preds = %92
%105 = load i64, i64* %8
%106 = add i64 %105, 1
store i64 %106, i64* %8
br label %71
107: ; preds = %71
%108 = load i64, i64* %5
%109 = uitofp i64 %108 to double
%110 = load double, double* %3
%111 = fdiv double %110, %109
store double %111, double* %3
%112 = load double, double* %3
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), double %112)
%114 = call signext i8 (...) @getchar()
%115 = load i32, i32* @EXIT_SUCCESS
store i32 %115, i32* %1
br label %116
116: ; preds = %107, %15
%117 = load i32, i32* %1
ret i32 %117
}

LLVM IR (-O2):
@.str = [26 x i8] c"Please enter a sentence: \00"
@stdin = global i32 0
@EXIT_FAILURE = global i32 0
@EOF = global i8 0
@.str.1 = [25 x i8] c"Average word length: %g\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %2, i32 256, i32 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %76, label %7
7: ; preds = %0
%8 = call i32 @strlen(i8* %2)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 10
br i1 %13, label %20, label %14
14: ; preds = %7, %14
%15 = call signext i8 (...) @getchar()
%16 = icmp ne i8 %15, 10
%17 = load i8, i8* @EOF
%18 = icmp ne i8 %15, %17
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %14, label %20
20: ; preds = %14, %7
%21 = load i8, i8* %2
%22 = icmp eq i8 %21, 0
br i1 %22, label %50, label %25
23: ; preds = %38
%24 = icmp eq i64 %39, 0
br i1 %24, label %50, label %44
25: ; preds = %20, %38
%26 = phi i8 [ %42, %38 ], [ %21, %20 ]
%27 = phi i8* [ %41, %38 ], [ %2, %20 ]
%28 = phi i64 [ %39, %38 ], [ 0, %20 ]
%29 = call i64 @isalnum(i8 signext %26)
%30 = icmp eq i64 %29, 0
br i1 %30, label %38, label %31
31: ; preds = %25
%32 = getelementptr inbounds i8, i8* %27, i64 1
%33 = load i8, i8* %32
%34 = call i64 @isalnum(i8 signext %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
store i8 0, i8* %32
%37 = add i64 %28, 1
br label %38
38: ; preds = %36, %31, %25
%39 = phi i64 [ %28, %31 ], [ %37, %36 ], [ %28, %25 ]
%40 = phi i8* [ %27, %31 ], [ %32, %36 ], [ %27, %25 ]
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 0
br i1 %43, label %23, label %25
44: ; preds = %23, %66
%45 = phi i64 [ %74, %66 ], [ 0, %23 ]
%46 = phi i8* [ %73, %66 ], [ %2, %23 ]
%47 = phi double [ %71, %66 ], [ 0.000000e+00, %23 ]
%48 = load i8, i8* %46
%49 = icmp eq i8 %48, 0
br i1 %49, label %66, label %57
50: ; preds = %66, %20, %23
%51 = phi i64 [ 0, %23 ], [ 0, %20 ], [ %39, %66 ]
%52 = phi double [ 0.000000e+00, %23 ], [ 0.000000e+00, %20 ], [ %71, %66 ]
%53 = uitofp i64 %51 to double
%54 = fdiv double %52, %53
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), double %54)
%56 = call signext i8 (...) @getchar()
br label %76
57: ; preds = %44, %62
%58 = phi i8 [ %64, %62 ], [ %48, %44 ]
%59 = phi i8* [ %63, %62 ], [ %46, %44 ]
%60 = call i64 @isalnum(i8 signext %58)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %57
%63 = getelementptr inbounds i8, i8* %59, i64 1
%64 = load i8, i8* %63
%65 = icmp eq i8 %64, 0
br i1 %65, label %66, label %57
66: ; preds = %57, %62, %44
%67 = phi i8* [ %46, %44 ], [ %63, %62 ], [ %59, %57 ]
%68 = call i32 @strlen(i8* %67)
%69 = sext i32 %68 to i64
%70 = uitofp i64 %69 to double
%71 = fadd double %47, %70
%72 = add nsw i64 %69, 1
%73 = getelementptr inbounds i8, i8* %67, i64 %72
%74 = add nuw i64 %45, 1
%75 = icmp eq i64 %74, %39
br i1 %75, label %50, label %44
76: ; preds = %0, %50
%77 = phi i32* [ @EXIT_SUCCESS, %50 ], [ @EXIT_FAILURE, %0 ]
%78 = load i32, i32* %77
ret i32 %78
}