#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*/ MSG_NOSIGNAL;
char *calloc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int snprintf(char *, int, char *, char const *, char const *, char const *,
             char const *);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char const *);
void goodbye(int sock, const char *id, const char *nickname,
             const char *color) {
  int length = 0;
  length += strlen(id) + strlen(id) + strlen(nickname) + strlen(color) + 96;
  char *buffer = calloc(1, length);
  length = snprintf(buffer, length,
                    "{\"type\":\"goodbye\",\"id\":\"%s\",\"data\":{\"id\":\"%"
                    "s\",\"nickname\":\"%s\",\"color\":\"%s\"}}",
                    id, id, nickname, color);
  send(sock, buffer, length, MSG_NOSIGNAL);
  fprintf(stderr,
          "\x1B[35m"
          "send %s"
          "\x1B[0m\n",
          buffer);
  free(buffer);
}


x86 assembly (clang, -O0):
<goodbye>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rcx
add    %rax,%rcx
add    $0x60,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
mov    $0x1,%edi
call   1070 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    -0x20(%rbp),%rax
lea    0xdfa(%rip),%rdx
mov    %rax,(%rsp)
call   1060 <snprintf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    0x2db5(%rip),%rax
mov    (%rax),%ecx
call   1050 <send@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xe0f(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<goodbye>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%r13
mov    %edi,%r14d
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rbx,2),%ebx
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rbx,1),%ebp
add    $0x60,%ebp
mov    $0x1,%edi
mov    %ebp,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    %r12,(%rsp)
lea    0xe4b(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r13,%rcx
mov    %r13,%r8
mov    %r15,%r9
call   1060 <snprintf@plt>
mov    0x2e09(%rip),%rcx
mov    (%rcx),%ecx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <send@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdx
call   1080 <fprintf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [77 x i8] c"{\22type\22:\22goodbye\22,\22id\22:\22%s\22,\22data\22:{\22id\22:\22%s\22,\22nickname\22:\22%s\22,\22color\22:\22%s\22}}\00"
@MSG_NOSIGNAL = global i32 0
@stderr = global i32 0
@.str.1 = [18 x i8] c"\1B[35msend %s\1B[0m\0A\00"
define void @goodbye(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i32 0, i32* %9
%11 = load i8*, i8** %6
%12 = call i64 @strlen(i8* %11)
%13 = load i8*, i8** %6
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %12, %14
%16 = load i8*, i8** %7
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %15, %17
%19 = load i8*, i8** %8
%20 = call i64 @strlen(i8* %19)
%21 = add nsw i64 %18, %20
%22 = add nsw i64 %21, 96
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = add nsw i64 %24, %22
%26 = trunc i64 %25 to i32
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = call i8* @calloc(i32 1, i32 %27)
store i8* %28, i8** %10
%29 = load i8*, i8** %10
%30 = load i32, i32* %9
%31 = load i8*, i8** %6
%32 = load i8*, i8** %6
%33 = load i8*, i8** %7
%34 = load i8*, i8** %8
%35 = call i32 @snprintf(i8* %29, i32 %30, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0), i8* %31, i8* %32, i8* %33, i8* %34)
store i32 %35, i32* %9
%36 = load i32, i32* %5
%37 = load i8*, i8** %10
%38 = load i32, i32* %9
%39 = load i32, i32* @MSG_NOSIGNAL
%40 = call i32 @send(i32 %36, i8* %37, i32 %38, i32 %39)
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %10
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %42)
%44 = load i8*, i8** %10
%45 = call i32 @free(i8* %44)
ret void
}

LLVM IR (-O2):
@.str = [77 x i8] c"{\22type\22:\22goodbye\22,\22id\22:\22%s\22,\22data\22:{\22id\22:\22%s\22,\22nickname\22:\22%s\22,\22color\22:\22%s\22}}\00"
@MSG_NOSIGNAL = global i32 0
@stderr = global i32 0
@.str.1 = [18 x i8] c"\1B[35msend %s\1B[0m\0A\00"
define void @goodbye(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = shl nsw i64 %5, 1
%7 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%8 = add nsw i64 %6, %7
%9 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%10 = add nsw i64 %8, %9
%11 = trunc i64 %10 to i32
%12 = add i32 %11, 96
%13 = tail call i8* @calloc(i32 1, i32 %12)
%14 = tail call i32 @snprintf(i8* %13, i32 %12, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %1, i8* %2, i8* %3)
%15 = load i32, i32* @MSG_NOSIGNAL
%16 = tail call i32 @send(i32 %0, i8* %13, i32 %14, i32 %15)
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%19 = tail call i32 @free(i8* %13)
ret void
}