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

/* Variables and functions */
int /*<<< orphan*/ recvfrom(int, char *, int, int /*<<< orphan*/,
                            struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int /*<<< orphan*/);
void str_echo(int sockfd, struct sockaddr *cliaddr, socklen_t addrlen) {
  ssize_t n;
  char msg[1024];
  while (1) {
    n = recvfrom(sockfd, msg, 1024, 0, cliaddr, &addrlen);
    sendto(sockfd, msg, n, 0, cliaddr, addrlen);
  }
}


x86 assembly (clang, -O0):
<str_echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x10(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x14(%rbp),%r9
call   1040 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%r8
mov    -0x14(%rbp),%r9d
xor    %ecx,%ecx
call   1030 <sendto@plt>
jmp    1135 <str_echo+0x15>

x86 assembly (clang, -O2):
<str_echo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %edx,0xc(%rsp)
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    %r15,%r9
call   1040 <recvfrom@plt>
mov    0xc(%rsp),%r9d
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   1030 <sendto@plt>
jmp    1140 <str_echo+0x20>

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

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