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

/* Variables and functions */
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
             int /*<<< orphan*/ *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
void dg_echo(int sockfd, struct sockaddr *pca, socklen_t clen) {
  socklen_t len;
  int n;
  char s[80];
  for (;;) {
    len = clen;
    n = recvfrom(sockfd, s, 80, 0, pca, &len);
    sendto(sockfd, s, strlen(s), 0, pca, len);
  }
}


x86 assembly (clang, -O0):
<dg_echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    -0x10(%rbp),%r8
mov    $0x50,%edx
xor    %ecx,%ecx
lea    -0x18(%rbp),%r9
call   1050 <recvfrom@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x7c(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9d
xor    %ecx,%ecx
call   1040 <sendto@plt>
jmp    1145 <dg_echo+0x15>

x86 assembly (clang, -O2):
<dg_echo>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
xchg   %ax,%ax
mov    %r14d,0xc(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    %r12,%r9
call   1050 <recvfrom@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    0xc(%rsp),%r9d
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   1040 <sendto@plt>
jmp    1150 <dg_echo+0x20>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
define void @dg_echo(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [80 x i8]
store i32 %0, i32* %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
store i32 %2, i32* %6
br label %10
10: ; preds = %10, %3
%11 = load i32, i32* %6
store i32 %11, i32* %7
%12 = load i32, i32* %4
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%14 = load %struct.sockaddr*, %struct.sockaddr** %5
%15 = call i32 @recvfrom(i32 %12, i8* %13, i32 80, i32 0, %struct.sockaddr* %14, i32* %7)
store i32 %15, i32* %8
%16 = load i32, i32* %4
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = load %struct.sockaddr*, %struct.sockaddr** %5
%21 = load i32, i32* %7
%22 = call i32 @sendto(i32 %16, i8* %17, i32 %19, i32 0, %struct.sockaddr* %20, i32 %21)
br label %10
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
define void @dg_echo(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca [80 x i8]
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
br label %8
8: ; preds = %8, %3
store i32 %2, i32* %4
%9 = call i32 @recvfrom(i32 %0, i8* %7, i32 80, i32 0, %struct.sockaddr* %1, i32* %4)
%10 = call i32 @strlen(i8* %7)
%11 = load i32, i32* %4
%12 = call i32 @sendto(i32 %0, i8* %7, i32 %10, i32 0, %struct.sockaddr* %1, i32 %11)
br label %8
}