#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_6__ TYPE_3__;
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct timeval {
  int member_0;
  int /*<<< orphan*/ member_1;
};
struct TYPE_4__ {
  void *s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct iphdr {
  int ihl;
  int version;
  int tot_len;
  int ttl;
  int /*<<< orphan*/ id;
  void *check;
  void *daddr;
  void *saddr;
  int /*<<< orphan*/ protocol;
  scalar_t__ frag_off;
  scalar_t__ tos;
};
struct TYPE_5__ {
  scalar_t__ sequence;
  int /*<<< orphan*/ id;
};
struct TYPE_6__ {
  TYPE_2__ echo;
};
struct icmphdr {
  void *checksum;
  TYPE_3__ un;
  scalar_t__ code;
  int /*<<< orphan*/ type;
};
typedef int /*<<< orphan*/ packet;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ connection;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ ICMP_ECHO;
int /*<<< orphan*/ IPPROTO_ICMP;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_HDRINCL;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
void *in_cksum(unsigned short *, int);
void *inet_addr(char *);
char *malloc(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ random();
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int icmp_check(char *src_addr, char *dst_addr) {
  struct iphdr *ip;
  struct iphdr *ip_reply;
  struct icmphdr *icmp;
  struct sockaddr_in connection;
  char *packet;
  char *buffer;
  int sockfd;
  int optval;
  int addrlen;
  int siz;
  int ping_result;
  printf("Source address: %s\n", src_addr);
  printf("Destination address: %s\n", dst_addr);
  packet = malloc(sizeof(struct iphdr) + sizeof(struct icmphdr));
  buffer = malloc(sizeof(struct iphdr) + sizeof(struct icmphdr));
  ip = (struct iphdr *)packet;
  icmp = (struct icmphdr *)(packet + sizeof(struct iphdr));
  ip->ihl = 5;
  ip->version = 4;
  ip->tos = 0;
  ip->tot_len = sizeof(struct iphdr) + sizeof(struct icmphdr);
  ip->id = htons(0);
  ip->frag_off = 0;
  ip->ttl = 1;
  ip->protocol = IPPROTO_ICMP;
  ip->saddr = inet_addr(src_addr);
  ip->daddr = inet_addr(dst_addr);
  ip->check = in_cksum((unsigned short *)ip, sizeof(struct iphdr));
  if ((sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) == -1) {
    free(packet);
    free(buffer);
    perror("socket");
    exit(EXIT_FAILURE);
    return 0;
  }
  connection.sin_family = AF_INET;
  connection.sin_addr.s_addr = inet_addr(dst_addr);
  setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &optval, sizeof(int));
  icmp->type = ICMP_ECHO;
  icmp->code = 0;
  icmp->un.echo.id = random();
  icmp->un.echo.sequence = 0;
  icmp->checksum = in_cksum((unsigned short *)icmp, sizeof(struct icmphdr));
  sendto(sockfd, packet, ip->tot_len, 0, (struct sockaddr *)&connection,
         sizeof(struct sockaddr));
  printf("Sent %d byte packet to %s\n", sizeof(packet), dst_addr);
  int rc;
  struct timeval timeout = {3, 0};
  fd_set read_set;
  memset(&read_set, 0, sizeof read_set);
  FD_SET(sockfd, &read_set);
  rc = select(sockfd + 1, &read_set, NULL, NULL, &timeout);
  if (rc == 0) {
    puts("Got no reply\n");
    ping_result = 0;
    return 0;
  } else if (rc < 0) {
    perror("Select");
    ping_result = 0;
  }
  addrlen = sizeof(connection);
  if ((siz = recvfrom(sockfd, buffer,
                      sizeof(struct iphdr) + sizeof(struct icmphdr), 0,
                      (struct sockaddr *)&connection, &addrlen)) == -1) {
    perror("recv");
    ping_result = 0;
  } else {
    printf("Received %d byte reply from %s:\n", siz, dst_addr);
    ip_reply = (struct iphdr *)buffer;
    printf("ID: %d\n", ntohs(ip_reply->id));
    printf("TTL: %d\n", ip_reply->ttl);
    ping_result = 1;
  }
  free(packet);
  free(buffer);
  close(sockfd);
  if (ping_result == 0) {
    return 0;
  } else {
    return 1;
  }
}


x86 assembly (clang, -O0):
<icmp_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x70,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    $0x70,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x48(%rbp),%rax
add    $0x48,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x5,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x4,0x4(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,0x40(%rax)
mov    -0x20(%rbp),%rax
movl   $0x70,0x8(%rax)
xor    %edi,%edi
call   1070 <htons@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,0x38(%rax)
mov    -0x20(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    0x2cd7(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x30(%rax)
mov    -0x10(%rbp),%rdi
call   10c0 <inet_addr@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    -0x18(%rbp),%rdi
call   10c0 <inet_addr@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x20(%rbp),%rdi
mov    $0x48,%esi
call   1060 <in_cksum@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
mov    0x2c8d(%rip),%rax
mov    (%rax),%esi
mov    0x2c74(%rip),%rax
mov    (%rax),%edx
call   1150 <socket@plt>
mov    %eax,-0x54(%rbp)
cmp    $0xffffffff,%eax
jne    1393 <icmp_check+0x163>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
lea    0xcad(%rip),%rdi
call   1120 <perror@plt>
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>
mov    0x2c46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   10c0 <inet_addr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x54(%rbp),%edi
mov    0x2c1a(%rip),%rax
mov    (%rax),%esi
mov    0x2c31(%rip),%rax
mov    (%rax),%edx
lea    -0x58(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
mov    0x2be1(%rip),%rax
mov    (%rax),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x20(%rax)
mov    -0x30(%rbp),%rax
movq   $0x0,0x18(%rax)
mov    $0x0,%al
call   10e0 <random@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x30(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x30(%rbp),%rdi
mov    $0x28,%esi
call   1060 <in_cksum@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x54(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edx
lea    -0x40(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   10a0 <sendto@plt>
mov    -0x18(%rbp),%rdx
lea    0xbea(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0xc3f(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    -0x74(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1090 <memset@plt>
mov    -0x54(%rbp),%edi
lea    -0x74(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    -0x54(%rbp),%edi
add    $0x1,%edi
lea    -0x74(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x70(%rbp),%r8
mov    %rcx,%rdx
call   10d0 <select@plt>
mov    %eax,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
jne    14c3 <icmp_check+0x293>
lea    0xba4(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x4(%rbp)
jmp    15b7 <icmp_check+0x387>
cmpl   $0x0,-0x68(%rbp)
jge    14e0 <icmp_check+0x2b0>
lea    0xb89(%rip),%rdi
call   1120 <perror@plt>
movl   $0x0,-0x64(%rbp)
jmp    14e5 <icmp_check+0x2b5>
movl   $0x10,-0x5c(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
lea    -0x40(%rbp),%r8
mov    $0x70,%edx
xor    %ecx,%ecx
lea    -0x5c(%rbp),%r9
call   1100 <recvfrom@plt>
mov    %eax,-0x60(%rbp)
cmp    $0xffffffff,%eax
jne    152b <icmp_check+0x2fb>
lea    0xb4a(%rip),%rdi
call   1120 <perror@plt>
movl   $0x0,-0x64(%rbp)
jmp    1580 <icmp_check+0x350>
mov    -0x60(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xb30(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%edi
call   1110 <ntohs@plt>
mov    %eax,%esi
lea    0xb2d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%esi
lea    0xb20(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x64(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x54(%rbp),%edi
call   10b0 <close@plt>
cmpl   $0x0,-0x64(%rbp)
jne    15b0 <icmp_check+0x380>
movl   $0x0,-0x4(%rbp)
jmp    15b7 <icmp_check+0x387>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<icmp_check>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0xdb5(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xdb8(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x70,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbx
mov    $0x70,%edi
call   10f0 <malloc@plt>
mov    %rax,%r13
movabs $0x400000005,%rax
mov    %rax,(%rbx)
movq   $0x0,0x40(%rbx)
movl   $0x70,0x8(%rbx)
xor    %edi,%edi
call   1070 <htons@plt>
mov    %eax,0x10(%rbx)
movq   $0x0,0x38(%rbx)
movl   $0x1,0xc(%rbx)
mov    0x2d0c(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x30(%rbx)
mov    %rbp,%rdi
call   10c0 <inet_addr@plt>
mov    %rax,0x28(%rbx)
mov    %r15,%rdi
call   10c0 <inet_addr@plt>
mov    %rax,0x20(%rbx)
mov    %rbx,%rdi
mov    $0x48,%esi
call   1060 <in_cksum@plt>
mov    %rax,0x18(%rbx)
mov    0x2cee(%rip),%r12
mov    (%r12),%edi
mov    0x2cdb(%rip),%rax
mov    (%rax),%esi
mov    (%r14),%edx
call   1150 <socket@plt>
cmp    $0xffffffff,%eax
je     14de <icmp_check+0x2ae>
mov    %eax,%r14d
mov    %rbx,%rbp
add    $0x48,%rbp
mov    (%r12),%eax
mov    %eax,0x18(%rsp)
mov    %r15,%rdi
call   10c0 <inet_addr@plt>
mov    %rax,0x10(%rsp)
mov    0x2c9a(%rip),%rax
mov    (%rax),%esi
mov    0x2cb1(%rip),%rax
mov    (%rax),%edx
lea    0x24(%rsp),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
mov    0x2c5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x68(%rbx)
movq   $0x0,0x60(%rbx)
xor    %r12d,%r12d
xor    %eax,%eax
call   10e0 <random@plt>
mov    %eax,0x58(%rbx)
movq   $0x0,0x50(%rbx)
mov    %rbp,%rdi
mov    $0x28,%esi
call   1060 <in_cksum@plt>
mov    %rax,0x48(%rbx)
mov    0x8(%rbx),%edx
lea    0x10(%rsp),%r8
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
mov    $0x4,%r9d
call   10a0 <sendto@plt>
lea    0xc84(%rip),%rdi
mov    $0x8,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
movq   $0x3,0x8(%rsp)
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1090 <memset@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1140 <FD_SET@plt>
mov    %r14d,%edi
add    $0x1,%edi
lea    0x8(%rsp),%r8
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   10d0 <select@plt>
test   %eax,%eax
je     14a1 <icmp_check+0x271>
js     14bf <icmp_check+0x28f>
movl   $0x10,0x4(%rsp)
lea    0x10(%rsp),%r8
lea    0x4(%rsp),%r9
mov    %r14d,%edi
mov    %r13,%rbp
mov    %r13,%rsi
mov    $0x70,%edx
xor    %ecx,%ecx
call   1100 <recvfrom@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
je     14d0 <icmp_check+0x2a0>
lea    0xc23(%rip),%rdi
mov    %r13d,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x10(%rbp),%edi
call   1110 <ntohs@plt>
lea    0xc28(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0xc(%rbp),%esi
lea    0xc1d(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %r12d,%r12d
cmp    $0xffffffff,%r13d
setne  %r12b
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
call   10b0 <close@plt>
jmp    14ad <icmp_check+0x27d>
lea    0xba7(%rip),%rdi
call   1040 <puts@plt>
mov    %r12d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb97(%rip),%rdi
call   1120 <perror@plt>
jmp    140c <icmp_check+0x1dc>
lea    0xb8d(%rip),%rdi
call   1120 <perror@plt>
jmp    147c <icmp_check+0x24c>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
lea    0xb38(%rip),%rdi
call   1120 <perror@plt>
mov    0x2aaf(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.iphdr = type { i32, i32, i32, i32, i32, i8*, i8*, i8*, i32, i64, i64 }
%struct.icmphdr = type { i8*, %struct.TYPE_6__, i64, i32 }
%struct.TYPE_6__ = type { %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i64, i32 }
%struct.sockaddr_in = type { %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { i8* }
%struct.sockaddr = type { i32 }
@.str = [20 x i8] c"Source address: %s\0A\00"
@.str.1 = [25 x i8] c"Destination address: %s\0A\00"
@IPPROTO_ICMP = global i32 0
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@IPPROTO_IP = global i32 0
@IP_HDRINCL = global i32 0
@ICMP_ECHO = global i32 0
@.str.3 = [27 x i8] c"Sent %d byte packet to %s\0A\00"
@__const.icmp_check.timeout = %struct.timeval { i32 3, i32 0 }
@.str.4 = [14 x i8] c"Got no reply\0A\00"
@.str.5 = [7 x i8] c"Select\00"
@.str.6 = [5 x i8] c"recv\00"
@.str.7 = [33 x i8] c"Received %d byte reply from %s:\0A\00"
@.str.8 = [8 x i8] c"ID: %d\0A\00"
@.str.9 = [9 x i8] c"TTL: %d\0A\00"
define i32 @icmp_check(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.iphdr*
%7 = alloca %struct.iphdr*
%8 = alloca %struct.icmphdr*
%9 = alloca %struct.sockaddr_in
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca %struct.timeval
%19 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%20 = load i8*, i8** %4
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %5
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i8* @malloc(i32 112)
store i8* %24, i8** %10
%25 = call i8* @malloc(i32 112)
store i8* %25, i8** %11
%26 = load i8*, i8** %10
%27 = bitcast i8* %26 to %struct.iphdr*
store %struct.iphdr* %27, %struct.iphdr** %6
%28 = load i8*, i8** %10
%29 = getelementptr inbounds i8, i8* %28, i64 72
%30 = bitcast i8* %29 to %struct.icmphdr*
store %struct.icmphdr* %30, %struct.icmphdr** %8
%31 = load %struct.iphdr*, %struct.iphdr** %6
%32 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %31, i32 0, i32 0
store i32 5, i32* %32
%33 = load %struct.iphdr*, %struct.iphdr** %6
%34 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %33, i32 0, i32 1
store i32 4, i32* %34
%35 = load %struct.iphdr*, %struct.iphdr** %6
%36 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %35, i32 0, i32 10
store i64 0, i64* %36
%37 = load %struct.iphdr*, %struct.iphdr** %6
%38 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %37, i32 0, i32 2
store i32 112, i32* %38
%39 = call i32 @htons(i32 0)
%40 = load %struct.iphdr*, %struct.iphdr** %6
%41 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %40, i32 0, i32 4
store i32 %39, i32* %41
%42 = load %struct.iphdr*, %struct.iphdr** %6
%43 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %42, i32 0, i32 9
store i64 0, i64* %43
%44 = load %struct.iphdr*, %struct.iphdr** %6
%45 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %44, i32 0, i32 3
store i32 1, i32* %45
%46 = load i32, i32* @IPPROTO_ICMP
%47 = load %struct.iphdr*, %struct.iphdr** %6
%48 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %47, i32 0, i32 8
store i32 %46, i32* %48
%49 = load i8*, i8** %4
%50 = call i8* @inet_addr(i8* %49)
%51 = load %struct.iphdr*, %struct.iphdr** %6
%52 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %51, i32 0, i32 7
store i8* %50, i8** %52
%53 = load i8*, i8** %5
%54 = call i8* @inet_addr(i8* %53)
%55 = load %struct.iphdr*, %struct.iphdr** %6
%56 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %55, i32 0, i32 6
store i8* %54, i8** %56
%57 = load %struct.iphdr*, %struct.iphdr** %6
%58 = bitcast %struct.iphdr* %57 to i16*
%59 = call i8* @in_cksum(i16* %58, i32 72)
%60 = load %struct.iphdr*, %struct.iphdr** %6
%61 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %60, i32 0, i32 5
store i8* %59, i8** %61
%62 = load i32, i32* @AF_INET
%63 = load i32, i32* @SOCK_RAW
%64 = load i32, i32* @IPPROTO_ICMP
%65 = call i32 @socket(i32 %62, i32 %63, i32 %64)
store i32 %65, i32* %12
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %75
67: ; preds = %2
%68 = load i8*, i8** %10
%69 = call i32 @free(i8* %68)
%70 = load i8*, i8** %11
%71 = call i32 @free(i8* %70)
%72 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %2
%76 = load i32, i32* @AF_INET
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %76, i32* %77
%78 = load i8*, i8** %5
%79 = call i8* @inet_addr(i8* %78)
%80 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%81 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %80, i32 0, i32 0
store i8* %79, i8** %81
%82 = load i32, i32* %12
%83 = load i32, i32* @IPPROTO_IP
%84 = load i32, i32* @IP_HDRINCL
%85 = call i32 @setsockopt(i32 %82, i32 %83, i32 %84, i32* %13, i32 4)
%86 = load i32, i32* @ICMP_ECHO
%87 = load %struct.icmphdr*, %struct.icmphdr** %8
%88 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %87, i32 0, i32 3
store i32 %86, i32* %88
%89 = load %struct.icmphdr*, %struct.icmphdr** %8
%90 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %89, i32 0, i32 2
store i64 0, i64* %90
%91 = call i32 (...) @random()
%92 = load %struct.icmphdr*, %struct.icmphdr** %8
%93 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %92, i32 0, i32 1
%94 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %93, i32 0, i32 0
%95 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %94, i32 0, i32 1
store i32 %91, i32* %95
%96 = load %struct.icmphdr*, %struct.icmphdr** %8
%97 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %96, i32 0, i32 1
%98 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %97, i32 0, i32 0
%99 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %98, i32 0, i32 0
store i64 0, i64* %99
%100 = load %struct.icmphdr*, %struct.icmphdr** %8
%101 = bitcast %struct.icmphdr* %100 to i16*
%102 = call i8* @in_cksum(i16* %101, i32 40)
%103 = load %struct.icmphdr*, %struct.icmphdr** %8
%104 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %103, i32 0, i32 0
store i8* %102, i8** %104
%105 = load i32, i32* %12
%106 = load i8*, i8** %10
%107 = load %struct.iphdr*, %struct.iphdr** %6
%108 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %107, i32 0, i32 2
%109 = load i32, i32* %108
%110 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%111 = call i32 @sendto(i32 %105, i8* %106, i32 %109, i32 0, %struct.sockaddr* %110, i32 4)
%112 = load i8*, i8** %5
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i64 8, i8* %112)
%114 = bitcast %struct.timeval* %18 to i8*
%115 = call i32 @memset(i32* %19, i32 0, i32 4)
%116 = load i32, i32* %12
%117 = call i32 @FD_SET(i32 %116, i32* %19)
%118 = load i32, i32* %12
%119 = add nsw i32 %118, 1
%120 = call i32 @select(i32 %119, i32* %19, i32* null, i32* null, %struct.timeval* %18)
store i32 %120, i32* %17
%121 = load i32, i32* %17
%122 = icmp eq i32 %121, 0
br i1 %122, label %123, label %125
123: ; preds = %75
%124 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %16
store i32 0, i32* %3
br label %165
125: ; preds = %75
%126 = load i32, i32* %17
%127 = icmp slt i32 %126, 0
br i1 %127, label %128, label %130
128: ; preds = %125
%129 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %16
br label %130
130: ; preds = %128, %125
br label %131
131: ; preds = %130
store i32 16, i32* %14
%132 = load i32, i32* %12
%133 = load i8*, i8** %11
%134 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%135 = call i32 @recvfrom(i32 %132, i8* %133, i32 112, i32 0, %struct.sockaddr* %134, i32* %14)
store i32 %135, i32* %15
%136 = icmp eq i32 %135, -1
br i1 %136, label %137, label %139
137: ; preds = %131
%138 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %16
br label %154
139: ; preds = %131
%140 = load i32, i32* %15
%141 = load i8*, i8** %5
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 %140, i8* %141)
%143 = load i8*, i8** %11
%144 = bitcast i8* %143 to %struct.iphdr*
store %struct.iphdr* %144, %struct.iphdr** %7
%145 = load %struct.iphdr*, %struct.iphdr** %7
%146 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %145, i32 0, i32 4
%147 = load i32, i32* %146
%148 = call i32 @ntohs(i32 %147)
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %148)
%150 = load %struct.iphdr*, %struct.iphdr** %7
%151 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %150, i32 0, i32 3
%152 = load i32, i32* %151
%153 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 %152)
store i32 1, i32* %16
br label %154
154: ; preds = %139, %137
%155 = load i8*, i8** %10
%156 = call i32 @free(i8* %155)
%157 = load i8*, i8** %11
%158 = call i32 @free(i8* %157)
%159 = load i32, i32* %12
%160 = call i32 @close(i32 %159)
%161 = load i32, i32* %16
%162 = icmp eq i32 %161, 0
br i1 %162, label %163, label %164
163: ; preds = %154
store i32 0, i32* %3
br label %165
164: ; preds = %154
store i32 1, i32* %3
br label %165
165: ; preds = %164, %163, %123
%166 = load i32, i32* %3
ret i32 %166
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { i8* }
%struct.iphdr = type { i32, i32, i32, i32, i32, i8*, i8*, i8*, i32, i64, i64 }
%struct.timeval = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [20 x i8] c"Source address: %s\0A\00"
@.str.1 = [25 x i8] c"Destination address: %s\0A\00"
@IPPROTO_ICMP = global i32 0
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@IPPROTO_IP = global i32 0
@IP_HDRINCL = global i32 0
@ICMP_ECHO = global i32 0
@.str.3 = [27 x i8] c"Sent %d byte packet to %s\0A\00"
@.str.4 = [14 x i8] c"Got no reply\0A\00"
@.str.5 = [7 x i8] c"Select\00"
@.str.6 = [5 x i8] c"recv\00"
@.str.7 = [33 x i8] c"Received %d byte reply from %s:\0A\00"
@.str.8 = [8 x i8] c"ID: %d\0A\00"
@.str.9 = [9 x i8] c"TTL: %d\0A\00"
define i32 @icmp_check(i8* %0, i8* %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%13 = tail call dereferenceable_or_null(112) i8* @malloc(i32 112)
%14 = tail call dereferenceable_or_null(112) i8* @malloc(i32 112)
%15 = bitcast i8* %13 to %struct.iphdr*
%16 = getelementptr inbounds i8, i8* %13, i64 72
%17 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %15, i64 0, i32 0
store i32 5, i32* %17
%18 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %15, i64 0, i32 1
store i32 4, i32* %18
%19 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %15, i64 0, i32 10
store i64 0, i64* %19
%20 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %15, i64 0, i32 2
store i32 112, i32* %20
%21 = tail call i32 @htons(i32 0)
%22 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %15, i64 0, i32 4
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %15, i64 0, i32 9
store i64 0, i64* %23
%24 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %15, i64 0, i32 3
store i32 1, i32* %24
%25 = load i32, i32* @IPPROTO_ICMP
%26 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %15, i64 0, i32 8
store i32 %25, i32* %26
%27 = tail call i8* @inet_addr(i8* %0)
%28 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %15, i64 0, i32 7
store i8* %27, i8** %28
%29 = tail call i8* @inet_addr(i8* %1)
%30 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %15, i64 0, i32 6
store i8* %29, i8** %30
%31 = bitcast i8* %13 to i16*
%32 = tail call i8* @in_cksum(i16* %31, i32 72)
%33 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %15, i64 0, i32 5
store i8* %32, i8** %33
%34 = load i32, i32* @AF_INET
%35 = load i32, i32* @SOCK_RAW
%36 = load i32, i32* @IPPROTO_ICMP
%37 = tail call i32 @socket(i32 %34, i32 %35, i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %45
39: ; preds = %2
%40 = tail call i32 @free(i8* %13)
%41 = tail call i32 @free(i8* %14)
%42 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = tail call i32 @exit(i32 %43)
unreachable
45: ; preds = %2
%46 = bitcast i64* %6 to %struct.timeval*
%47 = load i32, i32* @AF_INET
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %47, i32* %48
%49 = tail call i8* @inet_addr(i8* %1)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i8* %49, i8** %50
%51 = load i32, i32* @IPPROTO_IP
%52 = load i32, i32* @IP_HDRINCL
%53 = call i32 @setsockopt(i32 %37, i32 %51, i32 %52, i32* %4, i32 4)
%54 = load i32, i32* @ICMP_ECHO
%55 = getelementptr inbounds i8, i8* %13, i64 104
%56 = bitcast i8* %55 to i32*
store i32 %54, i32* %56
%57 = getelementptr inbounds i8, i8* %13, i64 96
%58 = bitcast i8* %57 to i64*
store i64 0, i64* %58
%59 = call i32 (...) @random()
%60 = getelementptr inbounds i8, i8* %13, i64 80
%61 = getelementptr inbounds i8, i8* %13, i64 88
%62 = bitcast i8* %61 to i32*
store i32 %59, i32* %62
%63 = bitcast i8* %60 to i64*
store i64 0, i64* %63
%64 = bitcast i8* %16 to i16*
%65 = call i8* @in_cksum(i16* %64, i32 40)
%66 = bitcast i8* %16 to i8**
store i8* %65, i8** %66
%67 = load i32, i32* %20
%68 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%69 = call i32 @sendto(i32 %37, i8* %13, i32 %67, i32 0, %struct.sockaddr* %68, i32 4)
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i64 8, i8* %1)
%71 = bitcast i64* %6 to i8*
store i64 3, i64* %6
%72 = bitcast i32* %7 to i8*
%73 = call i32 @memset(i32* %7, i32 0, i32 4)
%74 = call i32 @FD_SET(i32 %37, i32* %7)
%75 = add nuw nsw i32 %37, 1
%76 = call i32 @select(i32 %75, i32* %7, i32* null, i32* null, %struct.timeval* %46)
%77 = icmp eq i32 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %45
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %105
80: ; preds = %45
%81 = icmp slt i32 %76, 0
br i1 %81, label %82, label %84
82: ; preds = %80
%83 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %84
84: ; preds = %80, %82
store i32 16, i32* %5
%85 = call i32 @recvfrom(i32 %37, i8* %14, i32 112, i32 0, %struct.sockaddr* %68, i32* %5)
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %89
87: ; preds = %84
%88 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %99
89: ; preds = %84
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 %85, i8* %1)
%91 = bitcast i8* %14 to %struct.iphdr*
%92 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %91, i64 0, i32 4
%93 = load i32, i32* %92
%94 = call i32 @ntohs(i32 %93)
%95 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %94)
%96 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %91, i64 0, i32 3
%97 = load i32, i32* %96
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 %97)
br label %99
99: ; preds = %89, %87
%100 = call i32 @free(i8* %13)
%101 = call i32 @free(i8* %14)
%102 = call i32 @close(i32 %37)
%103 = xor i1 %86, true
%104 = zext i1 %103 to i32
br label %105
105: ; preds = %99, %78
%106 = phi i32 [ 0, %78 ], [ %104, %99 ]
ret i32 %106
}