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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char, ...);
int strlen(char *);
void findRepeatedChar2(char *str) {
  unsigned int val = 0;
  printf("sizeof(bitMap) %lu\n", sizeof(val));
  for (int i = 0; i < strlen(str); i++) {
    if ((val & (1 << (str[i] - 'a'))) > 0) {
      printf("%c[value %d] repeated at location %d bitmask 0x%x\n", str[i],
             str[i] - 'a', i, val);
    } else {
      val |= (1 << (str[i] - 'a'));
      printf("%c(value %d) 1st seen at location %d bitmask 0x%x\n", str[i],
             str[i] - 'a', i, val);
    }
  }
}


x86 assembly (clang, -O0):
<findRepeatedChar2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xec6(%rip),%rdi
mov    $0x4,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    1227 <findRepeatedChar2+0x107>
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
sub    $0x61,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jbe    11c6 <findRepeatedChar2+0xa6>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
movsbl (%rcx,%rdx,1),%edx
sub    $0x61,%edx
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%r8d
lea    0xe5d(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1214 <findRepeatedChar2+0xf4>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
sub    $0x61,%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
movsbl (%rcx,%rdx,1),%edx
sub    $0x61,%edx
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%r8d
lea    0xe3d(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1219 <findRepeatedChar2+0xf9>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114d <findRepeatedChar2+0x2d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findRepeatedChar2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
lea    0xece(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11a7 <findRepeatedChar2+0x87>
lea    0xef6(%rip),%r14
lea    0xebc(%rip),%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1189 <findRepeatedChar2+0x69>
xchg   %ax,%ax
or     %edx,%ebp
movsbl %al,%esi
mov    %r14,%rdi
mov    %ecx,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11a7 <findRepeatedChar2+0x87>
movsbl (%r12,%rbx,1),%eax
mov    %eax,%ecx
add    $0xffffff9f,%ecx
mov    $0x1,%edx
shl    %cl,%edx
bt     %ecx,%ebp
jae    1160 <findRepeatedChar2+0x40>
movsbl %al,%esi
mov    %r15,%rdi
jmp    1168 <findRepeatedChar2+0x48>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"sizeof(bitMap) %lu\0A\00"
@.str.1 = [51 x i8] c"%c[value %d] repeated at location %d bitmask 0x%x\0A\00"
@.str.2 = [51 x i8] c"%c(value %d) 1st seen at location %d bitmask 0x%x\0A\00"
define void @findRepeatedChar2(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8 signext 4)
store i32 0, i32* %4
br label %6
6: ; preds = %66, %1
%7 = load i32, i32* %4
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %69
11: ; preds = %6
%12 = load i32, i32* %3
%13 = load i8*, i8** %2
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = sub nsw i32 %18, 97
%20 = shl i32 1, %19
%21 = and i32 %12, %20
%22 = icmp ugt i32 %21, 0
br i1 %22, label %23, label %39
23: ; preds = %11
%24 = load i8*, i8** %2
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = load i8*, i8** %2
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = sub nsw i32 %34, 97
%36 = load i32, i32* %4
%37 = load i32, i32* %3
%38 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8 signext %28, i32 %35, i32 %36, i32 %37)
br label %65
39: ; preds = %11
%40 = load i8*, i8** %2
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = sub nsw i32 %45, 97
%47 = shl i32 1, %46
%48 = load i32, i32* %3
%49 = or i32 %48, %47
store i32 %49, i32* %3
%50 = load i8*, i8** %2
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = load i8*, i8** %2
%56 = load i32, i32* %4
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = sub nsw i32 %60, 97
%62 = load i32, i32* %4
%63 = load i32, i32* %3
%64 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8 signext %54, i32 %61, i32 %62, i32 %63)
br label %65
65: ; preds = %39, %23
br label %66
66: ; preds = %65
%67 = load i32, i32* %4
%68 = add nsw i32 %67, 1
store i32 %68, i32* %4
br label %6
69: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"sizeof(bitMap) %lu\0A\00"
@.str.1 = [51 x i8] c"%c[value %d] repeated at location %d bitmask 0x%x\0A\00"
@.str.2 = [51 x i8] c"%c(value %d) 1st seen at location %d bitmask 0x%x\0A\00"
define void @findRepeatedChar2(i8* %0) {
%2 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8 signext 4)
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %6, label %5
5: ; preds = %23, %1
ret void
6: ; preds = %1, %23
%7 = phi i64 [ %25, %23 ], [ 0, %1 ]
%8 = phi i32 [ %24, %23 ], [ 0, %1 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = add nsw i32 %11, -97
%13 = shl nuw nsw i32 1, %12
%14 = and i32 %13, %8
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %6
%17 = trunc i64 %7 to i32
%18 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8 signext %10, i32 %12, i32 %17, i32 %8)
br label %23
19: ; preds = %6
%20 = or i32 %13, %8
%21 = trunc i64 %7 to i32
%22 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8 signext %10, i32 %12, i32 %21, i32 %20)
br label %23
23: ; preds = %16, %19
%24 = phi i32 [ %8, %16 ], [ %20, %19 ]
%25 = add nuw nsw i64 %7, 1
%26 = tail call i32 @strlen(i8* %0)
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %6, label %5
}