#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 sk_send(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, ...);
int /*<<< orphan*/ strlen(char const *);
int srv_setpresence(int sock, const char *type, const char *msg, int ssl) {
  int rv;
  char *str = malloc(1024);
  char *_msg = (char *)msg;
  if (!strlen(msg))
    _msg = "";
  if (!strlen(type))
    sprintf(str, "<presence><status>%s</status></presence>", _msg);
  else
    sprintf(str, "<presence><show>%s</show><status>%s</status></presence>",
            type, _msg);
  if (!(rv = sk_send(sock, str, ssl))) {
    perror("senddata (server.c:199)");
  }
  free(str);
  return rv;
}


x86 assembly (clang, -O0):
<srv_setpresence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jne    11a9 <srv_setpresence+0x49>
lea    0xed3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jne    11d6 <srv_setpresence+0x76>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
jmp    11f0 <srv_setpresence+0x90>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <sk_send@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jne    1217 <srv_setpresence+0xb7>
lea    0xe4f(%rip),%rdi
call   1070 <perror@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<srv_setpresence>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %edi,%r15d
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
lea    0xee3(%rip),%rbp
cmovne %rbx,%rbp
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11be <srv_setpresence+0x5e>
lea    0xe7d(%rip),%rsi
mov    %r13,%rdi
mov    %r12,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1080 <sprintf@plt>
jmp    11d2 <srv_setpresence+0x72>
lea    0xe3b(%rip),%rsi
mov    %r13,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    %r14d,%edx
call   1060 <sk_send@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11ff <srv_setpresence+0x9f>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe5b(%rip),%rdi
call   1070 <perror@plt>
jmp    11e6 <srv_setpresence+0x86>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [41 x i8] c"<presence><status>%s</status></presence>\00"
@.str.2 = [56 x i8] c"<presence><show>%s</show><status>%s</status></presence>\00"
@.str.3 = [24 x i8] c"senddata (server.c:199)\00"
define i32 @srv_setpresence(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%12 = call i8* @malloc(i32 1024)
store i8* %12, i8** %10
%13 = load i8*, i8** %7
store i8* %13, i8** %11
%14 = load i8*, i8** %7
%15 = call i32 @strlen(i8* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %4
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %11
br label %18
18: ; preds = %17, %4
%19 = load i8*, i8** %6
%20 = call i32 @strlen(i8* %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i8*, i8** %10
%24 = load i8*, i8** %11
%25 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %31
26: ; preds = %18
%27 = load i8*, i8** %10
%28 = load i8*, i8** %6
%29 = load i8*, i8** %11
%30 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i8* %28, i8* %29)
br label %31
31: ; preds = %26, %22
%32 = load i32, i32* %5
%33 = load i8*, i8** %10
%34 = load i32, i32* %8
%35 = call i32 @sk_send(i32 %32, i8* %33, i32 %34)
store i32 %35, i32* %9
%36 = icmp ne i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %31
%38 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %31
%40 = load i8*, i8** %10
%41 = call i32 @free(i8* %40)
%42 = load i32, i32* %9
ret i32 %42
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [41 x i8] c"<presence><status>%s</status></presence>\00"
@.str.2 = [56 x i8] c"<presence><show>%s</show><status>%s</status></presence>\00"
@.str.3 = [24 x i8] c"senddata (server.c:199)\00"
define i32 @srv_setpresence(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%6 = tail call i32 @strlen(i8* %2)
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %2
%9 = tail call i32 @strlen(i8* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %15
13: ; preds = %4
%14 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %8)
br label %15
15: ; preds = %13, %11
%16 = tail call i32 @sk_send(i32 %0, i8* %5, i32 %3)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
%21 = tail call i32 @free(i8* %5)
ret i32 %16
}