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

/* Variables and functions */
int /*<<< orphan*/ memset(int *, int, int);
int lengthOfLongestSubstring(char *s) {
  int offset[128];
  int max_len = 0;
  int len = 0;
  int index = 0;
  memset(offset, 0xff, sizeof(offset));
  while (*s != '\0') {
    if (offset[*s] == -1) {
      len++;
    } else {
      if (index - offset[*s] > len) {
        len++;
      } else {
        len = index - offset[*s];
      }
    }
    if (len > max_len) {
      max_len = len;
    }
    offset[*s++] = index++;
  }
  return max_len;
}


x86 assembly (clang, -O0):
<lengthOfLongestSubstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x214(%rbp)
movl   $0x0,-0x218(%rbp)
movl   $0x0,-0x21c(%rbp)
lea    -0x210(%rbp),%rdi
mov    $0xff,%esi
mov    $0x200,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1230 <lengthOfLongestSubstring+0x120>
mov    -0x8(%rbp),%rax
movsbq (%rax),%rax
cmpl   $0xffffffff,-0x210(%rbp,%rax,4)
ff
jne    118d <lengthOfLongestSubstring+0x7d>
mov    -0x218(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x218(%rbp)
jmp    11e2 <lengthOfLongestSubstring+0xd2>
mov    -0x21c(%rbp),%eax
mov    -0x8(%rbp),%rcx
movsbq (%rcx),%rcx
sub    -0x210(%rbp,%rcx,4),%eax
cmp    -0x218(%rbp),%eax
jle    11c2 <lengthOfLongestSubstring+0xb2>
mov    -0x218(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x218(%rbp)
jmp    11dd <lengthOfLongestSubstring+0xcd>
mov    -0x21c(%rbp),%eax
mov    -0x8(%rbp),%rcx
movsbq (%rcx),%rcx
sub    -0x210(%rbp,%rcx,4),%eax
mov    %eax,-0x218(%rbp)
jmp    11e2 <lengthOfLongestSubstring+0xd2>
mov    -0x218(%rbp),%eax
cmp    -0x214(%rbp),%eax
jle    1200 <lengthOfLongestSubstring+0xf0>
mov    -0x218(%rbp),%eax
mov    %eax,-0x214(%rbp)
mov    -0x21c(%rbp),%ecx
mov    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x21c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
movsbq (%rax),%rax
mov    %ecx,-0x210(%rbp,%rax,4)
jmp    1153 <lengthOfLongestSubstring+0x43>
mov    -0x214(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lengthOfLongestSubstring>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0xff,%esi
mov    $0x200,%edx
call   1030 <memset@plt>
mov    (%r14),%bl
test   %bl,%bl
je     1173 <lengthOfLongestSubstring+0x63>
xor    %ecx,%ecx
xor    %edx,%edx
xor    %eax,%eax
jmp    1162 <lengthOfLongestSubstring+0x52>
xchg   %ax,%ax
mov    %ecx,%ebx
sub    %edi,%ebx
cmp    %edx,%ebx
lea    0x1(%rdx),%edx
cmovle %ebx,%edx
cmp    %eax,%edx
cmovg  %edx,%eax
mov    %ecx,(%rsp,%rsi,4)
movzbl 0x1(%r14,%rcx,1),%ebx
add    $0x1,%rcx
test   %bl,%bl
je     1175 <lengthOfLongestSubstring+0x65>
movsbq %bl,%rsi
mov    (%rsp,%rsi,4),%edi
cmp    $0xffffffff,%edi
jne    1140 <lengthOfLongestSubstring+0x30>
add    $0x1,%edx
jmp    114c <lengthOfLongestSubstring+0x3c>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

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

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