#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__ is_basic_type(char const *);
size_t find_type_len(const char *buf, size_t end) {
  size_t last_type_name_character = end;
  int paren = 0;
  while (0 < last_type_name_character) {
    char c = buf[last_type_name_character];
    paren += (')' == c);
    paren -= ('(' == c);
    if ((' ' == c) && (0 == paren)) {
      if (0 == is_basic_type(&buf[last_type_name_character + 1])) {
        return last_type_name_character;
      }
    }
    last_type_name_character--;
  }
  return end;
}


x86 assembly (clang, -O0):
<find_type_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jae    11de <find_type_len+0xce>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x25(%rbp)
movsbl -0x25(%rbp),%ecx
mov    $0x29,%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
movsbl -0x25(%rbp),%ecx
mov    $0x28,%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
movsbl -0x25(%rbp),%ecx
mov    $0x20,%eax
cmp    %ecx,%eax
jne    11cd <find_type_len+0xbd>
xor    %eax,%eax
cmp    -0x24(%rbp),%eax
jne    11cd <find_type_len+0xbd>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
add    $0x1,%rax
add    %rax,%rdi
call   1030 <is_basic_type@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11c8 <find_type_len+0xb8>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e6 <find_type_len+0xd6>
jmp    11cd <find_type_len+0xbd>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    112f <find_type_len+0x1f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_type_len>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
xor    %r12d,%r12d
test   %rsi,%rsi
je     1168 <find_type_len+0x58>
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x1(%rdi),%r13
mov    %rsi,%rbx
jmp    1136 <find_type_len+0x26>
add    $0xffffffffffffffff,%rbx
je     116c <find_type_len+0x5c>
movzbl (%r15,%rbx,1),%eax
xor    %ecx,%ecx
cmp    $0x29,%al
sete   %cl
add    %ecx,%r12d
xor    %ecx,%ecx
cmp    $0x28,%al
sete   %cl
sub    %ecx,%r12d
cmp    $0x20,%al
jne    1130 <find_type_len+0x20>
test   %r12d,%r12d
jne    1130 <find_type_len+0x20>
lea    (%rbx,%r13,1),%rdi
call   1030 <is_basic_type@plt>
test   %rax,%rax
jne    1130 <find_type_len+0x20>
jmp    116f <find_type_len+0x5f>
xor    %ebx,%ebx
jmp    116f <find_type_len+0x5f>
mov    %r14,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @find_type_len(i8* %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %26, label %4
4: ; preds = %2, %23
%5 = phi i32 [ %14, %23 ], [ 0, %2 ]
%6 = phi i64 [ %24, %23 ], [ %1, %2 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 41
%10 = zext i1 %9 to i32
%11 = add nsw i32 %5, %10
%12 = icmp eq i8 %8, 40
%13 = sext i1 %12 to i32
%14 = add i32 %11, %13
%15 = icmp eq i8 %8, 32
%16 = icmp eq i32 %14, 0
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %18, label %23
18: ; preds = %4
%19 = add i64 %6, 1
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = tail call i64 @is_basic_type(i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %4, %18
%24 = add i64 %6, -1
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %4
26: ; preds = %23, %18, %2
%27 = phi i64 [ 0, %2 ], [ %6, %18 ], [ %1, %23 ]
ret i64 %27
}