#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*/ ILibXmlEscape(char *, char const *);
scalar_t__ ILibXmlEscapeLength(char const *);
int /*<<< orphan*/ UpnpResponseGeneric(void const *, char *, char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strlen(char *);
void UpnpResponse_ContentDirectory_GetSortCapabilities(
    const void *UPnPToken, const char *unescaped_SortCaps) {
  char *body;
  char *SortCaps = (char *)malloc(1 + ILibXmlEscapeLength(unescaped_SortCaps));
  ILibXmlEscape(SortCaps, unescaped_SortCaps);
  body = (char *)malloc(22 + strlen(SortCaps));
  sprintf(body, "<SortCaps>%s</SortCaps>", SortCaps);
  UpnpResponseGeneric(UPnPToken,
                      "urn:schemas-upnp-org:service:ContentDirectory:1",
                      "GetSortCapabilities", body);
  free(body);
  free(SortCaps);
}


x86 assembly (clang, -O0):
<UpnpResponse_ContentDirectory_GetSortCapabilities>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <ILibXmlEscapeLength@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <ILibXmlEscape@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x16,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe32(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
lea    0xe36(%rip),%rsi
lea    0xe5f(%rip),%rdx
call   1050 <UpnpResponseGeneric@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UpnpResponse_ContentDirectory_GetSortCapabilities>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1090 <ILibXmlEscapeLength@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <ILibXmlEscape@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
lea    0x16(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe48(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
call   1080 <sprintf@plt>
lea    0xe4e(%rip),%rsi
lea    0xe77(%rip),%rdx
mov    %r14,%rdi
mov    %rbx,%rcx
call   1050 <UpnpResponseGeneric@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"<SortCaps>%s</SortCaps>\00"
@.str.1 = [48 x i8] c"urn:schemas-upnp-org:service:ContentDirectory:1\00"
@.str.2 = [20 x i8] c"GetSortCapabilities\00"
define void @UpnpResponse_ContentDirectory_GetSortCapabilities(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @ILibXmlEscapeLength(i8* %7)
%9 = add nsw i64 1, %8
%10 = call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = load i8*, i8** %4
%14 = call i32 @ILibXmlEscape(i8* %12, i8* %13)
%15 = load i8*, i8** %6
%16 = call i64 @strlen(i8* %15)
%17 = add nsw i64 22, %16
%18 = call i64 @malloc(i64 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = load i8*, i8** %6
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %3
%24 = load i8*, i8** %5
%25 = call i32 @UpnpResponseGeneric(i8* %23, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %5
%27 = call i32 @free(i8* %26)
%28 = load i8*, i8** %6
%29 = call i32 @free(i8* %28)
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"<SortCaps>%s</SortCaps>\00"
@.str.1 = [48 x i8] c"urn:schemas-upnp-org:service:ContentDirectory:1\00"
@.str.2 = [20 x i8] c"GetSortCapabilities\00"
define void @UpnpResponse_ContentDirectory_GetSortCapabilities(i8* %0, i8* %1) {
%3 = tail call i64 @ILibXmlEscapeLength(i8* %1)
%4 = add nsw i64 %3, 1
%5 = tail call i64 @malloc(i64 %4)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @ILibXmlEscape(i8* %6, i8* %1)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %6)
%9 = add nsw i64 %8, 22
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %6)
%13 = tail call i32 @UpnpResponseGeneric(i8* %0, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%14 = tail call i32 @free(i8* %11)
%15 = tail call i32 @free(i8* %6)
ret void
}