#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__ *);
scalar_t__ *realloc(scalar_t__ *, int);
int wcscspn(scalar_t__ *, char *);
void extract_class(wchar_t **key, wchar_t **cls) {
  int len = wcscspn(*key, L"#");
  if ((*key)[len] == 0) {
    *cls = 0;
    return;
  }
  *cls = compat_wcsdup(*key + len + 1);
  *key = realloc(*key, sizeof(wchar_t) * (len + 1));
  (*key)[len] = 0;
}


x86 assembly (clang, -O0):
<extract_class>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xeb2(%rip),%rsi
call   1030 <wcscspn@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    117c <extract_class+0x4c>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
jmp    11d8 <extract_class+0xa8>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
add    $0x8,%rdi
call   1050 <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   1040 <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)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_class>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rdi
lea    0xebb(%rip),%rsi
call   1030 <wcscspn@plt>
mov    (%r15),%rcx
movslq %eax,%rbx
cmpq   $0x0,(%rcx,%rbx,8)
je     1183 <extract_class+0x53>
lea    (%rcx,%rbx,8),%rdi
add    $0x8,%rdi
call   1050 <compat_wcsdup@plt>
mov    %rax,(%r14)
mov    (%r15),%rdi
lea    0x8(,%rbx,8),%esi
call   1040 <realloc@plt>
mov    %rax,(%r15)
movq   $0x0,(%rax,%rbx,8)
jmp    118a <extract_class+0x5a>
movq   $0x0,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i32] [i32 35, i32 0]
define void @extract_class(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 %41
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
br label %41
41: ; preds = %18, %16
ret void
}

LLVM IR (-O2):
@.str = [2 x i32] [i32 35, i32 0]
define void @extract_class(i64** nocapture %0, i64** nocapture writeonly %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 %19
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
br label %19
19: ; preds = %11, %10
ret void
}