#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*/ exit(int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void cmd_msg_cb(int fd, short events, void *arg) {
  char msg[1024];
  int ret = read(fd, msg, sizeof(msg));
  if (ret <= 0) {
    perror("read fail ");
    exit(1);
  }
  int sockfd = *((int *)arg);
  write(sockfd, msg, ret);
}


x86 assembly (clang, -O0):
<cmd_msg_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jg     1196 <cmd_msg_cb+0x56>
lea    0xe79(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x418(%rbp)
mov    -0x418(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
call   1030 <write@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_msg_cb>:
push   %rbx
sub    $0x400,%rsp
mov    %rdx,%rbx
mov    %rsp,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    1171 <cmd_msg_cb+0x31>
mov    (%rbx),%edi
mov    %rsp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x400,%rsp
pop    %rbx
ret
lea    0xe88(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"read fail \00"
define void @cmd_msg_cb(i32 %0, i16 signext %1, i8* %2) {
%4 = alloca i32
%5 = alloca i16
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i16 %1, i16* %5
store i8* %2, i8** %6
%10 = load i32, i32* %4
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 1024)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp sle i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = bitcast i8* %19 to i32*
%21 = load i32, i32* %20
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%24 = load i32, i32* %8
%25 = call i32 @write(i32 %22, i8* %23, i32 %24)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"read fail \00"
define void @cmd_msg_cb(i32 %0, i16 signext %1, i8* nocapture %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32 @read(i32 %0, i8* %5, i32 1024)
%7 = icmp slt i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %3
%12 = bitcast i8* %2 to i32*
%13 = load i32, i32* %12
%14 = call i32 @write(i32 %13, i8* %5, i32 %6)
ret void
}