#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 characters_count(const char *s) {
  int n = 0;
  int count[128] = {0};
  if (NULL == s) {
    return -1;
  }
  while (*s != '\0') {
    if (!count[*s]) {
      count[*s]++;
      n++;
    }
    s++;
  }
  return n;
}


x86 assembly (clang, -O0):
<characters_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1030 <memset@plt>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1151 <characters_count+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <characters_count+0xa5>
jmp    1156 <characters_count+0x46>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11af <characters_count+0x9f>
mov    -0x10(%rbp),%rax
movsbq (%rax),%rax
cmpl   $0x0,-0x220(%rbp,%rax,4)
jne    119e <characters_count+0x8e>
mov    -0x10(%rbp),%rax
movsbq (%rax),%rax
mov    -0x220(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x220(%rbp,%rax,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1156 <characters_count+0x46>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<characters_count>:
push   %rbp
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %ebp,%ebp
mov    $0x200,%edx
xor    %esi,%esi
call   1030 <memset@plt>
test   %rbx,%rbx
je     1161 <characters_count+0x51>
mov    (%rbx),%al
test   %al,%al
je     1166 <characters_count+0x56>
add    $0x1,%rbx
xor    %ebp,%ebp
jmp    114b <characters_count+0x3b>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1166 <characters_count+0x56>
movsbq %al,%rax
cmpl   $0x0,(%rsp,%rax,4)
jne    1140 <characters_count+0x30>
movl   $0x1,(%rsp,%rax,4)
add    $0x1,%ebp
jmp    1140 <characters_count+0x30>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x208,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @characters_count(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [128 x i32]
store i8* %0, i8** %3
store i32 0, i32* %4
%6 = bitcast [128 x i32]* %5 to i8*
%7 = load i8*, i8** %3
%8 = icmp eq i8* null, %7
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %37
10: ; preds = %1
br label %11
11: ; preds = %32, %10
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %35
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = sext i8 %18 to i64
%20 = getelementptr inbounds [128 x i32], [128 x i32]* %5, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = icmp ne i32 %21, 0
br i1 %22, label %32, label %23
23: ; preds = %16
%24 = load i8*, i8** %3
%25 = load i8, i8* %24
%26 = sext i8 %25 to i64
%27 = getelementptr inbounds [128 x i32], [128 x i32]* %5, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = add nsw i32 %28, 1
store i32 %29, i32* %27
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %32
32: ; preds = %23, %16
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %3
br label %11
35: ; preds = %11
%36 = load i32, i32* %4
store i32 %36, i32* %2
br label %37
37: ; preds = %35, %9
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @characters_count(i8* %0) {
%2 = alloca [128 x i32]
%3 = bitcast [128 x i32]* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %23, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %5, %18
%9 = phi i8 [ %21, %18 ], [ %6, %5 ]
%10 = phi i32 [ %19, %18 ], [ 0, %5 ]
%11 = phi i8* [ %20, %18 ], [ %0, %5 ]
%12 = sext i8 %9 to i64
%13 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %8
store i32 1, i32* %13
%17 = add nsw i32 %10, 1
br label %18
18: ; preds = %16, %8
%19 = phi i32 [ %10, %8 ], [ %17, %16 ]
%20 = getelementptr inbounds i8, i8* %11, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %8
23: ; preds = %18, %5, %1
%24 = phi i32 [ -1, %1 ], [ 0, %5 ], [ %19, %18 ]
ret i32 %24
}