#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 */
typedef scalar_t__ wchar_t;

/* Variables and functions */
scalar_t__ *compat_wcsdup(scalar_t__ *);
int mywcscspn(scalar_t__ *, char *, int);
scalar_t__ *realloc(scalar_t__ *, int);
int wcscspn(scalar_t__ *, char *);
void extract_name(wchar_t **key, wchar_t **name) {
  int len = wcscspn(*key, L"[");
  if ((*key)[len] == 0) {
    *name = 0;
    return;
  }
  *name = compat_wcsdup(*key + len + 1);
  *key = realloc(*key, sizeof(wchar_t) * (len + 1));
  (*key)[len] = 0;
  len = mywcscspn(*name, L"]", 0x01);
  (*name)[len] = 0;
}


x86 assembly (clang, -O0):
<extract_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xea2(%rip),%rsi
call   1040 <wcscspn@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    118c <extract_name+0x4c>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
jmp    1216 <extract_name+0xd6>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
add    $0x8,%rdi
call   1060 <compat_wcsdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe12(%rip),%rsi
mov    $0x1,%edx
call   1030 <mywcscspn@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_name>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rdi
lea    0xeab(%rip),%rsi
call   1040 <wcscspn@plt>
mov    (%r15),%rcx
movslq %eax,%rbx
cmpq   $0x0,(%rcx,%rbx,8)
je     11b4 <extract_name+0x74>
lea    (%rcx,%rbx,8),%rdi
add    $0x8,%rdi
call   1060 <compat_wcsdup@plt>
mov    %rax,(%r14)
mov    (%r15),%rdi
lea    0x8(,%rbx,8),%esi
call   1050 <realloc@plt>
mov    %rax,(%r15)
movq   $0x0,(%rax,%rbx,8)
mov    (%r14),%rdi
lea    0xe6d(%rip),%rsi
mov    $0x1,%edx
call   1030 <mywcscspn@plt>
mov    (%r14),%rcx
cltq
movq   $0x0,(%rcx,%rax,8)
jmp    11bb <extract_name+0x7b>
movq   $0x0,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i32] [i32 91, i32 0]
@.str.1 = [2 x i32] [i32 93, i32 0]
define void @extract_name(i64** %0, i64** %1) {
%3 = alloca i64**
%4 = alloca i64**
%5 = alloca i32
store i64** %0, i64*** %3
store i64** %1, i64*** %4
%6 = load i64**, i64*** %3
%7 = load i64*, i64** %6
%8 = call i32 @wcscspn(i64* %7, i8* bitcast ([2 x i32]* @.str to i8*))
store i32 %8, i32* %5
%9 = load i64**, i64*** %3
%10 = load i64*, i64** %9
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i64, i64* %10, i64 %12
%14 = load i64, i64* %13
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = load i64**, i64*** %4
store i64* null, i64** %17
br label %49
18: ; preds = %2
%19 = load i64**, i64*** %3
%20 = load i64*, i64** %19
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i64, i64* %20, i64 %22
%24 = getelementptr inbounds i64, i64* %23, i64 1
%25 = call i64* @compat_wcsdup(i64* %24)
%26 = load i64**, i64*** %4
store i64* %25, i64** %26
%27 = load i64**, i64*** %3
%28 = load i64*, i64** %27
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = mul i64 8, %31
%33 = trunc i64 %32 to i32
%34 = call i64* @realloc(i64* %28, i32 %33)
%35 = load i64**, i64*** %3
store i64* %34, i64** %35
%36 = load i64**, i64*** %3
%37 = load i64*, i64** %36
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i64, i64* %37, i64 %39
store i64 0, i64* %40
%41 = load i64**, i64*** %4
%42 = load i64*, i64** %41
%43 = call i32 @mywcscspn(i64* %42, i8* bitcast ([2 x i32]* @.str.1 to i8*), i32 1)
store i32 %43, i32* %5
%44 = load i64**, i64*** %4
%45 = load i64*, i64** %44
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i64, i64* %45, i64 %47
store i64 0, i64* %48
br label %49
49: ; preds = %18, %16
ret void
}

LLVM IR (-O2):
@.str = [2 x i32] [i32 91, i32 0]
@.str.1 = [2 x i32] [i32 93, i32 0]
define void @extract_name(i64** nocapture %0, i64** nocapture %1) {
%3 = load i64*, i64** %0
%4 = tail call i32 @wcscspn(i64* %3, i8* bitcast ([2 x i32]* @.str to i8*))
%5 = load i64*, i64** %0
%6 = sext i32 %4 to i64
%7 = getelementptr inbounds i64, i64* %5, i64 %6
%8 = load i64, i64* %7
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i64* null, i64** %1
br label %24
11: ; preds = %2
%12 = getelementptr inbounds i64, i64* %7, i64 1
%13 = tail call i64* @compat_wcsdup(i64* %12)
store i64* %13, i64** %1
%14 = load i64*, i64** %0
%15 = shl i32 %4, 3
%16 = add i32 %15, 8
%17 = tail call i64* @realloc(i64* %14, i32 %16)
store i64* %17, i64** %0
%18 = getelementptr inbounds i64, i64* %17, i64 %6
store i64 0, i64* %18
%19 = load i64*, i64** %1
%20 = tail call i32 @mywcscspn(i64* %19, i8* bitcast ([2 x i32]* @.str.1 to i8*), i32 1)
%21 = load i64*, i64** %1
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i64, i64* %21, i64 %22
store i64 0, i64* %23
br label %24
24: ; preds = %11, %10
ret void
}