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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ getIp(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int /*<<< orphan*/ writeChar(int, char *);
int /*<<< orphan*/ writeShort(int, char *);
void sendPing(int socket, const char *ip, int port) {
  struct sockaddr_in servaddr;
  memset((char *)&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(port);
  unsigned char myIp[4];
  getIp(ip, &servaddr.sin_addr);
  char pingMessage[7];
  writeChar(1, pingMessage);
  writeShort(258, pingMessage + 1);
  writeShort(41, pingMessage + 3);
  sendto(socket, pingMessage, 7, 0, (struct sockaddr *)&servaddr,
         sizeof(servaddr));
}


x86 assembly (clang, -O0):
<sendPing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <getIp@plt>
lea    -0x2b(%rbp),%rsi
mov    $0x1,%edi
call   1080 <writeChar@plt>
lea    -0x2b(%rbp),%rsi
add    $0x1,%rsi
mov    $0x102,%edi
call   1070 <writeShort@plt>
lea    -0x2b(%rbp),%rsi
add    $0x3,%rsi
mov    $0x29,%edi
call   1070 <writeShort@plt>
mov    -0x4(%rbp),%edi
lea    -0x2b(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x7,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendPing>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %rsi,%rbp
mov    %edi,%r15d
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
mov    %rbp,%rdi
mov    %r14,%rsi
call   1030 <getIp@plt>
lea    0x1(%rsp),%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
call   1080 <writeChar@plt>
lea    0x2(%rsp),%rsi
mov    $0x102,%edi
call   1070 <writeShort@plt>
lea    0x4(%rsp),%rsi
mov    $0x29,%edi
call   1070 <writeShort@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x7,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
define void @sendPing(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca [4 x i8]
%9 = alloca [7 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = bitcast %struct.sockaddr_in* %7 to i8*
%11 = call i32 @memset(i8* %10, i32 0, i32 12)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %12, i32* %13
%14 = load i32, i32* %6
%15 = call i32 @htons(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %15, i32* %16
%17 = load i8*, i8** %5
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%19 = call i32 @getIp(i8* %17, i32* %18)
%20 = getelementptr inbounds [7 x i8], [7 x i8]* %9, i64 0, i64 0
%21 = call i32 @writeChar(i32 1, i8* %20)
%22 = getelementptr inbounds [7 x i8], [7 x i8]* %9, i64 0, i64 0
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = call i32 @writeShort(i32 258, i8* %23)
%25 = getelementptr inbounds [7 x i8], [7 x i8]* %9, i64 0, i64 0
%26 = getelementptr inbounds i8, i8* %25, i64 3
%27 = call i32 @writeShort(i32 41, i8* %26)
%28 = load i32, i32* %4
%29 = getelementptr inbounds [7 x i8], [7 x i8]* %9, i64 0, i64 0
%30 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%31 = call i32 @sendto(i32 %28, i8* %29, i32 7, i32 0, %struct.sockaddr* %30, i32 12)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
define void @sendPing(i32 %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr_in
%5 = alloca [7 x i8]
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = call i32 @memset(i8* %6, i32 0, i32 12)
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %8, i32* %9
%10 = call i32 @htons(i32 %2)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%13 = call i32 @getIp(i8* %1, i32* %12)
%14 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%15 = call i32 @writeChar(i32 1, i8* %14)
%16 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 1
%17 = call i32 @writeShort(i32 258, i8* %16)
%18 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 3
%19 = call i32 @writeShort(i32 41, i8* %18)
%20 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%21 = call i32 @sendto(i32 %0, i8* %14, i32 7, i32 0, %struct.sockaddr* %20, i32 12)
ret void
}