#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 size_t ssize_t;
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ in_addr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EAGAIN;
scalar_t__ errno;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ htons(unsigned int);
int /*<<< orphan*/ ksft_print_msg(char *, int /*<<< orphan*/, int, ...);
scalar_t__ memcmp(char *, char **, size_t);
size_t recv(int, char **, size_t, int /*<<< orphan*/);
size_t sendto(int, char *, size_t, int /*<<< orphan*/, struct sockaddr const *,
              int);
int udp_ping_reply(int sock[2], in_addr_t dest_ip, unsigned int port, char *buf,
                   size_t buf_len) {
  struct sockaddr_in server;
  const struct sockaddr *dest_addr = (struct sockaddr *)&server;
  char *sock_buf[buf_len];
  ssize_t r_bytes, s_bytes;
  server.sin_family = AF_INET;
  server.sin_port = htons(port);
  server.sin_addr.s_addr = dest_ip;
  r_bytes = recv(sock[0], sock_buf, buf_len, 0);
  if (r_bytes < 0) {
    if (errno != EAGAIN)
      ksft_print_msg("%d[%u] "
                     "recv()"
                     ": %m"
                     "\n",
                     getpid(), 679);
    return -1;
  }
  if (r_bytes == 0) {
    ksft_print_msg("%d[%u] "
                   "EOF on reply to ping"
                   "\n",
                   getpid(), 683);
    return -1;
  }
  if (r_bytes != buf_len || memcmp(buf, sock_buf, buf_len)) {
    ksft_print_msg("%d[%u] "
                   "ping reply packet is corrupted %zd/%zu"
                   "\n",
                   getpid(), 687, r_bytes, buf_len);
    return -1;
  }
  s_bytes = sendto(sock[1], buf, buf_len, 0, dest_addr, sizeof(server));
  if (s_bytes < 0) {
    ksft_print_msg("%d[%u] "
                   "sendto()"
                   ": %m"
                   "\n",
                   getpid(), 693);
    return -1;
  } else if (s_bytes != buf_len) {
    ksft_print_msg("%d[%u] "
                   "send part of the message: %zd/%zu"
                   "\n",
                   getpid(), 696, s_bytes, sizeof(server));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<udp_ping_reply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
lea    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <htons@plt>
mov    -0x70(%rbp),%rsi
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jae    1234 <udp_ping_reply+0xd4>
mov    0x2de6(%rip),%rax
mov    (%rax),%rax
mov    0x2dcc(%rip),%rcx
cmp    (%rcx),%rax
je     1221 <udp_ping_reply+0xc1>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xdeb(%rip),%rdi
mov    $0x2a7,%edx
mov    $0x0,%al
call   1080 <ksft_print_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1386 <udp_ping_reply+0x226>
cmpq   $0x0,-0x58(%rbp)
jne    126e <udp_ping_reply+0x10e>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xdc4(%rip),%rdi
mov    $0x2ab,%edx
mov    $0x0,%al
call   1080 <ksft_print_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1386 <udp_ping_reply+0x226>
mov    -0x58(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1297 <udp_ping_reply+0x137>
mov    -0x70(%rbp),%rsi
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
je     12ce <udp_ping_reply+0x16e>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x58(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xd81(%rip),%rdi
mov    $0x2af,%edx
mov    $0x0,%al
call   1080 <ksft_print_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1386 <udp_ping_reply+0x226>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x40(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jae    132c <udp_ping_reply+0x1cc>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xd52(%rip),%rdi
mov    $0x2b5,%edx
mov    $0x0,%al
call   1080 <ksft_print_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1386 <udp_ping_reply+0x226>
mov    -0x60(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     1373 <udp_ping_reply+0x213>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x60(%rbp),%rcx
lea    0xd26(%rip),%rdi
mov    $0x2b8,%edx
mov    $0xc,%r8d
mov    $0x0,%al
call   1080 <ksft_print_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1386 <udp_ping_reply+0x226>
jmp    1378 <udp_ping_reply+0x218>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_ping_reply>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r12
mov    %rcx,%r14
mov    %esi,%r13d
mov    %rdi,%r15
mov    %rsp,-0x30(%rbp)
mov    %rsp,%rbx
lea    0xf(,%r8,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    %edx,%edi
call   1050 <htons@plt>
mov    %eax,-0x3c(%rbp)
mov    %r13d,-0x40(%rbp)
mov    (%r15),%edi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
je     1204 <udp_ping_reply+0xa4>
mov    %rax,%r13
cmp    %r12,%rax
jne    11e0 <udp_ping_reply+0x80>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1070 <memcmp@plt>
test   %rax,%rax
je     123d <udp_ping_reply+0xdd>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe2f(%rip),%rdi
mov    %eax,%esi
mov    $0x2af,%edx
mov    %r13,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1080 <ksft_print_msg@plt>
jmp    1220 <udp_ping_reply+0xc0>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xdee(%rip),%rdi
mov    %eax,%esi
mov    $0x2ab,%edx
xor    %eax,%eax
call   1080 <ksft_print_msg@plt>
mov    $0xffffffff,%ebx
mov    -0x30(%rbp),%r15
mov    %r15,%rsp
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x4(%r15),%edi
xor    %ebx,%ebx
lea    -0x40(%rbp),%r8
mov    %r14,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
cmp    %r12,%rax
mov    -0x30(%rbp),%r15
je     1229 <udp_ping_reply+0xc9>
mov    %rax,%r14
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xdd8(%rip),%rdi
mov    $0xc,%r8d
mov    %eax,%esi
mov    $0x2b8,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   1080 <ksft_print_msg@plt>
mov    $0xffffffff,%ebx
jmp    1229 <udp_ping_reply+0xc9>

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
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [19 x i8] c"%d[%u] recv(): %m\0A\00"
@.str.1 = [29 x i8] c"%d[%u] EOF on reply to ping\0A\00"
@.str.2 = [47 x i8] c"%d[%u] ping reply packet is corrupted %zd/%zu\0A\00"
@.str.3 = [21 x i8] c"%d[%u] sendto(): %m\0A\00"
@.str.4 = [42 x i8] c"%d[%u] send part of the message: %zd/%zu\0A\00"
define i32 @udp_ping_reply(i32* %0, i32 %1, i32 %2, i8* %3, i64 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca %struct.sockaddr_in
%13 = alloca %struct.sockaddr*
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i32
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i64 %4, i64* %11
%19 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
store %struct.sockaddr* %19, %struct.sockaddr** %13
%20 = load i64, i64* %11
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %14
%22 = alloca i8*, i64 %20
store i64 %20, i64* %15
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* %9
%26 = call i32 @htons(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* %8
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i32 %28, i32* %30
%31 = load i32*, i32** %7
%32 = getelementptr inbounds i32, i32* %31, i64 0
%33 = load i32, i32* %32
%34 = load i64, i64* %11
%35 = call i64 @recv(i32 %33, i8** %22, i64 %34, i32 0)
store i64 %35, i64* %16
%36 = load i64, i64* %16
%37 = icmp ult i64 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %5
%39 = load i64, i64* @errno
%40 = load i64, i64* @EAGAIN
%41 = icmp ne i64 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = call i32 (...) @getpid()
%44 = call i32 (i8*, i32, i32, ...) @ksft_print_msg(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %43, i32 679)
br label %45
45: ; preds = %42, %38
store i32 -1, i32* %6
store i32 1, i32* %18
br label %89
46: ; preds = %5
%47 = load i64, i64* %16
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = call i32 (...) @getpid()
%51 = call i32 (i8*, i32, i32, ...) @ksft_print_msg(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %50, i32 683)
store i32 -1, i32* %6
store i32 1, i32* %18
br label %89
52: ; preds = %46
%53 = load i64, i64* %16
%54 = load i64, i64* %11
%55 = icmp ne i64 %53, %54
br i1 %55, label %61, label %56
56: ; preds = %52
%57 = load i8*, i8** %10
%58 = load i64, i64* %11
%59 = call i64 @memcmp(i8* %57, i8** %22, i64 %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %56, %52
%62 = call i32 (...) @getpid()
%63 = load i64, i64* %16
%64 = load i64, i64* %11
%65 = call i32 (i8*, i32, i32, ...) @ksft_print_msg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %62, i32 687, i64 %63, i64 %64)
store i32 -1, i32* %6
store i32 1, i32* %18
br label %89
66: ; preds = %56
%67 = load i32*, i32** %7
%68 = getelementptr inbounds i32, i32* %67, i64 1
%69 = load i32, i32* %68
%70 = load i8*, i8** %10
%71 = load i64, i64* %11
%72 = load %struct.sockaddr*, %struct.sockaddr** %13
%73 = call i64 @sendto(i32 %69, i8* %70, i64 %71, i32 0, %struct.sockaddr* %72, i32 12)
store i64 %73, i64* %17
%74 = load i64, i64* %17
%75 = icmp ult i64 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %66
%77 = call i32 (...) @getpid()
%78 = call i32 (i8*, i32, i32, ...) @ksft_print_msg(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %77, i32 693)
store i32 -1, i32* %6
store i32 1, i32* %18
br label %89
79: ; preds = %66
%80 = load i64, i64* %17
%81 = load i64, i64* %11
%82 = icmp ne i64 %80, %81
br i1 %82, label %83, label %87
83: ; preds = %79
%84 = call i32 (...) @getpid()
%85 = load i64, i64* %17
%86 = call i32 (i8*, i32, i32, ...) @ksft_print_msg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %84, i32 696, i64 %85, i64 12)
store i32 -1, i32* %6
store i32 1, i32* %18
br label %89
87: ; preds = %79
br label %88
88: ; preds = %87
store i32 0, i32* %6
store i32 1, i32* %18
br label %89
89: ; preds = %88, %83, %76, %61, %49, %45
%90 = load i8*, i8** %14
%91 = load i32, i32* %6
ret i32 %91
}

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
@errno = global i64 0
@EAGAIN = global i64 0
@.str.1 = [29 x i8] c"%d[%u] EOF on reply to ping\0A\00"
@.str.2 = [47 x i8] c"%d[%u] ping reply packet is corrupted %zd/%zu\0A\00"
@.str.4 = [42 x i8] c"%d[%u] send part of the message: %zd/%zu\0A\00"
define i32 @udp_ping_reply(i32* nocapture %0, i32 %1, i32 %2, i8* %3, i64 %4) {
%6 = alloca %struct.sockaddr_in
%7 = bitcast %struct.sockaddr_in* %6 to i8*
%8 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8*, i64 %4
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i32 %11, i32* %12
%13 = tail call i32 @htons(i32 %2)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0, i32 0
store i32 %1, i32* %15
%16 = load i32, i32* %0
%17 = call i64 @recv(i32 %16, i8** %10, i64 %4, i32 0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %5
%20 = call i32 (...) @getpid()
%21 = call i32 (i8*, i32, i32, ...) @ksft_print_msg(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 683)
br label %38
22: ; preds = %5
%23 = icmp eq i64 %17, %4
br i1 %23, label %24, label %27
24: ; preds = %22
%25 = call i64 @memcmp(i8* %3, i8** %10, i64 %4)
%26 = icmp eq i64 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %24, %22
%28 = call i32 (...) @getpid()
%29 = call i32 (i8*, i32, i32, ...) @ksft_print_msg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 687, i64 %17, i64 %4)
br label %38
30: ; preds = %24
%31 = getelementptr inbounds i32, i32* %0, i64 1
%32 = load i32, i32* %31
%33 = call i64 @sendto(i32 %32, i8* %3, i64 %4, i32 0, %struct.sockaddr* %8, i32 12)
%34 = icmp eq i64 %33, %4
br i1 %34, label %38, label %35
35: ; preds = %30
%36 = call i32 (...) @getpid()
%37 = call i32 (i8*, i32, i32, ...) @ksft_print_msg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %36, i32 696, i64 %33, i64 12)
br label %38
38: ; preds = %30, %35, %27, %19
%39 = phi i32 [ -1, %19 ], [ -1, %27 ], [ -1, %35 ], [ 0, %30 ]
ret i32 %39
}