#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__ calloc(int, size_t);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
size_t strcspn(char *, char *);
size_t strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *strstr(char const *, char *);
void retrieve_cluster_attr(const char *metric, const char *name, char **value) {
  char *pos = NULL;
  char *pattern;
  size_t length;
  pattern = malloc(strlen(name) + 2);
  sprintf(pattern, "%s=", name);
  if (metric)
    pos = strstr(metric, pattern);
  if (pos) {
    length = strcspn(pos, ";:\n");
    *value = (char *)calloc(1, length - strlen(name));
    strncpy(*value, pos + strlen(name) + 1, length - strlen(name) - 1);
  } else
    (*value = NULL);
  free(pattern);
}


x86 assembly (clang, -O0):
<retrieve_cluster_attr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe3d(%rip),%rsi
call   1090 <sprintf@plt>
cmpq   $0x0,-0x8(%rbp)
je     11e4 <retrieve_cluster_attr+0x64>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     128b <retrieve_cluster_attr+0x10b>
mov    -0x20(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1060 <strcspn@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x58(%rbp),%rsi
sub    %rax,%rsi
mov    $0x1,%edi
call   1070 <calloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdx
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
sub    %rax,%rdx
sub    $0x1,%rdx
call   1040 <strncpy@plt>
jmp    1296 <retrieve_cluster_attr+0x116>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<retrieve_cluster_attr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1050 <strlen@plt>
lea    0x2(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,%r15
lea    0xe52(%rip),%rsi
mov    %rax,%rdi
mov    %r13,%rdx
call   1090 <sprintf@plt>
test   %rbx,%rbx
je     1224 <retrieve_cluster_attr+0xa4>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     1224 <retrieve_cluster_attr+0xa4>
mov    %rax,%r12
lea    0xe2c(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcspn@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rsi
sub    %rax,%rsi
mov    $0x1,%edi
call   1070 <calloc@plt>
mov    %rax,%rbp
mov    %rax,(%r14)
mov    %r13,%rdi
call   1050 <strlen@plt>
lea    (%r12,%rax,1),%rsi
add    $0x1,%rsi
not    %rax
add    %rax,%rbx
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1040 <strncpy@plt>
jmp    122b <retrieve_cluster_attr+0xab>
movq   $0x0,(%r14)
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%s=\00"
@.str.1 = [4 x i8] c";:\0A\00"
define void @retrieve_cluster_attr(i8* %0, i8* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8** %2, i8*** %6
store i8* null, i8** %7
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = add i64 %11, 2
%13 = trunc i64 %12 to i32
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %8
%15 = load i8*, i8** %8
%16 = load i8*, i8** %5
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %4
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %3
%21 = load i8*, i8** %4
%22 = load i8*, i8** %8
%23 = call i8* @strstr(i8* %21, i8* %22)
store i8* %23, i8** %7
br label %24
24: ; preds = %20, %3
%25 = load i8*, i8** %7
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %50
27: ; preds = %24
%28 = load i8*, i8** %7
%29 = call i64 @strcspn(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i64 %29, i64* %9
%30 = load i64, i64* %9
%31 = load i8*, i8** %5
%32 = call i64 @strlen(i8* %31)
%33 = sub i64 %30, %32
%34 = call i64 @calloc(i32 1, i64 %33)
%35 = inttoptr i64 %34 to i8*
%36 = load i8**, i8*** %6
store i8* %35, i8** %36
%37 = load i8**, i8*** %6
%38 = load i8*, i8** %37
%39 = load i8*, i8** %7
%40 = load i8*, i8** %5
%41 = call i64 @strlen(i8* %40)
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i64, i64* %9
%45 = load i8*, i8** %5
%46 = call i64 @strlen(i8* %45)
%47 = sub i64 %44, %46
%48 = sub i64 %47, 1
%49 = call i32 @strncpy(i8* %38, i8* %43, i64 %48)
br label %52
50: ; preds = %24
%51 = load i8**, i8*** %6
store i8* null, i8** %51
br label %52
52: ; preds = %50, %27
%53 = load i8*, i8** %8
%54 = call i32 @free(i8* %53)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s=\00"
@.str.1 = [4 x i8] c";:\0A\00"
define void @retrieve_cluster_attr(i8* %0, i8* %1, i8** nocapture writeonly %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = trunc i64 %4 to i32
%6 = add i32 %5, 2
%7 = tail call i8* @malloc(i32 %6)
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
%9 = icmp eq i8* %0, null
br i1 %9, label %25, label %10
10: ; preds = %3
%11 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) %7)
%12 = icmp eq i8* %11, null
br i1 %12, label %25, label %13
13: ; preds = %10
%14 = tail call i64 @strcspn(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%16 = sub i64 %14, %15
%17 = tail call i64 @calloc(i32 1, i64 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %2
%19 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%20 = getelementptr inbounds i8, i8* %11, i64 %19
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = xor i64 %19, -1
%23 = add i64 %14, %22
%24 = tail call i32 @strncpy(i8* %18, i8* %21, i64 %23)
br label %26
25: ; preds = %3, %10
store i8* null, i8** %2
br label %26
26: ; preds = %25, %13
%27 = tail call i32 @free(i8* %7)
ret void
}