#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__ malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
char *strstr(char *, char *);
char *getXMLString(char **location) {
  char *curLoc;
  char *tagEnd;
  char *toReturn;
  size_t strLen;
  curLoc = *location;
  curLoc = strstr(curLoc, "<string>");
  if (!curLoc) {
    return NULL;
  }
  curLoc += sizeof("<string>") - 1;
  tagEnd = strstr(curLoc, "</string>");
  strLen = (size_t)(tagEnd - curLoc);
  toReturn = (char *)malloc(strLen + 1);
  memcpy(toReturn, curLoc, strLen);
  toReturn[strLen] = '\0';
  curLoc = tagEnd + sizeof("</string>") - 1;
  *location = curLoc;
  return toReturn;
}


x86 assembly (clang, -O0):
<getXMLString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeae(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1173 <getXMLString+0x43>
movq   $0x0,-0x8(%rbp)
jmp    11f3 <getXMLString+0xc3>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0xa,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getXMLString>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
mov    (%rdi),%rdi
lea    0xeba(%rip),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1197 <getXMLString+0x67>
mov    %rax,%rbx
add    $0x8,%rbx
lea    0xeab(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strstr@plt>
mov    %rax,%r12
mov    %rax,%r13
sub    %rbx,%r13
lea    0x1(%r13),%rdi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1030 <memcpy@plt>
movb   $0x0,(%r15,%r13,1)
add    $0x9,%r12
mov    %r12,(%r14)
jmp    119a <getXMLString+0x6a>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"<string>\00"
@.str.1 = [10 x i8] c"</string>\00"
define i8* @getXMLString(i8** %0) {
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i8** %0, i8*** %3
%8 = load i8**, i8*** %3
%9 = load i8*, i8** %8
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = call i8* @strstr(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 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 = %1
store i8* null, i8** %2
br label %42
15: ; preds = %1
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 8
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = call i8* @strstr(i8* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = load i8*, i8** %4
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
store i64 %24, i64* %7
%25 = load i64, i64* %7
%26 = add i64 %25, 1
%27 = call i64 @malloc(i64 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = load i8*, i8** %4
%31 = load i64, i64* %7
%32 = call i32 @memcpy(i8* %29, i8* %30, i64 %31)
%33 = load i8*, i8** %6
%34 = load i64, i64* %7
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8 0, i8* %35
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 10
%38 = getelementptr inbounds i8, i8* %37, i64 -1
store i8* %38, i8** %4
%39 = load i8*, i8** %4
%40 = load i8**, i8*** %3
store i8* %39, i8** %40
%41 = load i8*, i8** %6
store i8* %41, i8** %2
br label %42
42: ; preds = %15, %14
%43 = load i8*, i8** %2
ret i8* %43
}

LLVM IR (-O2):
@.str = [9 x i8] c"<string>\00"
@.str.1 = [10 x i8] c"</string>\00"
define i8* @getXMLString(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = tail call i8* @strstr(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %17, label %5
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %3, i64 8
%7 = tail call i8* @strstr(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%8 = ptrtoint i8* %7 to i64
%9 = ptrtoint i8* %6 to i64
%10 = sub i64 %8, %9
%11 = add i64 %10, 1
%12 = tail call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 @memcpy(i8* %13, i8* %6, i64 %10)
%15 = getelementptr inbounds i8, i8* %13, i64 %10
store i8 0, i8* %15
%16 = getelementptr inbounds i8, i8* %7, i64 9
store i8* %16, i8** %0
br label %17
17: ; preds = %1, %5
%18 = phi i8* [ %13, %5 ], [ null, %1 ]
ret i8* %18
}