#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 */
char *strchr(char *, char);
scalar_t__ strlen(char *);
char *strndup(char *, int);
char *strstr(char const *, char *);
char *get_active_tag(const char *a) {
  char *t;
  char *c;
  if (!a)
    return NULL;
  t = strstr(a, ",active-tag:");
  if (!t)
    return NULL;
  t += 12;
  c = strchr(t, ',');
  return strndup(t, c ? c - t : (int)strlen(t));
}


x86 assembly (clang, -O0):
<get_active_tag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <get_active_tag+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11f7 <get_active_tag+0xb7>
mov    -0x10(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1190 <get_active_tag+0x50>
movq   $0x0,-0x8(%rbp)
jmp    11f7 <get_active_tag+0xb7>
mov    -0x18(%rbp),%rax
add    $0xc,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d5 <get_active_tag+0x95>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    11e4 <get_active_tag+0xa4>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cltq
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    %eax,%esi
call   1050 <strndup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_active_tag>:
push   %rbx
test   %rdi,%rdi
je     1175 <get_active_tag+0x35>
lea    0xeb3(%rip),%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     1175 <get_active_tag+0x35>
mov    %rax,%rbx
add    $0xc,%rbx
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1179 <get_active_tag+0x39>
sub    %rbx,%rax
jmp    1183 <get_active_tag+0x43>
xor    %eax,%eax
pop    %rbx
ret
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
mov    %rbx,%rdi
mov    %eax,%esi
pop    %rbx
jmp    1050 <strndup@plt>

LLVM IR (-O0):
@.str = [13 x i8] c",active-tag:\00"
define i8* @get_active_tag(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i8* null, i8** %2
br label %38
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i8* @strstr(i8* %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %9
store i8* null, i8** %2
br label %38
15: ; preds = %9
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 12
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = call i8* @strchr(i8* %18, i8 signext 44)
store i8* %19, i8** %5
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %29
23: ; preds = %15
%24 = load i8*, i8** %5
%25 = load i8*, i8** %4
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
br label %34
29: ; preds = %15
%30 = load i8*, i8** %4
%31 = call i64 @strlen(i8* %30)
%32 = trunc i64 %31 to i32
%33 = sext i32 %32 to i64
br label %34
34: ; preds = %29, %23
%35 = phi i64 [ %28, %23 ], [ %33, %29 ]
%36 = trunc i64 %35 to i32
%37 = call i8* @strndup(i8* %20, i32 %36)
store i8* %37, i8** %2
br label %38
38: ; preds = %34, %14, %8
%39 = load i8*, i8** %2
ret i8* %39
}

LLVM IR (-O2):
@.str = [13 x i8] c",active-tag:\00"
define noalias i8* @get_active_tag(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %22, label %3
3: ; preds = %1
%4 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %22, label %6
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %4, i64 12
%8 = tail call i8* @strchr(i8* %7, i8 signext 44)
%9 = icmp eq i8* %8, null
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = ptrtoint i8* %8 to i64
%12 = ptrtoint i8* %7 to i64
%13 = sub i64 %11, %12
br label %18
14: ; preds = %6
%15 = tail call i64 @strlen(i8* %7)
%16 = shl i64 %15, 32
%17 = ashr exact i64 %16, 32
br label %18
18: ; preds = %14, %10
%19 = phi i64 [ %13, %10 ], [ %17, %14 ]
%20 = trunc i64 %19 to i32
%21 = tail call i8* @strndup(i8* %7, i32 %20)
br label %22
22: ; preds = %3, %1, %18
%23 = phi i8* [ %21, %18 ], [ null, %1 ], [ null, %3 ]
ret i8* %23
}