#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ isspace(unsigned char);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int read(int, unsigned char *, int);
void count(int descr, size_t *l, size_t *w, size_t *s) {
  unsigned char *symb = (unsigned char *)malloc(sizeof(char));
  ssize_t r;
  size_t len = 0;
  while ((r = read(descr, symb, 1)) > 0) {
    unsigned char c = symb[0];
    ++(*s);
    if (c == '\n') {
      ++(*l);
    }
    if (!isspace(c)) {
      ++len;
    } else if (len > 0) {
      len = 0;
      ++(*w);
    }
  }
  if (len > 0) {
    ++(*w);
  }
  if (r == -1) {
    perror(NULL);
    close(descr);
    free(symb);
    exit(1);
  }
  free(symb);
}


x86 assembly (clang, -O0):
<count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jle    123a <count+0xca>
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x39(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
movzbl -0x39(%rbp),%eax
cmp    $0xa,%eax
jne    11ec <count+0x7c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
movzbl -0x39(%rbp),%edi
call   1050 <isspace@plt>
cmp    $0x0,%eax
jne    120f <count+0x9f>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1235 <count+0xc5>
cmpq   $0x0,-0x38(%rbp)
jbe    1230 <count+0xc0>
movq   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1235 <count+0xc5>
jmp    119d <count+0x2d>
cmpq   $0x0,-0x38(%rbp)
jbe    1253 <count+0xe3>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1281 <count+0x111>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <perror@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r13
mov    %rdx,%r14
mov    %rsi,%r12
mov    %edi,%r15d
mov    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %r15d,%edi
mov    %rax,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    11ff <count+0x8f>
xor    %ebp,%ebp
jmp    11c6 <count+0x56>
nopl   0x0(%rax)
xor    %ebp,%ebp
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    11f6 <count+0x86>
movzbl (%rbx),%eax
addq   $0x1,0x0(%r13)
cmp    $0xa,%al
jne    11d7 <count+0x67>
addq   $0x1,(%r12)
movzbl %al,%edi
call   1050 <isspace@plt>
test   %eax,%eax
je     11f0 <count+0x80>
test   %rbp,%rbp
je     11b0 <count+0x40>
addq   $0x1,(%r14)
jmp    11b0 <count+0x40>
xchg   %ax,%ax
add    $0x1,%rbp
jmp    11b2 <count+0x42>
test   %rbp,%rbp
je     11ff <count+0x8f>
addq   $0x1,(%r14)
cmp    $0xffffffff,%eax
je     121a <count+0xaa>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
xor    %edi,%edi
call   1080 <perror@plt>
mov    %r15d,%edi
call   1040 <close@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
define void @count(i32 %0, i64* %1, i64* %2, i64* %3) {
%5 = alloca i32
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i64
%12 = alloca i8
store i32 %0, i32* %5
store i64* %1, i64** %6
store i64* %2, i64** %7
store i64* %3, i64** %8
%13 = call i64 @malloc(i32 1)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %9
store i64 0, i64* %11
br label %15
15: ; preds = %49, %4
%16 = load i32, i32* %5
%17 = load i8*, i8** %9
%18 = call i32 @read(i32 %16, i8* %17, i32 1)
store i32 %18, i32* %10
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %50
20: ; preds = %15
%21 = load i8*, i8** %9
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
store i8 %23, i8* %12
%24 = load i64*, i64** %8
%25 = load i64, i64* %24
%26 = add i64 %25, 1
store i64 %26, i64* %24
%27 = load i8, i8* %12
%28 = zext i8 %27 to i32
%29 = icmp eq i32 %28, 10
br i1 %29, label %30, label %34
30: ; preds = %20
%31 = load i64*, i64** %6
%32 = load i64, i64* %31
%33 = add i64 %32, 1
store i64 %33, i64* %31
br label %34
34: ; preds = %30, %20
%35 = load i8, i8* %12
%36 = call i32 @isspace(i8 zeroext %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %34
%39 = load i64, i64* %11
%40 = add i64 %39, 1
store i64 %40, i64* %11
br label %49
41: ; preds = %34
%42 = load i64, i64* %11
%43 = icmp ugt i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %41
store i64 0, i64* %11
%45 = load i64*, i64** %7
%46 = load i64, i64* %45
%47 = add i64 %46, 1
store i64 %47, i64* %45
br label %48
48: ; preds = %44, %41
br label %49
49: ; preds = %48, %38
br label %15
50: ; preds = %15
%51 = load i64, i64* %11
%52 = icmp ugt i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %50
%54 = load i64*, i64** %7
%55 = load i64, i64* %54
%56 = add i64 %55, 1
store i64 %56, i64* %54
br label %57
57: ; preds = %53, %50
%58 = load i32, i32* %10
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %67
60: ; preds = %57
%61 = call i32 @perror(i32* null)
%62 = load i32, i32* %5
%63 = call i32 @close(i32 %62)
%64 = load i8*, i8** %9
%65 = call i32 @free(i8* %64)
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %57
%68 = load i8*, i8** %9
%69 = call i32 @free(i8* %68)
ret void
}

LLVM IR (-O2):
define void @count(i32 %0, i64* nocapture %1, i64* nocapture %2, i64* nocapture %3) {
%5 = tail call i64 @malloc(i32 1)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @read(i32 %0, i8* %6, i32 1)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %37
9: ; preds = %4, %28
%10 = phi i64 [ %29, %28 ], [ 0, %4 ]
%11 = load i8, i8* %6
%12 = load i64, i64* %3
%13 = add i64 %12, 1
store i64 %13, i64* %3
%14 = icmp eq i8 %11, 10
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i64, i64* %1
%17 = add i64 %16, 1
store i64 %17, i64* %1
br label %18
18: ; preds = %15, %9
%19 = tail call i32 @isspace(i8 zeroext %11)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = add i64 %10, 1
br label %28
23: ; preds = %18
%24 = icmp eq i64 %10, 0
br i1 %24, label %28, label %25
25: ; preds = %23
%26 = load i64, i64* %2
%27 = add i64 %26, 1
store i64 %27, i64* %2
br label %28
28: ; preds = %23, %25, %21
%29 = phi i64 [ 0, %25 ], [ 0, %23 ], [ %22, %21 ]
%30 = tail call i32 @read(i32 %0, i8* %6, i32 1)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %9, label %32
32: ; preds = %28
%33 = icmp eq i64 %29, 0
br i1 %33, label %37, label %34
34: ; preds = %32
%35 = load i64, i64* %2
%36 = add i64 %35, 1
store i64 %36, i64* %2
br label %37
37: ; preds = %4, %34, %32
%38 = phi i32 [ %30, %34 ], [ %30, %32 ], [ %7, %4 ]
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = tail call i32 @perror(i32* null)
%42 = tail call i32 @close(i32 %0)
%43 = tail call i32 @free(i8* %6)
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %37
%46 = tail call i32 @free(i8* %6)
ret void
}