#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_storage {
  int /*<<< orphan*/ ss_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ recv_addr_str;
typedef int /*<<< orphan*/ recv_addr;

/* Variables and functions */
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, struct sockaddr *, char *,
                             int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
void recv_print_udp(int sockfd) {
  struct sockaddr_storage recv_addr;
  socklen_t recv_addr_size = sizeof(recv_addr);
  char recv_addr_str[INET6_ADDRSTRLEN];
  char buffer[100];
  int recv_nbytes;
  recv_nbytes = recvfrom(sockfd, buffer, 100 - 1, 0,
                         (struct sockaddr *)&recv_addr, &recv_addr_size);
  if (recv_nbytes == -1) {
    perror("\trecvfrom");
    return;
  }
  buffer[recv_nbytes] = '\0';
  inet_ntop(recv_addr.ss_family, (struct sockaddr *)&recv_addr, recv_addr_str,
            sizeof(recv_addr_str));
  printf("\t[-->x]\tPacket received from %s: %s\n", recv_addr_str, buffer);
}


x86 assembly (clang, -O0):
<recv_print_udp>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x4,-0xc(%rbp)
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0xa8(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xa0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x90(%rbp),%rsi
lea    -0x8(%rbp),%r8
mov    $0x63,%edx
xor    %ecx,%ecx
lea    -0xc(%rbp),%r9
call   1050 <recvfrom@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0xffffffff,-0x94(%rbp)
jne    11d7 <recv_print_udp+0x97>
lea    0xe3d(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x98(%rbp)
jmp    1226 <recv_print_udp+0xe6>
mov    -0xa0(%rbp),%rdx
mov    -0xa8(%rbp),%rax
movslq -0x94(%rbp),%rcx
movb   $0x0,-0x90(%rbp,%rcx,1)
mov    -0x8(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0xa0(%rbp),%rsi
lea    -0x90(%rbp),%rdx
lea    0xdf3(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x98(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_print_udp>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rsp,%r15
movl   $0x4,-0x24(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x90(%rbp),%rsi
lea    -0x20(%rbp),%r8
lea    -0x24(%rbp),%r9
mov    $0x63,%edx
xor    %ecx,%ecx
call   1050 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     11d2 <recv_print_udp+0x92>
cltq
movb   $0x0,-0x90(%rbp,%rax,1)
mov    -0x20(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
lea    0xe55(%rip),%rdi
lea    -0x90(%rbp),%rdx
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r15,%rsp
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe27(%rip),%rdi
call   1060 <perror@plt>
jmp    11c4 <recv_print_udp+0x84>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [10 x i8] c"\09recvfrom\00"
@.str.1 = [37 x i8] c"\09[-->x]\09Packet received from %s: %s\0A\00"
define void @recv_print_udp(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_storage
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [100 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %2
store i32 4, i32* %4
%10 = load i32, i32* @INET6_ADDRSTRLEN
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %5
%13 = alloca i8, i64 %11
store i64 %11, i64* %6
%14 = load i32, i32* %2
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%16 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%17 = call i32 @recvfrom(i32 %14, i8* %15, i32 99, i32 0, %struct.sockaddr* %16, i32* %4)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %1
%21 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %9
br label %33
22: ; preds = %1
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %24
store i8 0, i8* %25
%26 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %3, i32 0, i32 0
%27 = load i32, i32* %26
%28 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%29 = trunc i64 %11 to i32
%30 = call i32 @inet_ntop(i32 %27, %struct.sockaddr* %28, i8* %13, i32 %29)
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%32 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* %31)
store i32 0, i32* %9
br label %33
33: ; preds = %22, %20
%34 = load i8*, i8** %5
%35 = load i32, i32* %9
switch i32 %35, label %37 [
i32 0, label %36
i32 1, label %36
]
36: ; preds = %33, %33
ret void
37: ; preds = %33
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [10 x i8] c"\09recvfrom\00"
@.str.1 = [37 x i8] c"\09[-->x]\09Packet received from %s: %s\0A\00"
define void @recv_print_udp(i32 %0) {
%2 = alloca %struct.sockaddr_storage
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = bitcast %struct.sockaddr_storage* %2 to i8*
%6 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%7 = load i32, i32* @INET6_ADDRSTRLEN
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%12 = bitcast %struct.sockaddr_storage* %2 to %struct.sockaddr*
%13 = call i32 @recvfrom(i32 %0, i8* %11, i32 99, i32 0, %struct.sockaddr* %12, i32* %3)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %24
17: ; preds = %1
%18 = sext i32 %13 to i64
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %2, i64 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @inet_ntop(i32 %21, %struct.sockaddr* %12, i8* %10, i32 %7)
%23 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* %11)
br label %24
24: ; preds = %17, %15
ret void
}