int num_jewels_in_stones(char *j, char *s) {
  char char_index[128];
  char *p;
  int count = 0;
  p = j;
  for (int i = 0; i < 128; i++) {
    char_index[i] = 0;
  }
  while (*p != '\0') {
    char_index[*p] = 1;
    p++;
  }
  p = s;
  while (*p != '\0') {
    if (char_index[*p] == 1) {
      count++;
    }
    p++;
  }
  return count;
}


x86 assembly (clang, -O0):
<num_jewels_in_stones>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x9c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x98(%rbp)
movl   $0x0,-0xa0(%rbp)
cmpl   $0x80,-0xa0(%rbp)
jge    1162 <num_jewels_in_stones+0x62>
movslq -0xa0(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
mov    -0xa0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa0(%rbp)
jmp    112f <num_jewels_in_stones+0x2f>
jmp    1167 <num_jewels_in_stones+0x67>
mov    -0x98(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a4 <num_jewels_in_stones+0xa4>
mov    -0x98(%rbp),%rax
movsbq (%rax),%rax
movb   $0x1,-0x90(%rbp,%rax,1)
01
mov    -0x98(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x98(%rbp)
jmp    1167 <num_jewels_in_stones+0x67>
mov    -0x10(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1204 <num_jewels_in_stones+0x104>
mov    -0x98(%rbp),%rax
movsbq (%rax),%rax
movsbl -0x90(%rbp,%rax,1),%eax
ff
cmp    $0x1,%eax
jne    11ed <num_jewels_in_stones+0xed>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
mov    -0x98(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x98(%rbp)
jmp    11af <num_jewels_in_stones+0xaf>
mov    -0x9c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_jewels_in_stones>:
push   %rax
xorps  %xmm0,%xmm0
movaps %xmm0,-0x10(%rsp)
movaps %xmm0,-0x20(%rsp)
movaps %xmm0,-0x30(%rsp)
movaps %xmm0,-0x40(%rsp)
movaps %xmm0,-0x50(%rsp)
movaps %xmm0,-0x60(%rsp)
movaps %xmm0,-0x70(%rsp)
movaps %xmm0,-0x80(%rsp)
mov    (%rdi),%al
test   %al,%al
je     1154 <num_jewels_in_stones+0x54>
add    $0x1,%rdi
cs nopw 0x0(%rax,%rax,1)
movsbq %al,%rax
movb   $0x1,-0x80(%rsp,%rax,1)
movzbl (%rdi),%eax
add    $0x1,%rdi
test   %al,%al
jne    1140 <num_jewels_in_stones+0x40>
mov    (%rsi),%cl
test   %cl,%cl
je     117d <num_jewels_in_stones+0x7d>
add    $0x1,%rsi
xor    %eax,%eax
movsbq %cl,%rcx
xor    %edx,%edx
cmpb   $0x1,-0x80(%rsp,%rcx,1)
sete   %dl
add    %edx,%eax
movzbl (%rsi),%ecx
add    $0x1,%rsi
test   %cl,%cl
jne    1160 <num_jewels_in_stones+0x60>
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

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

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