dg_echo(sockfd, pcli_addr, maxclilen) int sockfd;
struct sockaddr *pcli_addr;
int maxclilen;
{
  int n, clilen;
  char mesg[2048];
  for (;;) {
    clilen = maxclilen;
    n = recvfrom(sockfd, mesg, 2048, 0, pcli_addr, &clilen);
    printf("Packet Recieved : \t");
    puts(mesg);
    if (n < 0)
      perror("dg_echo: recvfrom error");
    sleep(1);
    if (sendto(sockfd, mesg, n, 0, pcli_addr, clilen) != n)
      perror("dg_echo: sendto error");
    printf("Packet Send Back \n");
  }
}


x86 assembly (clang, -O0):
<dg_echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0x10(%rbp),%r8
mov    $0x800,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
mov    $0x0,%al
call   1060 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x820(%rbp),%rdi
mov    $0x0,%al
call   1030 <puts@plt>
cmpl   $0x0,-0x18(%rbp)
jge    11d2 <dg_echo+0x72>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1070 <perror@plt>
mov    $0x1,%edi
mov    $0x0,%al
call   1080 <sleep@plt>
mov    -0x4(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%r8
mov    -0x1c(%rbp),%r9d
xor    %ecx,%ecx
mov    $0x0,%al
call   1050 <sendto@plt>
cmp    -0x18(%rbp),%eax
je     1213 <dg_echo+0xb3>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1070 <perror@plt>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1175 <dg_echo+0x15>

x86 assembly (clang, -O2):
<dg_echo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x10(%rsp),%r15
lea    0xebd(%rip),%r12
jmp    1198 <dg_echo+0x38>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r14d,0xc(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
lea    0xc(%rsp),%r9
xor    %eax,%eax
call   1060 <recvfrom@plt>
mov    %eax,%r13d
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <puts@plt>
test   %r13d,%r13d
jns    11e6 <dg_echo+0x86>
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1070 <perror@plt>
mov    $0x1,%edi
xor    %eax,%eax
call   1080 <sleep@plt>
mov    0xc(%rsp),%r9d
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r13d,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <sendto@plt>
cmp    %r13d,%eax
je     1190 <dg_echo+0x30>
lea    0xe15(%rip),%rdi
xor    %eax,%eax
call   1070 <perror@plt>
jmp    1190 <dg_echo+0x30>

LLVM IR (-O0):
%struct.sockaddr = type opaque
@.str = [20 x i8] c"Packet Recieved : \09\00"
@.str.1 = [24 x i8] c"dg_echo: recvfrom error\00"
@.str.2 = [22 x i8] c"dg_echo: sendto error\00"
@.str.3 = [19 x i8] c"Packet Send Back \0A\00"
define i32 @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 [2048 x i8]
store i32 %0, i32* %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
store i32 %2, i32* %6
br label %10
10: ; preds = %35, %3
%11 = load i32, i32* %6
store i32 %11, i32* %8
%12 = load i32, i32* %4
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%14 = load %struct.sockaddr*, %struct.sockaddr** %5
%15 = call i32 (i32, i8*, i32, i32, %struct.sockaddr*, i32*, ...) bitcast (i32 (...)* @recvfrom to i32 (i32, i8*, i32, i32, %struct.sockaddr*, i32*, ...)*)(i32 %12, i8* %13, i32 2048, i32 0, %struct.sockaddr* %14, i32* %8)
store i32 %15, i32* %7
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%18 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* %17)
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %10
%22 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %10
%24 = call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 1)
%25 = load i32, i32* %4
%26 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%27 = load i32, i32* %7
%28 = load %struct.sockaddr*, %struct.sockaddr** %5
%29 = load i32, i32* %8
%30 = call i32 (i32, i8*, i32, i32, %struct.sockaddr*, i32, ...) bitcast (i32 (...)* @sendto to i32 (i32, i8*, i32, i32, %struct.sockaddr*, i32, ...)*)(i32 %25, i8* %26, i32 %27, i32 0, %struct.sockaddr* %28, i32 %29)
%31 = load i32, i32* %7
%32 = icmp ne i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %23
%34 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %23
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %10
}

LLVM IR (-O2):
%struct.sockaddr = type opaque
@.str = [20 x i8] c"Packet Recieved : \09\00"
@.str.1 = [24 x i8] c"dg_echo: recvfrom error\00"
@.str.2 = [22 x i8] c"dg_echo: sendto error\00"
@str = [18 x i8] c"Packet Send Back \00"
define i32 @dg_echo(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca [2048 x i8]
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
br label %8
8: ; preds = %22, %3
store i32 %2, i32* %4
%9 = call i32 (i32, i8*, i32, i32, %struct.sockaddr*, i32*, ...) bitcast (i32 (...)* @recvfrom to i32 (i32, i8*, i32, i32, %struct.sockaddr*, i32*, ...)*)(i32 %0, i8* %7, i32 2048, i32 0, %struct.sockaddr* %1, i32* %4)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* %7)
%12 = icmp slt i32 %9, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 1)
%17 = load i32, i32* %4
%18 = call i32 (i32, i8*, i32, i32, %struct.sockaddr*, i32, ...) bitcast (i32 (...)* @sendto to i32 (i32, i8*, i32, i32, %struct.sockaddr*, i32, ...)*)(i32 %0, i8* %7, i32 %9, i32 0, %struct.sockaddr* %1, i32 %17)
%19 = icmp eq i32 %18, %9
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = call i32 bitcast (i32 (...)* @puts to i32 (i8*)*)(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %8
}