#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
char *get_xml_attribute_value(char *str, char *attribute) {
  char *tmpstr, *fullatt, *retval, *endptr;
  int newlen = 0;
  fullatt = (char *)(malloc(strlen(attribute) + 3 * sizeof(char)));
  strcpy(fullatt, attribute);
  fullatt[strlen(attribute)] = '=';
  fullatt[strlen(attribute) + 1] = '\"';
  fullatt[strlen(attribute) + 2] = '\0';
  tmpstr = strstr(str, fullatt);
  if (!tmpstr)
    return NULL;
  free(fullatt);
  tmpstr = tmpstr + strlen(attribute) + 2;
  endptr = strstr(tmpstr, "\"");
  if (!endptr)
    return NULL;
  newlen = (endptr - tmpstr) + 1;
  retval = (char *)malloc(newlen * sizeof(char));
  memcpy(retval, tmpstr, newlen);
  retval[newlen - 1] = '\0';
  return retval;
}


x86 assembly (clang, -O0):
<get_xml_attribute_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cltq
add    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
movslq %ecx,%rcx
movb   $0x3d,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x22,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1227 <get_xml_attribute_value+0xc7>
movq   $0x0,-0x8(%rbp)
jmp    12cf <get_xml_attribute_value+0x16f>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1281 <get_xml_attribute_value+0x121>
movq   $0x0,-0x8(%rbp)
jmp    12cf <get_xml_attribute_value+0x16f>
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x3c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_xml_attribute_value>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <strlen@plt>
lea    0x3(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x3d,(%rbx,%rax,1)
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x22,0x1(%rax,%rbx,1)
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,0x2(%rax,%rbx,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     122f <get_xml_attribute_value+0xbf>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
add    %rax,%r14
add    $0x2,%r14
mov    %r14,%rdi
mov    $0x22,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     122f <get_xml_attribute_value+0xbf>
mov    %rax,%rbx
sub    %r14,%rbx
lea    0x1(%rbx),%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1070 <memcpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
jmp    1232 <get_xml_attribute_value+0xc2>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\22\00"
define i8* @get_xml_attribute_value(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %10
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = sext i32 %12 to i64
%14 = add i64 %13, 3
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = load i8*, i8** %5
%20 = call i32 @strcpy(i8* %18, i8* %19)
%21 = load i8*, i8** %7
%22 = load i8*, i8** %5
%23 = call i32 @strlen(i8* %22)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
store i8 61, i8* %25
%26 = load i8*, i8** %7
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
%29 = add nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %26, i64 %30
store i8 34, i8* %31
%32 = load i8*, i8** %7
%33 = load i8*, i8** %5
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %34, 2
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %32, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %4
%39 = load i8*, i8** %7
%40 = call i8* @strstr(i8* %38, i8* %39)
store i8* %40, i8** %6
%41 = load i8*, i8** %6
%42 = icmp ne i8* %41, null
br i1 %42, label %44, label %43
43: ; preds = %2
store i8* null, i8** %3
br label %82
44: ; preds = %2
%45 = load i8*, i8** %7
%46 = call i32 @free(i8* %45)
%47 = load i8*, i8** %6
%48 = load i8*, i8** %5
%49 = call i32 @strlen(i8* %48)
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
%52 = getelementptr inbounds i8, i8* %51, i64 2
store i8* %52, i8** %6
%53 = load i8*, i8** %6
%54 = call i8* @strstr(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %54, i8** %9
%55 = load i8*, i8** %9
%56 = icmp ne i8* %55, null
br i1 %56, label %58, label %57
57: ; preds = %44
store i8* null, i8** %3
br label %82
58: ; preds = %44
%59 = load i8*, i8** %9
%60 = load i8*, i8** %6
%61 = ptrtoint i8* %59 to i64
%62 = ptrtoint i8* %60 to i64
%63 = sub i64 %61, %62
%64 = add nsw i64 %63, 1
%65 = trunc i64 %64 to i32
store i32 %65, i32* %10
%66 = load i32, i32* %10
%67 = sext i32 %66 to i64
%68 = mul i64 %67, 1
%69 = trunc i64 %68 to i32
%70 = call i64 @malloc(i32 %69)
%71 = inttoptr i64 %70 to i8*
store i8* %71, i8** %8
%72 = load i8*, i8** %8
%73 = load i8*, i8** %6
%74 = load i32, i32* %10
%75 = call i32 @memcpy(i8* %72, i8* %73, i32 %74)
%76 = load i8*, i8** %8
%77 = load i32, i32* %10
%78 = sub nsw i32 %77, 1
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %76, i64 %79
store i8 0, i8* %80
%81 = load i8*, i8** %8
store i8* %81, i8** %3
br label %82
82: ; preds = %58, %57, %43
%83 = load i8*, i8** %3
ret i8* %83
}

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