#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*/ strncpy(char *, char *, char);
int /*<<< orphan*/ write(int, char *, char);
void sendMsg(int sockfd, char *buffer, char frameSize) {
  char sendBuffer[frameSize + 1];
  sendBuffer[0] = frameSize;
  strncpy(sendBuffer + 1, buffer, frameSize);
  write(sockfd, sendBuffer, frameSize + 1);
}


x86 assembly (clang, -O0):
<sendMsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x11(%rbp),%al
mov    %al,(%rdi)
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
movsbl -0x11(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%rsi
mov    -0x4(%rbp),%edi
movsbl -0x11(%rbp),%eax
add    $0x1,%eax
movsbl %al,%edx
call   1040 <write@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendMsg>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
lea    0x1(%rdx),%r15d
mov    %rsp,%rax
lea    0xf(%r15),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rax,%rbx
sub    %rcx,%rbx
mov    %rbx,%rsp
neg    %rcx
mov    %dl,(%rax,%rcx,1)
lea    0x1(%rbx),%rdi
call   1030 <strncpy@plt>
movsbl %r15b,%edx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1040 <write@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @sendMsg(i32 %0, i8* %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8 %2, i8* %6
%9 = load i8, i8* %6
%10 = sext i8 %9 to i32
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i8, i64 %12
store i64 %12, i64* %8
%15 = load i8, i8* %6
%16 = getelementptr inbounds i8, i8* %14, i64 0
store i8 %15, i8* %16
%17 = getelementptr inbounds i8, i8* %14, i64 1
%18 = load i8*, i8** %5
%19 = load i8, i8* %6
%20 = call i32 @strncpy(i8* %17, i8* %18, i8 signext %19)
%21 = load i32, i32* %4
%22 = load i8, i8* %6
%23 = sext i8 %22 to i32
%24 = add nsw i32 %23, 1
%25 = trunc i32 %24 to i8
%26 = call i32 @write(i32 %21, i8* %14, i8 signext %25)
%27 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
define void @sendMsg(i32 %0, i8* %1, i8 signext %2) {
%4 = sext i8 %2 to i32
%5 = add nsw i32 %4, 1
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
store i8 %2, i8* %7
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = call i32 @strncpy(i8* %8, i8* %1, i8 signext %2)
%10 = trunc i32 %5 to i8
%11 = call i32 @write(i32 %0, i8* %7, i8 signext %10)
ret void
}