#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sockaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_BROADCAST;
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int /*<<< orphan*/ sleep(int);
void *sender(void *arg) {
  int sock = *((int *)arg);
  struct sockaddr_in sockaddr;
  sockaddr.sin_family = AF_INET;
  sockaddr.sin_port = htons(9999);
  sockaddr.sin_addr.s_addr = INADDR_BROADCAST;
  for (;;) {
    printf("PING?\n");
    sendto(sock, "PING", 4, 0, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
    sleep(3);
  }
}


x86 assembly (clang, -O0):
<sender>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x270f,%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xe7f(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%r8
lea    0xe73(%rip),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    $0x3,%edi
call   1060 <sleep@plt>
jmp    117a <sender+0x3a>

x86 assembly (clang, -O2):
<sender>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    (%rdi),%ebx
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    $0x270f,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0xe89(%rip),%r14
lea    0xe7d(%rip),%r15
lea    0x8(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    $0x3,%edi
call   1060 <sleep@plt>
jmp    1190 <sender+0x50>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_BROADCAST = global i32 0
@.str = [7 x i8] c"PING?\0A\00"
@.str.1 = [5 x i8] c"PING\00"
define i8* @sender(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = bitcast i8* %5 to i32*
%7 = load i32, i32* %6
store i32 %7, i32* %3
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %8, i32* %9
%10 = call i32 @htons(i32 9999)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %10, i32* %11
%12 = load i32, i32* @INADDR_BROADCAST
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%14 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %13, i32 0, i32 0
store i32 %12, i32* %14
br label %15
15: ; preds = %15, %1
%16 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %3
%18 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%19 = call i32 @sendto(i32 %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4, i32 0, %struct.sockaddr* %18, i32 12)
%20 = call i32 @sleep(i32 3)
br label %15
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_BROADCAST = global i32 0
@.str.1 = [5 x i8] c"PING\00"
@str = [6 x i8] c"PING?\00"
define noalias i8* @sender(i8* nocapture %0) {
%2 = alloca %struct.sockaddr_in
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = load i32, i32* @AF_INET
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %6, i32* %7
%8 = tail call i32 @htons(i32 9999)
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %8, i32* %9
%10 = load i32, i32* @INADDR_BROADCAST
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %10, i32* %11
%12 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
br label %13
13: ; preds = %13, %1
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%15 = call i32 @sendto(i32 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4, i32 0, %struct.sockaddr* %12, i32 12)
%16 = call i32 @sleep(i32 3)
br label %13
}