#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*/ memcmp(char const *, char const *, size_t);
char *strchr(char const *, char);
size_t strlen(char const *);
int unicode_find_name(const char *name_table, const char *name) {
  const char *p, *r;
  int pos;
  size_t name_len, len;
  p = name_table;
  pos = 0;
  name_len = strlen(name);
  while (*p) {
    for (;;) {
      r = strchr(p, ',');
      if (!r)
        len = strlen(p);
      else
        len = r - p;
      if (len == name_len && !memcmp(p, name, name_len))
        return pos;
      p += len + 1;
      if (!r)
        break;
    }
    pos++;
  }
  return -1;
}


x86 assembly (clang, -O0):
<unicode_find_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1212 <unicode_find_name+0xe2>
jmp    116e <unicode_find_name+0x3e>
mov    -0x20(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119d <unicode_find_name+0x6d>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x40(%rbp)
jmp    11ac <unicode_find_name+0x7c>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    11df <unicode_find_name+0xaf>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1050 <memcmp@plt>
cmp    $0x0,%eax
jne    11df <unicode_find_name+0xaf>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1219 <unicode_find_name+0xe9>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ff <unicode_find_name+0xcf>
jmp    1204 <unicode_find_name+0xd4>
jmp    116e <unicode_find_name+0x3e>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115c <unicode_find_name+0x2c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unicode_find_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    $0xffffffff,%eax
cmpb   $0x0,0x0(%rbp)
je     11c8 <unicode_find_name+0x98>
xor    %r14d,%r14d
jmp    116c <unicode_find_name+0x3c>
nopl   0x0(%rax)
add    %rbx,%rbp
add    $0x1,%rbp
test   %r13,%r13
je     11b4 <unicode_find_name+0x84>
mov    %rbp,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,%r13
test   %rax,%rax
je     1190 <unicode_find_name+0x60>
mov    %r13,%rbx
sub    %rbp,%rbx
cmp    %r12,%rbx
jne    1160 <unicode_find_name+0x30>
jmp    11a0 <unicode_find_name+0x70>
xchg   %ax,%ax
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
cmp    %r12,%rbx
jne    1160 <unicode_find_name+0x30>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <bcmp@plt>
test   %eax,%eax
jne    1160 <unicode_find_name+0x30>
jmp    11c5 <unicode_find_name+0x95>
add    $0x1,%r14d
cmpb   $0x0,0x0(%rbp)
jne    116c <unicode_find_name+0x3c>
mov    $0xffffffff,%eax
jmp    11c8 <unicode_find_name+0x98>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @unicode_find_name(i8* %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %32, label %6
6: ; preds = %2, %28
%7 = phi i32 [ %29, %28 ], [ 0, %2 ]
%8 = phi i8* [ %27, %28 ], [ %0, %2 ]
br label %9
9: ; preds = %6, %25
%10 = phi i8* [ %27, %25 ], [ %8, %6 ]
%11 = tail call i8* @strchr(i8* dereferenceable(1) %10, i8 signext 44)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i64 @strlen(i8* dereferenceable(1) %10)
br label %19
15: ; preds = %9
%16 = ptrtoint i8* %11 to i64
%17 = ptrtoint i8* %10 to i64
%18 = sub i64 %16, %17
br label %19
19: ; preds = %15, %13
%20 = phi i64 [ %18, %15 ], [ %14, %13 ]
%21 = icmp eq i64 %20, %3
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = tail call i32 @bcmp(i8* %10, i8* %1, i64 %3)
%24 = icmp eq i32 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %22, %19
%26 = add i64 %20, 1
%27 = getelementptr inbounds i8, i8* %10, i64 %26
br i1 %12, label %28, label %9
28: ; preds = %25
%29 = add nuw nsw i32 %7, 1
%30 = load i8, i8* %27
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %6
32: ; preds = %28, %22, %2
%33 = phi i32 [ -1, %2 ], [ %7, %22 ], [ -1, %28 ]
ret i32 %33
}