#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
unsigned readNonspace(FILE *f, char buf[], unsigned len) {
  unsigned cnt = 0;
  int c;
  while (cnt < len && (c = fgetc(f)) != EOF) {
    switch (c) {
    default:
      buf[cnt++] = c;
      continue;
    case ' ':
    case '\t':
    case '\r':
    case '\n':
      ungetc(c, f);
    }
    break;
  }
  buf[cnt] = '\0';
  return cnt;
}


x86 assembly (clang, -O0):
<readNonspace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jae    1166 <readNonspace+0x46>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e8a(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1176 <readNonspace+0x56>
jmp    11de <readNonspace+0xbe>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
add    $0xfffffff7,%eax
sub    $0x2,%eax
jb     11cd <readNonspace+0xad>
jmp    118d <readNonspace+0x6d>
mov    -0x24(%rbp),%eax
sub    $0xd,%eax
je     11cd <readNonspace+0xad>
jmp    119e <readNonspace+0x7e>
mov    -0x24(%rbp),%eax
sub    $0x20,%eax
je     11cd <readNonspace+0xad>
jmp    11af <readNonspace+0x8f>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
jmp    113a <readNonspace+0x1a>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1040 <ungetc@plt>
jmp    11de <readNonspace+0xbe>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readNonspace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
test   %edx,%edx
je     1184 <readNonspace+0x64>
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
mov    0x2ea7(%rip),%r13
movabs $0x100002600,%rbp
jmp    115d <readNonspace+0x3d>
nopl   (%rax)
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
je     1188 <readNonspace+0x68>
mov    %r15,%rdi
call   1030 <fgetc@plt>
cmp    0x0(%r13),%eax
je     118b <readNonspace+0x6b>
cmp    $0x20,%eax
ja     1150 <readNonspace+0x30>
mov    %eax,%ecx
bt     %rcx,%rbp
jae    1150 <readNonspace+0x30>
mov    %eax,%edi
mov    %r15,%rsi
call   1040 <ungetc@plt>
jmp    118b <readNonspace+0x6b>
xor    %ebx,%ebx
jmp    118b <readNonspace+0x6b>
mov    %r12d,%ebx
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @readNonspace(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %22, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp ult i32 %10, %11
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i32*, i32** %4
%15 = call i32 @fgetc(i32* %14)
store i32 %15, i32* %8
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %15, %16
br label %18
18: ; preds = %13, %9
%19 = phi i1 [ false, %9 ], [ %17, %13 ]
br i1 %19, label %20, label %35
20: ; preds = %18
%21 = load i32, i32* %8
switch i32 %21, label %22 [
i32 32, label %30
i32 9, label %30
i32 13, label %30
i32 10, label %30
]
22: ; preds = %20
%23 = load i32, i32* %8
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %5
%26 = load i32, i32* %7
%27 = add i32 %26, 1
store i32 %27, i32* %7
%28 = zext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8 %24, i8* %29
br label %9
30: ; preds = %20, %20, %20, %20
%31 = load i32, i32* %8
%32 = load i32*, i32** %4
%33 = call i32 @ungetc(i32 %31, i32* %32)
br label %34
34: ; preds = %30
br label %35
35: ; preds = %34, %18
%36 = load i8*, i8** %5
%37 = load i32, i32* %7
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
%40 = load i32, i32* %7
ret i32 %40
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @readNonspace(i32* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %23, label %5
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %13
%8 = phi i64 [ 0, %5 ], [ %15, %13 ]
%9 = tail call i32 @fgetc(i32* %0)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %21, label %12
12: ; preds = %7
switch i32 %9, label %13 [
i32 32, label %18
i32 9, label %18
i32 13, label %18
i32 10, label %18
]
13: ; preds = %12
%14 = trunc i32 %9 to i8
%15 = add nuw nsw i64 %8, 1
%16 = getelementptr inbounds i8, i8* %1, i64 %8
store i8 %14, i8* %16
%17 = icmp eq i64 %15, %6
br i1 %17, label %23, label %7
18: ; preds = %12, %12, %12, %12
%19 = trunc i64 %8 to i32
%20 = tail call i32 @ungetc(i32 %9, i32* %0)
br label %23
21: ; preds = %7
%22 = trunc i64 %8 to i32
br label %23
23: ; preds = %13, %21, %3, %18
%24 = phi i32 [ %19, %18 ], [ 0, %3 ], [ %22, %21 ], [ %2, %13 ]
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %1, i64 %25
store i8 0, i8* %26
ret i32 %24
}