#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 */
struct ILibWebServer_Session {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ILibWebServer_Send_Raw(struct ILibWebServer_Session *,
                                          char *, int, int /*<<< orphan*/, int);
scalar_t__ malloc(int);
int sprintf(char *, char *, int const, ...);
scalar_t__ strlen(char const *);
void UpnpResponse_Error(const void *UPnPToken, const int ErrorCode,
                        const char *ErrorMsg) {
  char *body;
  int bodylength;
  char *head;
  int headlength;
  body = (char *)malloc(395 + (int)strlen(ErrorMsg));
  bodylength = sprintf(
      body,
      "<s:Envelope\r\n xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
      "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/"
      "\"><s:Body><s:Fault><faultcode>s:Client</"
      "faultcode><faultstring>UPnPError</faultstring><detail><UPnPError "
      "xmlns=\"urn:schemas-upnp-org:control-1-0\"><errorCode>%d</"
      "errorCode><errorDescription>%s</errorDescription></UPnPError></detail></"
      "s:Fault></s:Body></s:Envelope>",
      ErrorCode, ErrorMsg);
  head = (char *)malloc(59);
  headlength = sprintf(
      head, "HTTP/1.1 500 Internal\r\nContent-Length: %d\r\n\r\n", bodylength);
  ILibWebServer_Send_Raw((struct ILibWebServer_Session *)UPnPToken, head,
                         headlength, 0, 0);
  ILibWebServer_Send_Raw((struct ILibWebServer_Session *)UPnPToken, body,
                         bodylength, 0, 1);
}


x86 assembly (clang, -O0):
<UpnpResponse_Error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
add    $0x18b,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    %eax,-0x24(%rbp)
mov    $0x3b,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xfdf(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1060 <ILibWebServer_Send_Raw@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
xor    %ecx,%ecx
mov    $0x1,%r8d
call   1060 <ILibWebServer_Send_Raw@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UpnpResponse_Error>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    %rdx,%rdi
call   1030 <strlen@plt>
lea    0x18b(%rax),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
lea    0xe94(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %eax,%ebx
mov    $0x3b,%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
lea    0xff3(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <ILibWebServer_Send_Raw@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
mov    $0x1,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <ILibWebServer_Send_Raw@plt>

LLVM IR (-O0):
%struct.ILibWebServer_Session = type { i32 }
@.str = [388 x i8] c"<s:Envelope\0D\0A xmlns:s=\22http://schemas.xmlsoap.org/soap/envelope/\22 s:encodingStyle=\22http://schemas.xmlsoap.org/soap/encoding/\22><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring>UPnPError</faultstring><detail><UPnPError xmlns=\22urn:schemas-upnp-org:control-1-0\22><errorCode>%d</errorCode><errorDescription>%s</errorDescription></UPnPError></detail></s:Fault></s:Body></s:Envelope>\00"
@.str.1 = [46 x i8] c"HTTP/1.1 500 Internal\0D\0AContent-Length: %d\0D\0A\0D\0A\00"
define void @UpnpResponse_Error(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = load i8*, i8** %6
%12 = call i64 @strlen(i8* %11)
%13 = trunc i64 %12 to i32
%14 = add nsw i32 395, %13
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = load i32, i32* %5
%19 = load i8*, i8** %6
%20 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([388 x i8], [388 x i8]* @.str, i64 0, i64 0), i32 %18, i8* %19)
store i32 %20, i32* %8
%21 = call i64 @malloc(i32 59)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %9
%23 = load i8*, i8** %9
%24 = load i32, i32* %8
%25 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %24)
store i32 %25, i32* %10
%26 = load i8*, i8** %4
%27 = bitcast i8* %26 to %struct.ILibWebServer_Session*
%28 = load i8*, i8** %9
%29 = load i32, i32* %10
%30 = call i32 @ILibWebServer_Send_Raw(%struct.ILibWebServer_Session* %27, i8* %28, i32 %29, i32 0, i32 0)
%31 = load i8*, i8** %4
%32 = bitcast i8* %31 to %struct.ILibWebServer_Session*
%33 = load i8*, i8** %7
%34 = load i32, i32* %8
%35 = call i32 @ILibWebServer_Send_Raw(%struct.ILibWebServer_Session* %32, i8* %33, i32 %34, i32 0, i32 1)
ret void
}

LLVM IR (-O2):
%struct.ILibWebServer_Session = type { i32 }
@.str = [388 x i8] c"<s:Envelope\0D\0A xmlns:s=\22http://schemas.xmlsoap.org/soap/envelope/\22 s:encodingStyle=\22http://schemas.xmlsoap.org/soap/encoding/\22><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring>UPnPError</faultstring><detail><UPnPError xmlns=\22urn:schemas-upnp-org:control-1-0\22><errorCode>%d</errorCode><errorDescription>%s</errorDescription></UPnPError></detail></s:Fault></s:Body></s:Envelope>\00"
@.str.1 = [46 x i8] c"HTTP/1.1 500 Internal\0D\0AContent-Length: %d\0D\0A\0D\0A\00"
define void @UpnpResponse_Error(i8* %0, i32 %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%5 = trunc i64 %4 to i32
%6 = add nsw i32 %5, 395
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([388 x i8], [388 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %2)
%10 = tail call i64 @malloc(i32 59)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%13 = bitcast i8* %0 to %struct.ILibWebServer_Session*
%14 = tail call i32 @ILibWebServer_Send_Raw(%struct.ILibWebServer_Session* %13, i8* %11, i32 %12, i32 0, i32 0)
%15 = tail call i32 @ILibWebServer_Send_Raw(%struct.ILibWebServer_Session* %13, i8* %8, i32 %9, i32 0, i32 1)
ret void
}