#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 mux_socket {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ mux_socket_close(struct mux_socket *);
int /*<<< orphan*/ mux_socket_write(struct mux_socket *, char *, scalar_t__);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
void readcb(struct mux_socket *sock, const char *data, size_t len, void *arg) {
  printf("%s\n", data);
  printf("len %d\n", len);
  mux_socket_write(sock, "hello", strlen("hello") + 1);
  mux_socket_close(sock);
}


x86 assembly (clang, -O0):
<readcb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe81(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xe6a(%rip),%rsi
call   1060 <mux_socket_write@plt>
mov    -0x8(%rbp),%rdi
call   1050 <mux_socket_close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readcb>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <puts@plt>
lea    0xea7(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9e(%rip),%rsi
mov    $0x6,%edx
mov    %rbx,%rdi
call   1060 <mux_socket_write@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <mux_socket_close@plt>

LLVM IR (-O0):
%struct.mux_socket = type { i32 }
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [8 x i8] c"len %d\0A\00"
@.str.2 = [6 x i8] c"hello\00"
define void @readcb(%struct.mux_socket* %0, i8* %1, i64 %2, i8* %3) {
%5 = alloca %struct.mux_socket*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
store %struct.mux_socket* %0, %struct.mux_socket** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i8* %3, i8** %8
%9 = load i8*, i8** %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i64, i64* %7
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 %11)
%13 = load %struct.mux_socket*, %struct.mux_socket** %5
%14 = call i64 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%15 = add nsw i64 %14, 1
%16 = call i32 @mux_socket_write(%struct.mux_socket* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %15)
%17 = load %struct.mux_socket*, %struct.mux_socket** %5
%18 = call i32 @mux_socket_close(%struct.mux_socket* %17)
ret void
}

LLVM IR (-O2):
%struct.mux_socket = type { i32 }
@.str.1 = [8 x i8] c"len %d\0A\00"
@.str.2 = [6 x i8] c"hello\00"
define void @readcb(%struct.mux_socket* %0, i8* nocapture %1, i64 %2, i8* nocapture readnone %3) {
%5 = tail call i32 @puts(i8* dereferenceable(1) %1)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 %2)
%7 = tail call i32 @mux_socket_write(%struct.mux_socket* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 6)
%8 = tail call i32 @mux_socket_close(%struct.mux_socket* %0)
ret void
}