#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 *strchr(char *, char);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char const *, char const *);
int extract_xml_value(const char *data, char *result, const char *search_str) {
  char *s, *e;
  s = strstr(data, search_str);
  if (!s)
    return -1;
  s = s + strlen(search_str) + 1;
  e = strchr(s, '"');
  if (!e)
    return -1;
  strncpy(result, s, e - s);
  result[e - s] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<extract_xml_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117c <extract_xml_value+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <extract_xml_value+0xbe>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x22,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11ca <extract_xml_value+0x8a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <extract_xml_value+0xbe>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_xml_value>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdx,%rsi
call   1060 <strstr@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
je     11a2 <extract_xml_value+0x62>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%rbp,1),%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x22,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11a2 <extract_xml_value+0x62>
mov    %rax,%rbp
sub    %rbx,%rbp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%rbp,1)
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @extract_xml_value(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = load i8*, i8** %7
%12 = call i8* @strstr(i8* %10, i8* %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %3
store i32 -1, i32* %4
br label %45
16: ; preds = %3
%17 = load i8*, i8** %8
%18 = load i8*, i8** %7
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = call i8* @strchr(i8* %23, i8 signext 34)
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = icmp ne i8* %25, null
br i1 %26, label %28, label %27
27: ; preds = %16
store i32 -1, i32* %4
br label %45
28: ; preds = %16
%29 = load i8*, i8** %6
%30 = load i8*, i8** %8
%31 = load i8*, i8** %9
%32 = load i8*, i8** %8
%33 = ptrtoint i8* %31 to i64
%34 = ptrtoint i8* %32 to i64
%35 = sub i64 %33, %34
%36 = trunc i64 %35 to i32
%37 = call i32 @strncpy(i8* %29, i8* %30, i32 %36)
%38 = load i8*, i8** %6
%39 = load i8*, i8** %9
%40 = load i8*, i8** %8
%41 = ptrtoint i8* %39 to i64
%42 = ptrtoint i8* %40 to i64
%43 = sub i64 %41, %42
%44 = getelementptr inbounds i8, i8* %38, i64 %43
store i8 0, i8* %44
store i32 0, i32* %4
br label %45
45: ; preds = %28, %27, %15
%46 = load i32, i32* %4
ret i32 %46
}

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