#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 /*<<< orphan*/ bzero(char *, int);
size_t strlen(char *);
int lengthOfLongestSubstring(char *s) {
  int retval = 0;
  size_t sl = strlen(s);
  char buffer[128] = {0};
  for (size_t i = 0; i < sl; i++) {
    int length = -1;
    bzero(buffer, 128);
    for (size_t j = i; j < sl; j++) {
      if (buffer[s[j]]) {
        length = j - i;
        break;
      } else {
        buffer[s[j]] = 1;
      }
    }
    if (length == -1) {
      length = sl - i;
    }
    if (retval < length) {
      retval = length;
    }
  }
  return retval;
}


x86 assembly (clang, -O0):
<lengthOfLongestSubstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
movq   $0x0,-0xa8(%rbp)
mov    -0xa8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1279 <lengthOfLongestSubstring+0x149>
movl   $0xffffffff,-0xac(%rbp)
ff ff ff
lea    -0xa0(%rbp),%rdi
mov    $0x80,%esi
call   1050 <bzero@plt>
mov    -0xa8(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0xb8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1227 <lengthOfLongestSubstring+0xf7>
mov    -0x8(%rbp),%rax
mov    -0xb8(%rbp),%rcx
movsbq (%rax,%rcx,1),%rax
cmpb   $0x0,-0xa0(%rbp,%rax,1)
je     11f3 <lengthOfLongestSubstring+0xc3>
mov    -0xb8(%rbp),%rax
sub    -0xa8(%rbp),%rax
mov    %eax,-0xac(%rbp)
jmp    1227 <lengthOfLongestSubstring+0xf7>
mov    -0x8(%rbp),%rax
mov    -0xb8(%rbp),%rcx
movsbq (%rax,%rcx,1),%rax
movb   $0x1,-0xa0(%rbp,%rax,1)
01
jmp    1210 <lengthOfLongestSubstring+0xe0>
mov    -0xb8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xb8(%rbp)
jmp    11ab <lengthOfLongestSubstring+0x7b>
cmpl   $0xffffffff,-0xac(%rbp)
jne    1245 <lengthOfLongestSubstring+0x115>
mov    -0x18(%rbp),%rax
sub    -0xa8(%rbp),%rax
mov    %eax,-0xac(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0xac(%rbp),%eax
jge    125d <lengthOfLongestSubstring+0x12d>
mov    -0xac(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1262 <lengthOfLongestSubstring+0x132>
mov    -0xa8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xa8(%rbp)
jmp    1171 <lengthOfLongestSubstring+0x41>
mov    -0xc(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lengthOfLongestSubstring>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %rdi,%r14
call   1030 <strlen@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
test   %rax,%rax
je     11d9 <lengthOfLongestSubstring+0xb9>
mov    %rax,%rbx
xor    %ebp,%ebp
mov    %rsp,%r15
xor    %r12d,%r12d
jmp    1194 <lengthOfLongestSubstring+0x74>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%eax
sub    %ebp,%eax
cmp    %eax,%r12d
cmovl  %eax,%r12d
add    $0x1,%rbp
cmp    %rbx,%rbp
je     11dc <lengthOfLongestSubstring+0xbc>
mov    %r15,%rdi
mov    $0x80,%esi
call   1040 <bzero@plt>
xor    %eax,%eax
mov    %rbp,%rcx
cs nopw 0x0(%rax,%rax,1)
movsbq (%r14,%rcx,1),%rdx
cmpb   $0x0,(%rsp,%rdx,1)
jne    11d0 <lengthOfLongestSubstring+0xb0>
movb   $0x1,(%rsp,%rdx,1)
add    $0x1,%rcx
add    $0xffffffff,%eax
cmp    %rbx,%rcx
jb     11b0 <lengthOfLongestSubstring+0x90>
jmp    1180 <lengthOfLongestSubstring+0x60>
nopl   (%rax)
cmp    $0x1,%eax
je     1180 <lengthOfLongestSubstring+0x60>
neg    %eax
jmp    1184 <lengthOfLongestSubstring+0x64>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @lengthOfLongestSubstring(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca [128 x i8]
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %2
store i32 0, i32* %3
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %4
%11 = bitcast [128 x i8]* %5 to i8*
store i64 0, i64* %6
br label %12
12: ; preds = %64, %1
%13 = load i64, i64* %6
%14 = load i64, i64* %4
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %67
16: ; preds = %12
store i32 -1, i32* %7
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%18 = call i32 @bzero(i8* %17, i32 128)
%19 = load i64, i64* %6
store i64 %19, i64* %8
br label %20
20: ; preds = %46, %16
%21 = load i64, i64* %8
%22 = load i64, i64* %4
%23 = icmp ult i64 %21, %22
br i1 %23, label %24, label %49
24: ; preds = %20
%25 = load i8*, i8** %2
%26 = load i64, i64* %8
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%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
%31 = load i8, i8* %30
%32 = icmp ne i8 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %24
%34 = load i64, i64* %8
%35 = load i64, i64* %6
%36 = sub i64 %34, %35
%37 = trunc i64 %36 to i32
store i32 %37, i32* %7
br label %49
38: ; preds = %24
%39 = load i8*, i8** %2
%40 = load i64, i64* %8
%41 = getelementptr inbounds i8, i8* %39, i64 %40
%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
store i8 1, i8* %44
br label %45
45: ; preds = %38
br label %46
46: ; preds = %45
%47 = load i64, i64* %8
%48 = add i64 %47, 1
store i64 %48, i64* %8
br label %20
49: ; preds = %33, %20
%50 = load i32, i32* %7
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %57
52: ; preds = %49
%53 = load i64, i64* %4
%54 = load i64, i64* %6
%55 = sub i64 %53, %54
%56 = trunc i64 %55 to i32
store i32 %56, i32* %7
br label %57
57: ; preds = %52, %49
%58 = load i32, i32* %3
%59 = load i32, i32* %7
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = load i32, i32* %7
store i32 %62, i32* %3
br label %63
63: ; preds = %61, %57
br label %64
64: ; preds = %63
%65 = load i64, i64* %6
%66 = add i64 %65, 1
store i64 %66, i64* %6
br label %12
67: ; preds = %12
%68 = load i32, i32* %3
ret i32 %68
}

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