#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 */
struct mg_connection {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ mg_write(struct mg_connection *, unsigned char *, int);
unsigned char snprintf(char *, int, char *, char *);
void websocket_ready_handler(struct mg_connection *conn) {
  unsigned char buf[40];
  buf[0] = 0x81;
  buf[1] = snprintf((char *)buf + 2, sizeof(buf) - 2, "%s", "server ready");
  mg_write(conn, buf, 2 + buf[1]);
}


x86 assembly (clang, -O0):
<websocket_ready_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x81,-0x30(%rbp)
lea    -0x30(%rbp),%rdi
add    $0x2,%rdi
mov    $0x26,%esi
lea    0xebc(%rip),%rdx
lea    0xeb8(%rip),%rcx
call   1030 <snprintf@plt>
mov    %al,-0x2f(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
movzbl -0x2f(%rbp),%edx
add    $0x2,%edx
call   1040 <mg_write@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<websocket_ready_handler>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
movb   $0x81,(%rsp)
lea    0x2(%rsp),%rdi
lea    0xec8(%rip),%rdx
lea    0xec4(%rip),%rcx
mov    $0x26,%esi
call   1030 <snprintf@plt>
mov    %al,0x1(%rsp)
movzbl %al,%edx
add    $0x2,%edx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1040 <mg_write@plt>
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.mg_connection = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [13 x i8] c"server ready\00"
define void @websocket_ready_handler(%struct.mg_connection* %0) {
%2 = alloca %struct.mg_connection*
%3 = alloca [40 x i8]
store %struct.mg_connection* %0, %struct.mg_connection** %2
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
store i8 -127, i8* %4
%5 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds i8, i8* %5, i64 2
%7 = call zeroext i8 @snprintf(i8* %6, i32 38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 1
store i8 %7, i8* %8
%9 = load %struct.mg_connection*, %struct.mg_connection** %2
%10 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 1
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = add nsw i32 2, %13
%15 = call i32 @mg_write(%struct.mg_connection* %9, i8* %10, i32 %14)
ret void
}

LLVM IR (-O2):
%struct.mg_connection = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [13 x i8] c"server ready\00"
define void @websocket_ready_handler(%struct.mg_connection* %0) {
%2 = alloca [40 x i8]
%3 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
store i8 -127, i8* %3
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 2
%5 = call zeroext i8 @snprintf(i8* %4, i32 38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 1
store i8 %5, i8* %6
%7 = zext i8 %5 to i32
%8 = add nuw nsw i32 %7, 2
%9 = call i32 @mg_write(%struct.mg_connection* %0, i8* %3, i32 %8)
ret void
}