#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 */
char *strchr(char *, char);
unsigned int strlen(char *);
char *winstr2(char *, char *);
char *winstr3(char *, char *);
char *winstr4(char *, char *);
char *winstr5(char *, char *);
char *winstr6(char *, char *);
char *winstr7(char *, char *);
char *winstr8(char *, char *);
char *winstrm(char *, char *, unsigned int);
char *winstr(char *tgt, char *pat) {
  unsigned len = strlen(pat);
  switch (len) {
  case 0:
    return tgt;
  case 1:
    return strchr(tgt, *pat);
  case 2:
    return winstr2(tgt, pat);
  case 3:
    return winstr3(tgt, pat);
  case 4:
    return winstr4(tgt, pat);
  case 5:
    return winstr5(tgt, pat);
  case 6:
    return winstr6(tgt, pat);
  case 7:
    return winstr7(tgt, pat);
  case 8:
    return winstr8(tgt, pat);
  default:
    return winstrm(tgt, pat, len);
  }
}


x86 assembly (clang, -O0):
<winstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rax,-0x28(%rbp)
sub    $0x8,%rax
ja     12a1 <winstr+0x101>
mov    -0x28(%rbp),%rax
lea    0xe28(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12b5 <winstr+0x115>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
call   1040 <strchr@plt>
mov    %rax,-0x8(%rbp)
jmp    12b5 <winstr+0x115>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <winstr2@plt>
mov    %rax,-0x8(%rbp)
jmp    12b5 <winstr+0x115>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <winstr3@plt>
mov    %rax,-0x8(%rbp)
jmp    12b5 <winstr+0x115>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10c0 <winstr4@plt>
mov    %rax,-0x8(%rbp)
jmp    12b5 <winstr+0x115>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <winstr5@plt>
mov    %rax,-0x8(%rbp)
jmp    12b5 <winstr+0x115>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <winstr6@plt>
mov    %rax,-0x8(%rbp)
jmp    12b5 <winstr+0x115>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <winstr7@plt>
mov    %rax,-0x8(%rbp)
jmp    12b5 <winstr+0x115>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <winstr8@plt>
mov    %rax,-0x8(%rbp)
jmp    12b5 <winstr+0x115>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1080 <winstrm@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<winstr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmp    $0x8,%eax
ja     11d4 <winstr+0x34>
mov    %eax,%eax
lea    0xe40(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <winstrm@plt>
movsbl (%rbx),%esi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <strchr@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10b0 <winstr2@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <winstr3@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10c0 <winstr4@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <winstr5@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10a0 <winstr6@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <winstr7@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <winstr8@plt>

LLVM IR (-O0):
define i8* @winstr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
switch i32 %9, label %45 [
i32 0, label %10
i32 1, label %12
i32 2, label %17
i32 3, label %21
i32 4, label %25
i32 5, label %29
i32 6, label %33
i32 7, label %37
i32 8, label %41
]
10: ; preds = %2
%11 = load i8*, i8** %4
store i8* %11, i8** %3
br label %50
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = call i8* @strchr(i8* %13, i8 signext %15)
store i8* %16, i8** %3
br label %50
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = load i8*, i8** %5
%20 = call i8* @winstr2(i8* %18, i8* %19)
store i8* %20, i8** %3
br label %50
21: ; preds = %2
%22 = load i8*, i8** %4
%23 = load i8*, i8** %5
%24 = call i8* @winstr3(i8* %22, i8* %23)
store i8* %24, i8** %3
br label %50
25: ; preds = %2
%26 = load i8*, i8** %4
%27 = load i8*, i8** %5
%28 = call i8* @winstr4(i8* %26, i8* %27)
store i8* %28, i8** %3
br label %50
29: ; preds = %2
%30 = load i8*, i8** %4
%31 = load i8*, i8** %5
%32 = call i8* @winstr5(i8* %30, i8* %31)
store i8* %32, i8** %3
br label %50
33: ; preds = %2
%34 = load i8*, i8** %4
%35 = load i8*, i8** %5
%36 = call i8* @winstr6(i8* %34, i8* %35)
store i8* %36, i8** %3
br label %50
37: ; preds = %2
%38 = load i8*, i8** %4
%39 = load i8*, i8** %5
%40 = call i8* @winstr7(i8* %38, i8* %39)
store i8* %40, i8** %3
br label %50
41: ; preds = %2
%42 = load i8*, i8** %4
%43 = load i8*, i8** %5
%44 = call i8* @winstr8(i8* %42, i8* %43)
store i8* %44, i8** %3
br label %50
45: ; preds = %2
%46 = load i8*, i8** %4
%47 = load i8*, i8** %5
%48 = load i32, i32* %6
%49 = call i8* @winstrm(i8* %46, i8* %47, i32 %48)
store i8* %49, i8** %3
br label %50
50: ; preds = %45, %41, %37, %33, %29, %25, %21, %17, %12, %10
%51 = load i8*, i8** %3
ret i8* %51
}

LLVM IR (-O2):
define i8* @winstr(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
switch i32 %3, label %21 [
i32 0, label %23
i32 1, label %4
i32 2, label %7
i32 3, label %9
i32 4, label %11
i32 5, label %13
i32 6, label %15
i32 7, label %17
i32 8, label %19
]
4: ; preds = %2
%5 = load i8, i8* %1
%6 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext %5)
br label %23
7: ; preds = %2
%8 = tail call i8* @winstr2(i8* %0, i8* %1)
br label %23
9: ; preds = %2
%10 = tail call i8* @winstr3(i8* %0, i8* %1)
br label %23
11: ; preds = %2
%12 = tail call i8* @winstr4(i8* %0, i8* %1)
br label %23
13: ; preds = %2
%14 = tail call i8* @winstr5(i8* %0, i8* %1)
br label %23
15: ; preds = %2
%16 = tail call i8* @winstr6(i8* %0, i8* %1)
br label %23
17: ; preds = %2
%18 = tail call i8* @winstr7(i8* %0, i8* %1)
br label %23
19: ; preds = %2
%20 = tail call i8* @winstr8(i8* %0, i8* %1)
br label %23
21: ; preds = %2
%22 = tail call i8* @winstrm(i8* %0, i8* %1, i32 %3)
br label %23
23: ; preds = %2, %21, %19, %17, %15, %13, %11, %9, %7, %4
%24 = phi i8* [ %22, %21 ], [ %20, %19 ], [ %18, %17 ], [ %16, %15 ], [ %14, %13 ], [ %12, %11 ], [ %10, %9 ], [ %8, %7 ], [ %6, %4 ], [ %0, %2 ]
ret i8* %24
}