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

/* Variables and functions */
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ recvfrom(int, void *, int, int /*<<< orphan*/,
                            struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ strncmp(char *, char *, int);
void *receiver(void *arg) {
  int sock = *((int *)arg);
  for (;;) {
    char buf[4];
    struct sockaddr_in sender;
    socklen_t socklen;
    recvfrom(sock, (void *)buf, 4, 0, (struct sockaddr *)&sender, &socklen);
    if (!strncmp(buf, "PONG", 4)) {
      printf("received PONG from %s\n", inet_ntoa(sender.sin_addr));
    }
  }
}


x86 assembly (clang, -O0):
<receiver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%r8
mov    $0x4,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   1060 <recvfrom@plt>
lea    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11a5 <receiver+0x65>
mov    -0x18(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe65(%rip),%rdi
call   1050 <printf@plt>
jmp    1155 <receiver+0x15>

x86 assembly (clang, -O2):
<receiver>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    (%rdi),%ebp
lea    0x14(%rsp),%rbx
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xe9a(%rip),%r12
lea    0xe98(%rip),%r13
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1060 <recvfrom@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1170 <receiver+0x30>
mov    0x8(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %r13,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
jmp    1170 <receiver+0x30>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"PONG\00"
@.str.1 = [23 x i8] c"received PONG from %s\0A\00"
define i8* @receiver(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [4 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = bitcast i8* %7 to i32*
%9 = load i32, i32* %8
store i32 %9, i32* %3
br label %10
10: ; preds = %23, %1
%11 = load i32, i32* %3
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%13 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%14 = call i32 @recvfrom(i32 %11, i8* %12, i32 4, i32 0, %struct.sockaddr* %13, i32* %6)
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%16 = call i32 @strncmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%17 = icmp ne i32 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %10
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i8* @inet_ntoa(i32 %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %18, %10
br label %10
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"PONG\00"
@.str.1 = [23 x i8] c"received PONG from %s\0A\00"
define noalias i8* @receiver(i8* nocapture %0) {
%2 = alloca [4 x i8]
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = bitcast i8* %0 to i32*
%6 = load i32, i32* %5
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
br label %12
12: ; preds = %20, %1
%13 = call i32 @recvfrom(i32 %6, i8* %7, i32 4, i32 0, %struct.sockaddr* %10, i32* %4)
%14 = call i32 @strncmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i32, i32* %11
%18 = call i8* @inet_ntoa(i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %16, %12
br label %12
}