#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 */
scalar_t__ non_repeating_characters(char *, int, int);
int strlen(char *);
int length_of_longest_substr(char *s) {
  for (int try_len = strlen(s); try_len > 0; try_len--) {
    int beg = 0;
    while (beg + try_len <= strlen(s)) {
      if (non_repeating_characters(s, beg, beg + try_len - 1))
        return try_len;
      beg++;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<length_of_longest_substr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11b3 <length_of_longest_substr+0x93>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jg     11a0 <length_of_longest_substr+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
add    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1030 <non_repeating_characters@plt>
cmp    $0x0,%rax
je     1192 <length_of_longest_substr+0x72>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ba <length_of_longest_substr+0x9a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1149 <length_of_longest_substr+0x29>
jmp    11a5 <length_of_longest_substr+0x85>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1138 <length_of_longest_substr+0x18>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<length_of_longest_substr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
xor    %r14d,%r14d
test   %eax,%eax
jle    119b <length_of_longest_substr+0x7b>
mov    %eax,%r15d
mov    %eax,%r12d
add    $0xffffffff,%r12d
jmp    1161 <length_of_longest_substr+0x41>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    -0x1(%r15),%eax
add    $0xffffffff,%r12d
cmp    $0x1,%r15d
mov    %eax,%r15d
jle    119b <length_of_longest_substr+0x7b>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %eax,%r15d
jg     1150 <length_of_longest_substr+0x30>
xor    %ebp,%ebp
lea    (%r12,%rbp,1),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <non_repeating_characters@plt>
test   %rax,%rax
jne    1198 <length_of_longest_substr+0x78>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rbp,1),%ecx
cmp    %eax,%ecx
jle    1170 <length_of_longest_substr+0x50>
jmp    1150 <length_of_longest_substr+0x30>
mov    %r15d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @length_of_longest_substr(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %4
br label %8
8: ; preds = %34, %1
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %37
11: ; preds = %8
store i32 0, i32* %5
br label %12
12: ; preds = %30, %11
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = add nsw i32 %13, %14
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = icmp sle i32 %15, %17
br i1 %18, label %19, label %33
19: ; preds = %12
%20 = load i8*, i8** %3
%21 = load i32, i32* %5
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = add nsw i32 %22, %23
%25 = sub nsw i32 %24, 1
%26 = call i64 @non_repeating_characters(i8* %20, i32 %21, i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %19
%29 = load i32, i32* %4
store i32 %29, i32* %2
br label %38
30: ; preds = %19
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %12
33: ; preds = %12
br label %34
34: ; preds = %33
%35 = load i32, i32* %4
%36 = add nsw i32 %35, -1
store i32 %36, i32* %4
br label %8
37: ; preds = %8
store i32 0, i32* %2
br label %38
38: ; preds = %37, %28
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
define i32 @length_of_longest_substr(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %22
4: ; preds = %1, %19
%5 = phi i32 [ %20, %19 ], [ %2, %1 ]
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %5, %6
br i1 %7, label %19, label %12
8: ; preds = %12
%9 = add nsw i32 %18, %5
%10 = tail call i32 @strlen(i8* %0)
%11 = icmp sgt i32 %9, %10
br i1 %11, label %19, label %12
12: ; preds = %4, %8
%13 = phi i32 [ %9, %8 ], [ %5, %4 ]
%14 = phi i32 [ %18, %8 ], [ 0, %4 ]
%15 = add nsw i32 %13, -1
%16 = tail call i64 @non_repeating_characters(i8* %0, i32 %14, i32 %15)
%17 = icmp eq i64 %16, 0
%18 = add nuw nsw i32 %14, 1
br i1 %17, label %8, label %22
19: ; preds = %8, %4
%20 = add nsw i32 %5, -1
%21 = icmp sgt i32 %5, 1
br i1 %21, label %4, label %22
22: ; preds = %19, %12, %1
%23 = phi i32 [ 0, %1 ], [ %5, %12 ], [ 0, %19 ]
ret i32 %23
}