#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 *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *strchr(char *, char);
char *strstr(char const *, char const *);
char *GetAttribute(const char *strAttribute, const char *strElement) {
  char *pMatch;
  char *pEnd;
  char *strOut;
  pMatch = strstr(strElement, strAttribute);
  if (NULL == pMatch)
    return NULL;
  pMatch = strchr(pMatch, '=');
  if (NULL == pMatch)
    return NULL;
  pMatch = strchr(pMatch, '\"');
  if (NULL == pMatch)
    return NULL;
  pMatch++;
  pEnd = strchr(pMatch, '\"');
  if (NULL == pEnd)
    return NULL;
  strOut = malloc(pEnd - pMatch + 1);
  memcpy(strOut, pMatch, pEnd - pMatch);
  strOut[pEnd - pMatch] = '\0';
  return strOut;
}


x86 assembly (clang, -O0):
<GetAttribute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    117a <GetAttribute+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    1256 <GetAttribute+0x116>
mov    -0x20(%rbp),%rdi
mov    $0x3d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11a5 <GetAttribute+0x65>
movq   $0x0,-0x8(%rbp)
jmp    1256 <GetAttribute+0x116>
mov    -0x20(%rbp),%rdi
mov    $0x22,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11d0 <GetAttribute+0x90>
movq   $0x0,-0x8(%rbp)
jmp    1256 <GetAttribute+0x116>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x22,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    1207 <GetAttribute+0xc7>
movq   $0x0,-0x8(%rbp)
jmp    1256 <GetAttribute+0x116>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetAttribute>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rax
mov    %rsi,%rdi
mov    %rax,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     11bc <GetAttribute+0x7c>
mov    %rax,%rdi
mov    $0x3d,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11bc <GetAttribute+0x7c>
mov    %rax,%rdi
mov    $0x22,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11bc <GetAttribute+0x7c>
mov    %rax,%r14
add    $0x1,%r14
mov    %r14,%rdi
mov    $0x22,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11bc <GetAttribute+0x7c>
mov    %rax,%r15
sub    %r14,%r15
lea    0x1(%r15),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <memcpy@plt>
movb   $0x0,(%rbx,%r15,1)
jmp    11be <GetAttribute+0x7e>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @GetAttribute(i8* nocapture %0, i8* %1) {
%3 = tail call i8* @strstr(i8* dereferenceable(1) %1, i8* dereferenceable(1) %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %24, label %5
5: ; preds = %2
%6 = tail call i8* @strchr(i8* %3, i8 signext 61)
%7 = icmp eq i8* %6, null
br i1 %7, label %24, label %8
8: ; preds = %5
%9 = tail call i8* @strchr(i8* %6, i8 signext 34)
%10 = icmp eq i8* %9, null
br i1 %10, label %24, label %11
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = tail call i8* @strchr(i8* %12, i8 signext 34)
%14 = icmp eq i8* %13, null
br i1 %14, label %24, label %15
15: ; preds = %11
%16 = ptrtoint i8* %13 to i64
%17 = ptrtoint i8* %12 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
%20 = add i32 %19, 1
%21 = tail call i8* @malloc(i32 %20)
%22 = tail call i32 @memcpy(i8* %21, i8* %12, i32 %19)
%23 = getelementptr inbounds i8, i8* %21, i64 %18
store i8 0, i8* %23
br label %24
24: ; preds = %11, %8, %5, %2, %15
%25 = phi i8* [ %21, %15 ], [ null, %2 ], [ null, %5 ], [ null, %8 ], [ null, %11 ]
ret i8* %25
}