#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 sockaddr_un {
  char *sun_path;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ addr_buf_;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *, char *);
int recvfrom(int, void *, int, int /*<<< orphan*/, struct sockaddr *, int *);
void udp_cb(int fd) {
  char buf[65536];
  char addr_buf_[sizeof(struct sockaddr_un)];
  struct sockaddr_un *cli_addr_ = (struct sockaddr_un *)addr_buf_;
  socklen_t socklen = sizeof(addr_buf_);
  int ret_ = recvfrom(fd, (void *)buf, sizeof(buf), 0,
                      (struct sockaddr *)cli_addr_, &socklen);
  if (ret_ > 0) {
    cli_addr_->sun_path[socklen - 2] = '\0';
    printf("recv '%s' from '%s'\n", buf, cli_addr_->sun_path + 1);
  }
}


x86 assembly (clang, -O0):
<udp_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10030,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x10018(%rbp),%rax
mov    %rax,-0x10020(%rbp)
movl   $0x8,-0x10024(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10010(%rbp),%rsi
mov    -0x10020(%rbp),%r8
mov    $0x10000,%edx
xor    %ecx,%ecx
lea    -0x10024(%rbp),%r9
call   1040 <recvfrom@plt>
mov    %eax,-0x10028(%rbp)
cmpl   $0x0,-0x10028(%rbp)
jle    11b8 <udp_cb+0x98>
mov    -0x10020(%rbp),%rax
mov    (%rax),%rax
mov    -0x10024(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x10010(%rbp),%rsi
mov    -0x10020(%rbp),%rax
mov    (%rax),%rdx
add    $0x1,%rdx
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
add    $0x10030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_cb>:
sub    $0x10018,%rsp
movl   $0x8,0x4(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%r8
lea    0x4(%rsp),%r9
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1040 <recvfrom@plt>
test   %eax,%eax
jle    1177 <udp_cb+0x57>
mov    0x8(%rsp),%rax
movslq 0x4(%rsp),%rcx
movb   $0x0,-0x2(%rcx,%rax,1)
mov    0x8(%rsp),%rdx
add    $0x1,%rdx
lea    0xe93(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1030 <printf@plt>
add    $0x10018,%rsp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i8* }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"recv '%s' from '%s'\0A\00"
define void @udp_cb(i32 %0) {
%2 = alloca i32
%3 = alloca [65536 x i8]
%4 = alloca [8 x i8]
%5 = alloca %struct.sockaddr_un*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%9 = bitcast i8* %8 to %struct.sockaddr_un*
store %struct.sockaddr_un* %9, %struct.sockaddr_un** %5
store i32 8, i32* %6
%10 = load i32, i32* %2
%11 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%12 = load %struct.sockaddr_un*, %struct.sockaddr_un** %5
%13 = bitcast %struct.sockaddr_un* %12 to %struct.sockaddr*
%14 = call i32 @recvfrom(i32 %10, i8* %11, i32 65536, i32 0, %struct.sockaddr* %13, i32* %6)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %31
17: ; preds = %1
%18 = load %struct.sockaddr_un*, %struct.sockaddr_un** %5
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = load i32, i32* %6
%22 = sub nsw i32 %21, 2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 0, i8* %24
%25 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%26 = load %struct.sockaddr_un*, %struct.sockaddr_un** %5
%27 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %25, i8* %29)
br label %31
31: ; preds = %17, %1
ret void
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8* }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"recv '%s' from '%s'\0A\00"
define void @udp_cb(i32 %0) {
%2 = alloca [65536 x i8]
%3 = alloca %struct.sockaddr_un
%4 = alloca i32
%5 = getelementptr inbounds [65536 x i8], [65536 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.sockaddr_un* %3 to i8*
%7 = bitcast i32* %4 to i8*
store i32 8, i32* %4
%8 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%9 = call i32 @recvfrom(i32 %0, i8* %5, i32 65536, i32 0, %struct.sockaddr* %8, i32* %4)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %1
%12 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = load i32, i32* %4
%15 = add nsw i32 %14, -2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
store i8 0, i8* %17
%18 = load i8*, i8** %12
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %19)
br label %21
21: ; preds = %11, %1
ret void
}