#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*/ crap_atts_free(char **);
int crap_atts_parse(char *, int, char ***, int *);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
scalar_t__ strncmp(char *, char *, int);
char *raw_encoding_extract(char *buffer, size_t len) {
  char *ret = NULL;
  if (len > 6 && strncmp(buffer, "<?xml ", 6) == 0) {
    char **atts = NULL;
    char *bufptr = buffer + 5;
    int buflen = len;
    buflen -= 5;
    int att_read = 0;
    int rc = crap_atts_parse(bufptr, buflen, &atts, &att_read);
    if (rc != 0) {
      goto done;
    }
    for (int i = 0; atts[i]; i += 2) {
      if (strcmp(atts[i], "encoding") == 0) {
        ret = strdup(atts[i + 1]);
        goto done;
      }
    }
    crap_atts_free(atts);
  }
done:
  return ret;
}


x86 assembly (clang, -O0):
<raw_encoding_extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x6,-0x10(%rbp)
jbe    125a <raw_encoding_extract+0x10a>
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    125a <raw_encoding_extract+0x10a>
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
sub    $0x5,%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
lea    -0x20(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1050 <crap_atts_parse@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11e3 <raw_encoding_extract+0x93>
jmp    125f <raw_encoding_extract+0x10f>
movl   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1251 <raw_encoding_extract+0x101>
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdf7(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    123e <raw_encoding_extract+0xee>
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    125f <raw_encoding_extract+0x10f>
jmp    1243 <raw_encoding_extract+0xf3>
mov    -0x38(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x38(%rbp)
jmp    11ea <raw_encoding_extract+0x9a>
mov    -0x20(%rbp),%rdi
call   1060 <crap_atts_free@plt>
jmp    125f <raw_encoding_extract+0x10f>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<raw_encoding_extract>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x7,%rsi
jb     11f8 <raw_encoding_extract+0xa8>
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe92(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11f8 <raw_encoding_extract+0xa8>
movq   $0x0,0x8(%rsp)
add    $0x5,%r14
add    $0xfffffffb,%ebx
movl   $0x0,0x14(%rsp)
lea    0x8(%rsp),%rdx
lea    0x14(%rsp),%rcx
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <crap_atts_parse@plt>
test   %eax,%eax
jne    11f8 <raw_encoding_extract+0xa8>
mov    0x8(%rsp),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
je     11f0 <raw_encoding_extract+0xa0>
xor    %ebx,%ebx
lea    0xe44(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1202 <raw_encoding_extract+0xb2>
mov    0x8(%rsp),%rax
mov    0x10(%rax,%rbx,8),%rdi
add    $0x2,%rbx
test   %rdi,%rdi
jne    11d0 <raw_encoding_extract+0x80>
mov    %rax,%rdi
call   1060 <crap_atts_free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x8(%rsp),%rax
mov    %ebx,%ecx
shl    $0x3,%rcx
or     $0x8,%rcx
mov    (%rax,%rcx,1),%rdi
call   1070 <strdup@plt>
jmp    11fa <raw_encoding_extract+0xaa>

LLVM IR (-O0):
@.str = [7 x i8] c"<?xml \00"
@.str.1 = [9 x i8] c"encoding\00"
define i8* @raw_encoding_extract(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
store i8* null, i8** %5
%12 = load i64, i64* %4
%13 = icmp ugt i64 %12, 6
br i1 %13, label %14, label %62
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %62
18: ; preds = %14
store i8** null, i8*** %6
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 5
store i8* %20, i8** %7
%21 = load i64, i64* %4
%22 = trunc i64 %21 to i32
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = sub nsw i32 %23, 5
store i32 %24, i32* %8
store i32 0, i32* %9
%25 = load i8*, i8** %7
%26 = load i32, i32* %8
%27 = call i32 @crap_atts_parse(i8* %25, i32 %26, i8*** %6, i32* %9)
store i32 %27, i32* %10
%28 = load i32, i32* %10
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %18
br label %63
31: ; preds = %18
store i32 0, i32* %11
br label %32
32: ; preds = %56, %31
%33 = load i8**, i8*** %6
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %59
39: ; preds = %32
%40 = load i8**, i8*** %6
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %55
47: ; preds = %39
%48 = load i8**, i8*** %6
%49 = load i32, i32* %11
%50 = add nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %48, i64 %51
%53 = load i8*, i8** %52
%54 = call i8* @strdup(i8* %53)
store i8* %54, i8** %5
br label %63
55: ; preds = %39
br label %56
56: ; preds = %55
%57 = load i32, i32* %11
%58 = add nsw i32 %57, 2
store i32 %58, i32* %11
br label %32
59: ; preds = %32
%60 = load i8**, i8*** %6
%61 = call i32 @crap_atts_free(i8** %60)
br label %62
62: ; preds = %59, %14, %2
br label %63
63: ; preds = %62, %47, %30
%64 = load i8*, i8** %5
ret i8* %64
}

LLVM IR (-O2):
@.str = [7 x i8] c"<?xml \00"
@.str.1 = [9 x i8] c"encoding\00"
define noalias i8* @raw_encoding_extract(i8* %0, i64 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = icmp ugt i64 %1, 6
br i1 %5, label %6, label %44
6: ; preds = %2
%7 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %44
9: ; preds = %6
%10 = bitcast i8*** %3 to i8*
store i8** null, i8*** %3
%11 = getelementptr inbounds i8, i8* %0, i64 5
%12 = trunc i64 %1 to i32
%13 = add nsw i32 %12, -5
%14 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%15 = call i32 @crap_atts_parse(i8* %11, i32 %13, i8*** %3, i32* %4)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %42
17: ; preds = %9
%18 = load i8**, i8*** %3
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %39, label %21
21: ; preds = %17, %26
%22 = phi i64 [ %27, %26 ], [ 0, %17 ]
%23 = phi i8* [ %30, %26 ], [ %19, %17 ]
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %21
%27 = add nuw i64 %22, 2
%28 = load i8**, i8*** %3
%29 = getelementptr inbounds i8*, i8** %28, i64 %27
%30 = load i8*, i8** %29
%31 = icmp eq i8* %30, null
br i1 %31, label %39, label %21
32: ; preds = %21
%33 = load i8**, i8*** %3
%34 = and i64 %22, 4294967294
%35 = or i64 %34, 1
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i8* @strdup(i8* %37)
br label %42
39: ; preds = %26, %17
%40 = phi i8** [ %18, %17 ], [ %28, %26 ]
%41 = call i32 @crap_atts_free(i8** %40)
br label %42
42: ; preds = %32, %9, %39
%43 = phi i8* [ null, %39 ], [ %38, %32 ], [ null, %9 ]
br label %44
44: ; preds = %6, %2, %42
%45 = phi i8* [ %43, %42 ], [ null, %6 ], [ null, %2 ]
ret i8* %45
}