#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 */
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *,
                           char const *, char const *);
scalar_t__ strlen(char const *);
int Create_Action_Message(const char *service_type, const char *action_name,
                          const char *action_params, char **action_message) {
  *action_message =
      (char *)malloc(strlen("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"
                            "<s:Envelope xmlns:s="
                            "\"http://schemas.xmlsoap.org/soap/envelope/\" "
                            "s:encodingStyle="
                            "\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n"
                            "<s:Body>\r\n"
                            "<u:%s xmlns:u="
                            "\"urn:schemas-upnp-org:service:%s\">\r\n%s"
                            "</u:%s>\r\n"
                            "</s:Body>\r\n"
                            "</s:Envelope>\r\n") +
                     strlen(service_type) + strlen(action_name) +
                     strlen(action_params) + strlen(action_name) + 1);
  if (NULL == *action_message) {
    return -499;
  }
  (void)sprintf(*action_message,
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"
                "<s:Envelope xmlns:s="
                "\"http://schemas.xmlsoap.org/soap/envelope/\" "
                "s:encodingStyle="
                "\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n"
                "<s:Body>\r\n"
                "<u:%s xmlns:u="
                "\"urn:schemas-upnp-org:service:%s\">\r\n%s"
                "</u:%s>\r\n"
                "</s:Body>\r\n"
                "</s:Envelope>\r\n",
                action_name, service_type, action_params, action_name);
  return 0;
}


x86 assembly (clang, -O0):
<Create_Action_Message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    0xeb1(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%rax
jne    11db <Create_Action_Message+0xab>
movl   $0xfffffe0d,-0x4(%rbp)
jmp    1205 <Create_Action_Message+0xd5>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x18(%rbp),%r9
lea    0xe07(%rip),%rsi
call   1050 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Create_Action_Message>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %rbx,%rax
lea    (%rax,%rbp,2),%rdi
add    $0x108,%rdi
call   1040 <malloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     119d <Create_Action_Message+0x6d>
lea    0xe7b(%rip),%rsi
mov    %rax,%rdi
mov    %r13,%rdx
mov    %r15,%rcx
mov    %r14,%r8
mov    %r13,%r9
call   1050 <sprintf@plt>
xor    %eax,%eax
jmp    11a2 <Create_Action_Message+0x72>
mov    $0xfffffe0d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [264 x i8] c"<?xml version=\221.0\22 encoding=\22utf-8\22?>\0D\0A<s:Envelope xmlns:s=\22http://schemas.xmlsoap.org/soap/envelope/\22 s:encodingStyle=\22http://schemas.xmlsoap.org/soap/encoding/\22>\0D\0A<s:Body>\0D\0A<u:%s xmlns:u=\22urn:schemas-upnp-org:service:%s\22>\0D\0A%s</u:%s>\0D\0A</s:Body>\0D\0A</s:Envelope>\0D\0A\00"
define i32 @Create_Action_Message(i8* %0, i8* %1, i8* %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8** %3, i8*** %9
%10 = call i64 @strlen(i8* getelementptr inbounds ([264 x i8], [264 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %6
%12 = call i64 @strlen(i8* %11)
%13 = add nsw i64 %10, %12
%14 = load i8*, i8** %7
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %13, %15
%17 = load i8*, i8** %8
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %16, %18
%20 = load i8*, i8** %7
%21 = call i64 @strlen(i8* %20)
%22 = add nsw i64 %19, %21
%23 = add nsw i64 %22, 1
%24 = call i64 @malloc(i64 %23)
%25 = inttoptr i64 %24 to i8*
%26 = load i8**, i8*** %9
store i8* %25, i8** %26
%27 = load i8**, i8*** %9
%28 = load i8*, i8** %27
%29 = icmp eq i8* null, %28
br i1 %29, label %30, label %31
30: ; preds = %4
store i32 -499, i32* %5
br label %39
31: ; preds = %4
%32 = load i8**, i8*** %9
%33 = load i8*, i8** %32
%34 = load i8*, i8** %7
%35 = load i8*, i8** %6
%36 = load i8*, i8** %8
%37 = load i8*, i8** %7
%38 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([264 x i8], [264 x i8]* @.str, i64 0, i64 0), i8* %34, i8* %35, i8* %36, i8* %37)
store i32 0, i32* %5
br label %39
39: ; preds = %31, %30
%40 = load i32, i32* %5
ret i32 %40
}

LLVM IR (-O2):
@.str = [264 x i8] c"<?xml version=\221.0\22 encoding=\22utf-8\22?>\0D\0A<s:Envelope xmlns:s=\22http://schemas.xmlsoap.org/soap/envelope/\22 s:encodingStyle=\22http://schemas.xmlsoap.org/soap/encoding/\22>\0D\0A<s:Body>\0D\0A<u:%s xmlns:u=\22urn:schemas-upnp-org:service:%s\22>\0D\0A%s</u:%s>\0D\0A</s:Body>\0D\0A</s:Envelope>\0D\0A\00"
define i32 @Create_Action_Message(i8* %0, i8* %1, i8* %2, i8** nocapture writeonly %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%8 = shl i64 %6, 1
%9 = add i64 %5, 264
%10 = add i64 %9, %7
%11 = add i64 %10, %8
%12 = tail call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %3
%14 = icmp eq i64 %12, 0
br i1 %14, label %17, label %15
15: ; preds = %4
%16 = tail call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([264 x i8], [264 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %0, i8* %2, i8* %1)
br label %17
17: ; preds = %4, %15
%18 = phi i32 [ 0, %15 ], [ -499, %4 ]
ret i32 %18
}