#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 /*<<< orphan*/ strncpy(char *, char *, int);
char *xml_get_element(char *xml_tag_buffer) {
  char xml_element_buffer[2048];
  char *p = NULL;
  char *q = NULL;
  char *r = NULL;
  p = &xml_tag_buffer[0];
  q = strchr(xml_tag_buffer, ' ');
  if (xml_tag_buffer[0] == '/') {
    xml_tag_buffer++;
  }
  if (q) {
    strncpy(xml_element_buffer, p, q - p);
    xml_element_buffer[q - p] = (char)NULL;
    r = xml_element_buffer;
    return (r);
  } else {
    return (xml_tag_buffer);
  }
}


x86 assembly (clang, -O0):
<xml_get_element>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x818(%rbp)
movq   $0x0,-0x820(%rbp)
movq   $0x0,-0x828(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x818(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x820(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    118c <xml_get_element+0x6c>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x820(%rbp)
je     11f7 <xml_get_element+0xd7>
lea    -0x810(%rbp),%rdi
mov    -0x818(%rbp),%rsi
mov    -0x820(%rbp),%rax
mov    -0x818(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x820(%rbp),%rax
mov    -0x818(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0x810(%rbp,%rax,1)
lea    -0x810(%rbp),%rax
mov    %rax,-0x828(%rbp)
mov    -0x828(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ff <xml_get_element+0xdf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xml_get_element>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rdi,%rbx
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,%r14
xor    %eax,%eax
cmpb   $0x2f,(%rbx)
sete   %cl
test   %r14,%r14
je     1167 <xml_get_element+0x47>
mov    %rsp,%r15
sub    %rbx,%r14
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rsp,%r14,1)
mov    %r15,%rbx
jmp    116c <xml_get_element+0x4c>
mov    %cl,%al
add    %rax,%rbx
mov    %rbx,%rax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @xml_get_element(i8* %0) {
%2 = alloca [2048 x i8]
%3 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 32)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 47
%7 = zext i1 %6 to i64
%8 = getelementptr i8, i8* %0, i64 %7
%9 = icmp eq i8* %4, null
br i1 %9, label %17, label %10
10: ; preds = %1
%11 = ptrtoint i8* %4 to i64
%12 = ptrtoint i8* %0 to i64
%13 = sub i64 %11, %12
%14 = trunc i64 %13 to i32
%15 = call i32 @strncpy(i8* %3, i8* %0, i32 %14)
%16 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %13
store i8 0, i8* %16
br label %17
17: ; preds = %1, %10
%18 = phi i8* [ %3, %10 ], [ %8, %1 ]
ret i8* %18
}