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

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
unsigned int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
                      int /*<<< orphan*/);
unsigned int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
                    int /*<<< orphan*/);
int process_packet(int socket_fd) {
  struct sockaddr_un server_address;
  struct sockaddr_un client_address;
  unsigned int bytes_received, bytes_sent, address_length;
  int integer_buffer;
  address_length = sizeof(struct sockaddr_un);
  while (1) {
    bytes_received = recvfrom(socket_fd, (char *)&integer_buffer, sizeof(int),
                              0, (struct sockaddr *)&(client_address),
                              (socklen_t)address_length);
    if (bytes_received != sizeof(int)) {
      printf("datagram was the wrong size.\n");
    } else {
      integer_buffer += 5;
      bytes_sent = sendto(socket_fd, (char *)&integer_buffer, sizeof(int), 0,
                          (struct sockaddr *)&(client_address),
                          (socklen_t)address_length);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<process_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x4,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x10(%rbp),%r8
mov    -0x1c(%rbp),%r9d
mov    $0x4,%edx
xor    %ecx,%ecx
call   1050 <recvfrom@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    $0x4,%rax
je     117e <process_packet+0x4e>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
jmp    11a5 <process_packet+0x75>
mov    -0x20(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x10(%rbp),%r8
mov    -0x1c(%rbp),%r9d
mov    $0x4,%edx
xor    %ecx,%ecx
call   1040 <sendto@plt>
mov    %eax,-0x18(%rbp)
jmp    1142 <process_packet+0x12>

x86 assembly (clang, -O2):
<process_packet>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    0xc(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xeb2(%rip),%r12
jmp    1158 <process_packet+0x28>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x4,%r9d
call   1050 <recvfrom@plt>
cmp    $0x4,%eax
jne    1150 <process_packet+0x20>
addl   $0x5,0xc(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x4,%r9d
call   1040 <sendto@plt>
jmp    1158 <process_packet+0x28>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [30 x i8] c"datagram was the wrong size.\0A\00"
define i32 @process_packet(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_un
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %2
store i32 4, i32* %7
br label %9
9: ; preds = %1, %28
%10 = load i32, i32* %2
%11 = bitcast i32* %8 to i8*
%12 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%13 = load i32, i32* %7
%14 = call i32 @recvfrom(i32 %10, i8* %11, i32 4, i32 0, %struct.sockaddr* %12, i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = zext i32 %15 to i64
%17 = icmp ne i64 %16, 4
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %28
20: ; preds = %9
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 5
store i32 %22, i32* %8
%23 = load i32, i32* %2
%24 = bitcast i32* %8 to i8*
%25 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%26 = load i32, i32* %7
%27 = call i32 @sendto(i32 %23, i8* %24, i32 4, i32 0, %struct.sockaddr* %25, i32 %26)
store i32 %27, i32* %6
br label %28
28: ; preds = %20, %18
br label %9
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@str = [29 x i8] c"datagram was the wrong size.\00"
define i32 @process_packet(i32 %0) {
%2 = alloca %struct.sockaddr_un
%3 = alloca i32
%4 = bitcast %struct.sockaddr_un* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
br label %7
7: ; preds = %16, %1
%8 = call i32 @recvfrom(i32 %0, i8* %5, i32 4, i32 0, %struct.sockaddr* %6, i32 4)
%9 = icmp eq i32 %8, 4
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %16
12: ; preds = %7
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 5
store i32 %14, i32* %3
%15 = call i32 @sendto(i32 %0, i8* %5, i32 4, i32 0, %struct.sockaddr* %6, i32 4)
br label %16
16: ; preds = %12, %10
br label %7
}