#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 ClassFromChN(char const);
int ClassFromChWS(char const);
int classify(const char *pszText, int *pcls, int cch, char fWS) {
  int ich;
  if (fWS) {
    for (ich = 0; ich < cch; ich++) {
      pcls[ich] = ClassFromChWS(pszText[ich]);
    }
    return ich;
  } else {
    for (ich = 0; ich < cch; ich++) {
      pcls[ich] = ClassFromChN(pszText[ich]);
    }
    return ich;
  }
}


x86 assembly (clang, -O0):
<classify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
cmpb   $0x0,-0x1d(%rbp)
je     118c <classify+0x6c>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1181 <classify+0x61>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <ClassFromChWS@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1149 <classify+0x29>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d1 <classify+0xb1>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11cb <classify+0xab>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <ClassFromChN@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1193 <classify+0x73>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<classify>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%r12
test   %cl,%cl
je     1159 <classify+0x39>
test   %r14d,%r14d
jle    1189 <classify+0x69>
mov    %r14d,%ebx
xor    %ebp,%ebp
nop
movsbl (%r12,%rbp,1),%edi
call   1030 <ClassFromChWS@plt>
mov    %eax,(%r15,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1140 <classify+0x20>
jmp    118c <classify+0x6c>
test   %r14d,%r14d
jle    1189 <classify+0x69>
mov    %r14d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%r12,%rbp,1),%edi
call   1040 <ClassFromChN@plt>
mov    %eax,(%r15,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1170 <classify+0x50>
jmp    118c <classify+0x6c>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @classify(i8* %0, i32* %1, i32 %2, i8 signext %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8
%10 = alloca i32
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i8 %3, i8* %9
%11 = load i8, i8* %9
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %34
13: ; preds = %4
store i32 0, i32* %10
br label %14
14: ; preds = %29, %13
%15 = load i32, i32* %10
%16 = load i32, i32* %8
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %32
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = load i32, i32* %10
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = call i32 @ClassFromChWS(i8 signext %23)
%25 = load i32*, i32** %7
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
store i32 %24, i32* %28
br label %29
29: ; preds = %18
%30 = load i32, i32* %10
%31 = add nsw i32 %30, 1
store i32 %31, i32* %10
br label %14
32: ; preds = %14
%33 = load i32, i32* %10
store i32 %33, i32* %5
br label %55
34: ; preds = %4
store i32 0, i32* %10
br label %35
35: ; preds = %50, %34
%36 = load i32, i32* %10
%37 = load i32, i32* %8
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %53
39: ; preds = %35
%40 = load i8*, i8** %6
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = call i32 @ClassFromChN(i8 signext %44)
%46 = load i32*, i32** %7
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
store i32 %45, i32* %49
br label %50
50: ; preds = %39
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %35
53: ; preds = %35
%54 = load i32, i32* %10
store i32 %54, i32* %5
br label %55
55: ; preds = %53, %32
%56 = load i32, i32* %5
ret i32 %56
}

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