#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*/ strlen(char const *);
scalar_t__ strncmp(char *, char const *, int /*<<< orphan*/);
char *strstr_eucjp(const char *str, const char *search) {
  char *pos;
  pos = (char *)str;
  while (*pos != '\0') {
    if (*pos == *search) {
      if (strncmp(pos, search, strlen(search)) == 0) {
        return pos;
      }
    }
    if ((unsigned char)*pos == 0x8Fu) {
      pos += 3;
    } else if ((unsigned char)*pos >= 0x80u) {
      pos += 2;
    } else {
      pos += 1;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<strstr_eucjp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11fe <strstr_eucjp+0xde>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11a2 <strstr_eucjp+0x82>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    119d <strstr_eucjp+0x7d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1206 <strstr_eucjp+0xe6>
jmp    11a2 <strstr_eucjp+0x82>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x8f,%eax
jne    11c5 <strstr_eucjp+0xa5>
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
jmp    11f9 <strstr_eucjp+0xd9>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x80,%eax
jb     11e8 <strstr_eucjp+0xc8>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    11f4 <strstr_eucjp+0xd4>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11f9 <strstr_eucjp+0xd9>
jmp    1138 <strstr_eucjp+0x18>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr_eucjp>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1181 <strstr_eucjp+0x61>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x3,%r15d
jmp    115d <strstr_eucjp+0x3d>
nopl   0x0(%rax)
mov    %eax,%ecx
shr    $0x7,%cl
movzbl %cl,%ecx
add    $0x1,%rcx
cmp    $0x8f,%al
cmove  %r15,%rcx
movzbl (%rbx,%rcx,1),%eax
add    %rcx,%rbx
test   %al,%al
je     1181 <strstr_eucjp+0x61>
cmp    (%r14),%al
jne    1140 <strstr_eucjp+0x20>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1183 <strstr_eucjp+0x63>
movzbl (%rbx),%eax
jmp    1140 <strstr_eucjp+0x20>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @strstr_eucjp(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
store i8* %7, i8** %6
br label %8
8: ; preds = %51, %2
%9 = load i8*, i8** %6
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %52
13: ; preds = %8
%14 = load i8*, i8** %6
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %16, %19
br i1 %20, label %21, label %31
21: ; preds = %13
%22 = load i8*, i8** %6
%23 = load i8*, i8** %5
%24 = load i8*, i8** %5
%25 = call i32 @strlen(i8* %24)
%26 = call i64 @strncmp(i8* %22, i8* %23, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = load i8*, i8** %6
store i8* %29, i8** %3
br label %53
30: ; preds = %21
br label %31
31: ; preds = %30, %13
%32 = load i8*, i8** %6
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = icmp eq i32 %34, 143
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i64 3
store i8* %38, i8** %6
br label %51
39: ; preds = %31
%40 = load i8*, i8** %6
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = icmp uge i32 %42, 128
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = load i8*, i8** %6
%46 = getelementptr inbounds i8, i8* %45, i64 2
store i8* %46, i8** %6
br label %50
47: ; preds = %39
%48 = load i8*, i8** %6
%49 = getelementptr inbounds i8, i8* %48, i64 1
store i8* %49, i8** %6
br label %50
50: ; preds = %47, %44
br label %51
51: ; preds = %50, %36
br label %8
52: ; preds = %8
store i8* null, i8** %3
br label %53
53: ; preds = %52, %28
%54 = load i8*, i8** %3
ret i8* %54
}

LLVM IR (-O2):
define i8* @strstr_eucjp(i8* %0, i8* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %25, label %5
5: ; preds = %2, %16
%6 = phi i8 [ %23, %16 ], [ %3, %2 ]
%7 = phi i8* [ %22, %16 ], [ %0, %2 ]
%8 = load i8, i8* %1
%9 = icmp eq i8 %6, %8
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = tail call i32 @strlen(i8* %1)
%12 = tail call i64 @strncmp(i8* %7, i8* %1, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %25, label %14
14: ; preds = %10
%15 = load i8, i8* %7
br label %16
16: ; preds = %14, %5
%17 = phi i8 [ %15, %14 ], [ %6, %5 ]
%18 = icmp eq i8 %17, -113
%19 = icmp slt i8 %17, 0
%20 = select i1 %19, i64 2, i64 1
%21 = select i1 %18, i64 3, i64 %20
%22 = getelementptr inbounds i8, i8* %7, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %5
25: ; preds = %10, %16, %2
%26 = phi i8* [ null, %2 ], [ null, %16 ], [ %7, %10 ]
ret i8* %26
}