#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 */
typedef int /*<<< orphan*/ msg;

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ send_data(int, char *);
int /*<<< orphan*/ slog(int /*<<< orphan*/, int, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *);
void send_message(int sock, char *chan, char *buf) {
  char msg[4098];
  bzero(msg, sizeof(msg));
  sprintf(msg, "PRIVMSG #%s :%s\r\n", chan, buf);
  send_data(sock, msg);
  sscanf(msg, "%512[^\n]\n", msg);
  slog(0, 1, "%s", msg);
}


x86 assembly (clang, -O0):
<send_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x1020(%rbp),%rdi
mov    $0x1002,%esi
call   1060 <bzero@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe73(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x1020(%rbp),%rsi
call   1030 <send_data@plt>
lea    -0x1020(%rbp),%rdi
lea    -0x1020(%rbp),%rdx
lea    0xe5c(%rip),%rsi
call   1050 <sscanf@plt>
lea    -0x1020(%rbp),%rcx
xor    %edi,%edi
mov    $0x1,%esi
lea    0xe4c(%rip),%rdx
call   1040 <slog@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_message>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1002,%esi
call   1060 <bzero@plt>
lea    0xe84(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1070 <sprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <send_data@plt>
lea    0xe77(%rip),%rsi
mov    %rbx,%rdi
mov    %rbx,%rdx
call   1050 <sscanf@plt>
lea    0xe6f(%rip),%rdx
xor    %edi,%edi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1040 <slog@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"PRIVMSG #%s :%s\0D\0A\00"
@.str.1 = [10 x i8] c"%512[^\0A]\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define void @send_message(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [4098 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = getelementptr inbounds [4098 x i8], [4098 x i8]* %7, i64 0, i64 0
%9 = call i32 @bzero(i8* %8, i32 4098)
%10 = getelementptr inbounds [4098 x i8], [4098 x i8]* %7, i64 0, i64 0
%11 = load i8*, i8** %5
%12 = load i8*, i8** %6
%13 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %12)
%14 = load i32, i32* %4
%15 = getelementptr inbounds [4098 x i8], [4098 x i8]* %7, i64 0, i64 0
%16 = call i32 @send_data(i32 %14, i8* %15)
%17 = getelementptr inbounds [4098 x i8], [4098 x i8]* %7, i64 0, i64 0
%18 = getelementptr inbounds [4098 x i8], [4098 x i8]* %7, i64 0, i64 0
%19 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [4098 x i8], [4098 x i8]* %7, i64 0, i64 0
%21 = call i32 @slog(i32 0, i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %20)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"PRIVMSG #%s :%s\0D\0A\00"
@.str.1 = [10 x i8] c"%512[^\0A]\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define void @send_message(i32 %0, i8* %1, i8* %2) {
%4 = alloca [4098 x i8]
%5 = getelementptr inbounds [4098 x i8], [4098 x i8]* %4, i64 0, i64 0
%6 = call i32 @bzero(i8* %5, i32 4098)
%7 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2)
%8 = call i32 @send_data(i32 %0, i8* %5)
%9 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%10 = call i32 @slog(i32 0, i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
ret void
}