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

/* Variables and functions */
int max(int, int);
int /*<<< orphan*/ memset(int *, int, int);
int lengthOfLongestSubstring(char *s) {
  int index[256];
  memset(index, -1, sizeof(index));
  int current_left = -1;
  int current_max = 0;
  for (int i = 0; s[i] != '\0'; ++i) {
    current_left = max(current_left, index[s[i]]);
    current_max = max(current_max, i - current_left);
    index[s[i]] = i;
  }
  return current_max;
}


x86 assembly (clang, -O0):
<lengthOfLongestSubstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0xffffffff,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
movl   $0xffffffff,-0x414(%rbp)
ff ff ff
movl   $0x0,-0x418(%rbp)
movl   $0x0,-0x41c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x41c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11f1 <lengthOfLongestSubstring+0xd1>
mov    -0x414(%rbp),%edi
mov    -0x8(%rbp),%rax
movslq -0x41c(%rbp),%rcx
movsbq (%rax,%rcx,1),%rax
mov    -0x410(%rbp,%rax,4),%esi
call   1030 <max@plt>
mov    %eax,-0x414(%rbp)
mov    -0x418(%rbp),%edi
mov    -0x41c(%rbp),%esi
sub    -0x414(%rbp),%esi
call   1030 <max@plt>
mov    %eax,-0x418(%rbp)
mov    -0x41c(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq -0x41c(%rbp),%rdx
movsbq (%rax,%rdx,1),%rax
mov    %ecx,-0x410(%rbp,%rax,4)
mov    -0x41c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x41c(%rbp)
jmp    1163 <lengthOfLongestSubstring+0x43>
mov    -0x418(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lengthOfLongestSubstring>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0xffffffff,%ebp
mov    $0xffffffff,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    (%r14),%al
test   %al,%al
je     1197 <lengthOfLongestSubstring+0x77>
xor    %ebx,%ebx
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbq %al,%rax
mov    (%rsp,%rax,4),%esi
mov    %ebp,%edi
call   1030 <max@plt>
mov    %eax,%ebp
mov    %ebx,%esi
sub    %eax,%esi
mov    %r15d,%edi
call   1030 <max@plt>
mov    %eax,%r15d
movsbq (%r14,%rbx,1),%rax
mov    %ebx,(%rsp,%rax,4)
movzbl 0x1(%r14,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <lengthOfLongestSubstring+0x40>
jmp    119a <lengthOfLongestSubstring+0x7a>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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