#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 char uint8_t;

/* Variables and functions */
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int strlen(char *);
void send_msg(int sockfd, char *msg) {
  uint8_t len;
  if (strlen(msg) > 254) {
    msg[254] = 0;
  }
  len = strlen(msg) + 1;
  send(sockfd, &len, 1, 0);
  send(sockfd, msg, strlen(msg) + 1, 0);
}


x86 assembly (clang, -O0):
<send_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0xfe,%eax
jle    114e <send_msg+0x2e>
mov    -0x10(%rbp),%rax
movb   $0x0,0xfe(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %al,-0x11(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_msg>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmp    $0xff,%eax
jl     113e <send_msg+0x1e>
movb   $0x0,0xfe(%rbx)
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0x1,%al
mov    %al,0x7(%rsp)
lea    0x7(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1040 <send@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @send_msg(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i32 @strlen(i8* %6)
%8 = icmp sgt i32 %7, 254
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 254
store i8 0, i8* %11
br label %12
12: ; preds = %9, %2
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %14, 1
%16 = trunc i32 %15 to i8
store i8 %16, i8* %5
%17 = load i32, i32* %3
%18 = call i32 @send(i32 %17, i8* %5, i32 1, i32 0)
%19 = load i32, i32* %3
%20 = load i8*, i8** %4
%21 = load i8*, i8** %4
%22 = call i32 @strlen(i8* %21)
%23 = add nsw i32 %22, 1
%24 = call i32 @send(i32 %19, i8* %20, i32 %23, i32 0)
ret void
}

LLVM IR (-O2):
define void @send_msg(i32 %0, i8* %1) {
%3 = alloca i8
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp sgt i32 %4, 254
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %1, i64 254
store i8 0, i8* %7
br label %8
8: ; preds = %6, %2
%9 = tail call i32 @strlen(i8* %1)
%10 = trunc i32 %9 to i8
%11 = add i8 %10, 1
store i8 %11, i8* %3
%12 = call i32 @send(i32 %0, i8* %3, i32 1, i32 0)
%13 = call i32 @strlen(i8* %1)
%14 = add nsw i32 %13, 1
%15 = call i32 @send(i32 %0, i8* %1, i32 %14, i32 0)
ret void
}