#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 */
size_t strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char const *, size_t);
char *strstr(char const *, char const *);
char *findtype(const char *types, const char *t) {
  const char *p;
  size_t len;
  for (len = strlen(t); (p = strstr(types, t)); types = p + len) {
    if (!strncmp(p, t, len) && (p[len] == '\0' || p[len] == ','))
      return (char *)p;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<findtype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11cf <findtype+0x9f>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11b9 <findtype+0x89>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11ac <findtype+0x7c>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    11b9 <findtype+0x89>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d7 <findtype+0xa7>
jmp    11be <findtype+0x8e>
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    114d <findtype+0x1d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findtype>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1197 <findtype+0x67>
mov    %rax,%rbx
jmp    1176 <findtype+0x46>
nopl   0x0(%rax,%rax,1)
add    %r15,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1197 <findtype+0x67>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1160 <findtype+0x30>
movzbl (%rbx,%r15,1),%eax
test   %al,%al
je     1199 <findtype+0x69>
cmp    $0x2c,%al
jne    1160 <findtype+0x30>
jmp    1199 <findtype+0x69>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @findtype(i8* %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %17, label %6
6: ; preds = %2, %13
%7 = phi i8* [ %15, %13 ], [ %4, %2 ]
%8 = tail call i32 @strncmp(i8* %7, i8* %1, i64 %3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %7, i64 %3
%12 = load i8, i8* %11
switch i8 %12, label %13 [
i8 0, label %17
i8 44, label %17
]
13: ; preds = %10, %6
%14 = getelementptr inbounds i8, i8* %7, i64 %3
%15 = tail call i8* @strstr(i8* dereferenceable(1) %14, i8* dereferenceable(1) %1)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %6
17: ; preds = %10, %10, %13, %2
%18 = phi i8* [ null, %2 ], [ null, %13 ], [ %7, %10 ], [ %7, %10 ]
ret i8* %18
}