#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__ calloc(int, int);
int /*<<< orphan*/ create_message(int /*<<< orphan*/ *, char *,
                                  int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ send_message_and_free(int, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
void send_quit(int fd, char *reason) {
  char *buf = (char *)calloc(513, sizeof(char));
  strcat(buf, ":");
  strcat(buf, reason);
  send_message_and_free(fd, create_message(NULL, "QUIT", 0, buf));
  free(buf);
}


x86 assembly (clang, -O0):
<send_quit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x201,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edi
lea    0xe5e(%rip),%rsi
xor    %edx,%edx
call   1040 <create_message@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
call   1060 <send_message_and_free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_quit>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
mov    $0x201,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbp
lea    0xe8d(%rip),%rsi
mov    %rax,%rdi
call   1070 <strcat@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <strcat@plt>
lea    0xe75(%rip),%rsi
xor    %edi,%edi
xor    %edx,%edx
mov    %rbp,%rcx
call   1040 <create_message@plt>
mov    %r14d,%edi
mov    %eax,%esi
call   1060 <send_message_and_free@plt>
mov    %rbp,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
@.str.1 = [5 x i8] c"QUIT\00"
define void @send_quit(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = call i64 @calloc(i32 513, i32 1)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strcat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = load i8*, i8** %5
%11 = load i8*, i8** %4
%12 = call i32 @strcat(i8* %10, i8* %11)
%13 = load i32, i32* %3
%14 = load i8*, i8** %5
%15 = call i32 @create_message(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 0, i8* %14)
%16 = call i32 @send_message_and_free(i32 %13, i32 %15)
%17 = load i8*, i8** %5
%18 = call i32 @free(i8* %17)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c":\00"
@.str.1 = [5 x i8] c"QUIT\00"
define void @send_quit(i32 %0, i8* %1) {
%3 = tail call i64 @calloc(i32 513, i32 1)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @strcat(i8* %4, i8* %1)
%7 = tail call i32 @create_message(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 0, i8* %4)
%8 = tail call i32 @send_message_and_free(i32 %0, i32 %7)
%9 = tail call i32 @free(i8* %4)
ret void
}