#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sk_send(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *, char *);
char *strdup(char const *);
int srv_sendtext(int sock, const char *to, const char *text, const char *from,
                 int ssl) {
  char *stringtosend = malloc(2048);
  char *utf8inputline = strdup(text);
  sprintf(stringtosend,
          "<message from='%s' to='%s' type='chat'><body>%s</body></message>",
          from, to, utf8inputline);
  if (!sk_send(sock, stringtosend, ssl)) {
    perror("senddata (server.c:247)");
    return -1;
  }
  free(stringtosend);
  free(utf8inputline);
  return 0;
}


x86 assembly (clang, -O0):
<srv_sendtext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    $0x800,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x38(%rbp),%r8
lea    0xe53(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <sk_send@plt>
cmp    $0x0,%eax
jne    11e2 <srv_sendtext+0x82>
lea    0xe70(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <srv_sendtext+0x9b>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<srv_sendtext>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,0x4(%rsp)
mov    %rcx,%r12
mov    %rdx,%rbp
mov    %rsi,%r13
mov    %edi,%r15d
mov    $0x800,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1080 <strdup@plt>
mov    %rax,%r14
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rax,%r8
call   1070 <sprintf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    0x4(%rsp),%edx
call   1050 <sk_send@plt>
test   %eax,%eax
je     11e0 <srv_sendtext+0x80>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe5a(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
jmp    11d1 <srv_sendtext+0x71>

LLVM IR (-O0):
@.str = [65 x i8] c"<message from='%s' to='%s' type='chat'><body>%s</body></message>\00"
@.str.1 = [24 x i8] c"senddata (server.c:247)\00"
define i32 @srv_sendtext(i32 %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store i32 %0, i32* %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%14 = call i8* @malloc(i32 2048)
store i8* %14, i8** %12
%15 = load i8*, i8** %9
%16 = call i8* @strdup(i8* %15)
store i8* %16, i8** %13
%17 = load i8*, i8** %12
%18 = load i8*, i8** %10
%19 = load i8*, i8** %8
%20 = load i8*, i8** %13
%21 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %19, i8* %20)
%22 = load i32, i32* %7
%23 = load i8*, i8** %12
%24 = load i32, i32* %11
%25 = call i32 @sk_send(i32 %22, i8* %23, i32 %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %5
%28 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %6
br label %34
29: ; preds = %5
%30 = load i8*, i8** %12
%31 = call i32 @free(i8* %30)
%32 = load i8*, i8** %13
%33 = call i32 @free(i8* %32)
store i32 0, i32* %6
br label %34
34: ; preds = %29, %27
%35 = load i32, i32* %6
ret i32 %35
}

LLVM IR (-O2):
@.str = [65 x i8] c"<message from='%s' to='%s' type='chat'><body>%s</body></message>\00"
@.str.1 = [24 x i8] c"senddata (server.c:247)\00"
define i32 @srv_sendtext(i32 %0, i8* %1, i8* nocapture %2, i8* %3, i32 %4) {
%6 = tail call dereferenceable_or_null(2048) i8* @malloc(i32 2048)
%7 = tail call i8* @strdup(i8* %2)
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %1, i8* %7)
%9 = tail call i32 @sk_send(i32 %0, i8* %6, i32 %4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %16
13: ; preds = %5
%14 = tail call i32 @free(i8* %6)
%15 = tail call i32 @free(i8* %7)
br label %16
16: ; preds = %13, %11
%17 = phi i32 [ 0, %13 ], [ -1, %11 ]
ret i32 %17
}