#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 */
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ int32_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
int /*<<< orphan*/ sscanf(char *, char *, int /*<<< orphan*/ *);
char *strstr(char *, char *);
uint32_t getXMLInteger(char **location) {
  char *curLoc;
  char *tagEnd;
  char *buffer;
  uint32_t toReturn;
  size_t strLen;
  curLoc = *location;
  curLoc = strstr(curLoc, "<integer>");
  if (!curLoc)
    return 0;
  curLoc += sizeof("<integer>") - 1;
  tagEnd = strstr(curLoc, "</integer>");
  strLen = (size_t)(tagEnd - curLoc);
  buffer = (char *)malloc(strLen + 1);
  memcpy(buffer, curLoc, strLen);
  buffer[strLen] = '\0';
  curLoc = tagEnd + sizeof("</integer>") - 1;
  sscanf(buffer, "%d", (int32_t *)(&toReturn));
  free(buffer);
  *location = curLoc;
  return toReturn;
}


x86 assembly (clang, -O0):
<getXMLInteger>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1192 <getXMLInteger+0x42>
movl   $0x0,-0x4(%rbp)
jmp    122d <getXMLInteger+0xdd>
mov    -0x18(%rbp),%rax
add    $0x9,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0xb,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe0b(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getXMLInteger>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    (%rdi),%rdi
lea    0xe96(%rip),%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     11dd <getXMLInteger+0x8d>
mov    %rax,%rbx
add    $0x9,%rbx
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
mov    %rax,%r15
mov    %rax,%r12
sub    %rbx,%r12
lea    0x1(%r12),%rdi
call   1050 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
movb   $0x0,0x0(%r13,%r12,1)
add    $0xa,%r15
lea    0xe56(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r13,%rdi
call   1060 <sscanf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r15,(%r14)
mov    0xc(%rsp),%eax
jmp    11df <getXMLInteger+0x8f>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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