#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*/ memcpy(char *, char *, int);
char *strchr(char *, char);
int strlen(char const *);
char *strstr(char const *, char const *);
char *xcalloc(int, int);
void getAttr(const char *data, const char *attr, char **val, char seperator) {
  char *start;
  if ((start = strstr(data, attr)) != NULL) {
    char *end;
    int len;
    end = strchr(start, seperator);
    if (end == NULL) {
      end = start + strlen(start);
    }
    len = end - start - strlen(attr);
    *val = xcalloc(len + 1, 1);
    memcpy(*val, start + strlen(attr), len);
    (*val)[len] = '\0';
  } else {
    *val = xcalloc(1, 1);
    (*val)[0] = '\0';
  }
}


x86 assembly (clang, -O0):
<getAttr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %cl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1247 <getAttr+0xf7>
mov    -0x28(%rbp),%rdi
movsbl -0x19(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c1 <getAttr+0x71>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
movslq %ecx,%rcx
sub    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <xcalloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdi
cltq
add    %rax,%rsi
mov    -0x34(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x34(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1267 <getAttr+0x117>
mov    $0x1,%esi
mov    %esi,%edi
call   1060 <xcalloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAttr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %rsi,%r15
call   1070 <strstr@plt>
test   %rax,%rax
je     11d2 <getAttr+0x82>
mov    %rax,%r12
movsbl %bl,%esi
mov    %rax,%rdi
call   1040 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    118f <getAttr+0x3f>
mov    %r12,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbx
add    %r12,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
add    %r12,%rax
sub    %rax,%rbx
lea    0x1(%rbx),%edi
mov    $0x1,%esi
call   1060 <xcalloc@plt>
mov    %rax,%r13
mov    %rax,(%r14)
mov    %r15,%rdi
call   1030 <strlen@plt>
movslq %eax,%rsi
add    %r12,%rsi
mov    %r13,%rdi
mov    %ebx,%edx
call   1050 <memcpy@plt>
movslq %ebx,%rax
add    (%r14),%rax
jmp    11e4 <getAttr+0x94>
mov    $0x1,%edi
mov    $0x1,%esi
call   1060 <xcalloc@plt>
mov    %rax,(%r14)
movb   $0x0,(%rax)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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