#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 pollfd {
  int fd;
  scalar_t__ revents;
  int /*<<< orphan*/ events;
};
struct msghdr {
  int msg_iovlen;
  char *msg_control;
  int msg_controllen;
  struct iovec *msg_iov;
  scalar_t__ msg_namelen;
  int /*<<< orphan*/ *msg_name;
};
struct iovec {
  int iov_len;
  char *iov_base;
};
typedef int /*<<< orphan*/ msg;
typedef int /*<<< orphan*/ ans_data;

/* Variables and functions */
int /*<<< orphan*/ MSG_DONTWAIT;
int /*<<< orphan*/ POLLIN;
int getopt(int, char **, char *);
int icmp_socket(char *);
int /*<<< orphan*/ memset(struct msghdr *, int /*<<< orphan*/, int);
char *optarg;
int /*<<< orphan*/ parse_reply(struct msghdr *, int);
int /*<<< orphan*/ perror(char *);
int poll(struct pollfd *, int, int);
int recvmsg(int, struct msghdr *, int /*<<< orphan*/);
int send_ra_solicit(int, unsigned char *);
char *strrchr(char *, char);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  char *prgName = NULL;
  int c;
  char *iface = NULL;
  if ((prgName = strrchr(argv[0], '/')))
    prgName++;
  else
    prgName = argv[0];
  while ((c = getopt(argc, argv, "i:h")) > 0) {
    switch (c) {
    case 'i':
      iface = optarg;
      break;
    case 'h':
      usage(prgName);
      return 1;
      break;
    }
  }
  if (iface == NULL) {
    usage(prgName);
    return 1;
  }
  int fd = icmp_socket(iface);
  if (fd == -1)
    return 1;
  unsigned char buf[2048];
  if ((c = send_ra_solicit(fd, buf)) < 0)
    return 1;
  struct pollfd pollfd;
  pollfd.fd = fd;
  pollfd.events = POLLIN;
  pollfd.revents = 0;
  int rp = poll(&pollfd, 1, 2000);
  if (rp > 0) {
    char ans_data[4096];
    struct iovec iov;
    struct msghdr msg;
    int cc;
    iov.iov_len = sizeof(ans_data);
    iov.iov_base = ans_data;
    memset(&msg, 0, sizeof(msg));
    msg.msg_name = NULL;
    msg.msg_namelen = 0;
    msg.msg_iov = &iov;
    msg.msg_iovlen = 1;
    msg.msg_control = ans_data;
    msg.msg_controllen = sizeof(ans_data);
    cc = recvmsg(fd, &msg, MSG_DONTWAIT);
    if (cc < 0) {
      perror("recvmsg:");
      return 1;
    } else {
      parse_reply(&msg, cc);
    }
  } else {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x18a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11f9 <main+0x59>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1204 <main+0x64>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1209 <main+0x69>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xde9(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    1280 <main+0xe0>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x1898(%rbp)
sub    $0x68,%eax
je     1266 <main+0xc6>
jmp    123f <main+0x9f>
mov    -0x1898(%rbp),%eax
sub    $0x69,%eax
jne    127b <main+0xdb>
jmp    1253 <main+0xb3>
mov    0x2d9e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    127b <main+0xdb>
mov    -0x18(%rbp),%rdi
call   1090 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1413 <main+0x273>
jmp    1209 <main+0x69>
cmpq   $0x0,-0x28(%rbp)
jne    12a0 <main+0x100>
mov    -0x18(%rbp),%rdi
call   1090 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1413 <main+0x273>
mov    -0x28(%rbp),%rdi
call   1050 <icmp_socket@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    12c2 <main+0x122>
movl   $0x1,-0x4(%rbp)
jmp    1413 <main+0x273>
mov    -0x2c(%rbp),%edi
lea    -0x830(%rbp),%rsi
call   1070 <send_ra_solicit@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    12e9 <main+0x149>
movl   $0x1,-0x4(%rbp)
jmp    1413 <main+0x273>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x848(%rbp)
mov    0x2ce7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x838(%rbp)
movq   $0x0,-0x840(%rbp)
lea    -0x848(%rbp),%rdi
mov    $0x1,%esi
mov    $0x7d0,%edx
call   10a0 <poll@plt>
mov    %eax,-0x84c(%rbp)
cmpl   $0x0,-0x84c(%rbp)
jle    1400 <main+0x260>
movl   $0x1000,-0x1860(%rbp)
lea    -0x1850(%rbp),%rax
mov    %rax,-0x1858(%rbp)
lea    -0x1890(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
movq   $0x0,-0x1868(%rbp)
movq   $0x0,-0x1870(%rbp)
lea    -0x1860(%rbp),%rax
mov    %rax,-0x1878(%rbp)
movl   $0x1,-0x1890(%rbp)
lea    -0x1850(%rbp),%rax
mov    %rax,-0x1888(%rbp)
movl   $0x1000,-0x1880(%rbp)
mov    -0x2c(%rbp),%edi
mov    0x2c20(%rip),%rax
mov    (%rax),%edx
lea    -0x1890(%rbp),%rsi
call   1080 <recvmsg@plt>
mov    %eax,-0x1894(%rbp)
cmpl   $0x0,-0x1894(%rbp)
jge    13e9 <main+0x249>
lea    0xc2c(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1413 <main+0x273>
mov    -0x1894(%rbp),%esi
lea    -0x1890(%rbp),%rdi
call   1060 <parse_reply@plt>
jmp    140c <main+0x26c>
movl   $0x1,-0x4(%rbp)
jmp    1413 <main+0x273>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x18a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1868,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    (%rsi),%r15
mov    %r15,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
lea    0x1(%rax),%r14
test   %rax,%rax
cmove  %r15,%r14
lea    0xe28(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   10c0 <getopt@plt>
test   %eax,%eax
jle    1306 <main+0x166>
xor    %r15d,%r15d
mov    0x2e04(%rip),%r13
lea    0xe05(%rip),%r12
jmp    1215 <main+0x75>
nopl   (%rax)
mov    0x0(%r13),%r15
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   10c0 <getopt@plt>
test   %eax,%eax
jle    1224 <main+0x84>
cmp    $0x69,%eax
je     1200 <main+0x60>
cmp    $0x68,%eax
jne    1204 <main+0x64>
jmp    1306 <main+0x166>
test   %r15,%r15
je     1306 <main+0x166>
mov    %r15,%rdi
call   1050 <icmp_socket@plt>
cmp    $0xffffffff,%eax
je     130e <main+0x16e>
mov    %eax,%ebp
lea    0x60(%rsp),%rsi
mov    %eax,%edi
call   1070 <send_ra_solicit@plt>
test   %eax,%eax
js     130e <main+0x16e>
mov    %ebp,0x18(%rsp)
mov    0x2d81(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
movq   $0x0,0x20(%rsp)
lea    0x18(%rsp),%rdi
mov    $0x1,%ebx
mov    $0x1,%esi
mov    $0x7d0,%edx
call   10a0 <poll@plt>
test   %eax,%eax
jle    1313 <main+0x173>
movl   $0x1000,0x8(%rsp)
lea    0x860(%rsp),%r15
mov    %r15,0x10(%rsp)
lea    0x30(%rsp),%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x50(%rsp)
lea    0x8(%rsp),%rax
mov    %rax,0x48(%rsp)
movl   $0x1,0x30(%rsp)
mov    %r15,0x38(%rsp)
movl   $0x1000,0x40(%rsp)
mov    0x2ce8(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %r14,%rsi
call   1080 <recvmsg@plt>
test   %eax,%eax
js     1327 <main+0x187>
lea    0x30(%rsp),%rdi
mov    %eax,%esi
call   1060 <parse_reply@plt>
jmp    1313 <main+0x173>
mov    %r14,%rdi
call   1090 <usage@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x1868,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcd6(%rip),%rdi
call   10b0 <perror@plt>
jmp    130e <main+0x16e>

LLVM IR (-O0):
%struct.pollfd = type { i32, i64, i32 }
%struct.iovec = type { i32, i8* }
%struct.msghdr = type { i32, i8*, i32, %struct.iovec*, i64, i32* }
@.str = [4 x i8] c"i:h\00"
@optarg = global i8* null
@POLLIN = global i32 0
@MSG_DONTWAIT = global i32 0
@.str.1 = [9 x i8] c"recvmsg:\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [2048 x i8]
%11 = alloca %struct.pollfd
%12 = alloca i32
%13 = alloca [4096 x i8]
%14 = alloca %struct.iovec
%15 = alloca %struct.msghdr
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i8* null, i8** %8
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i8* @strrchr(i8* %19, i8 signext 47)
store i8* %20, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %6
br label %29
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
store i8* %28, i8** %6
br label %29
29: ; preds = %25, %22
br label %30
30: ; preds = %42, %29
%31 = load i32, i32* %4
%32 = load i8**, i8*** %5
%33 = call i32 @getopt(i32 %31, i8** %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %33, i32* %7
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %43
35: ; preds = %30
%36 = load i32, i32* %7
switch i32 %36, label %42 [
i32 105, label %37
i32 104, label %39
]
37: ; preds = %35
%38 = load i8*, i8** @optarg
store i8* %38, i8** %8
br label %42
39: ; preds = %35
%40 = load i8*, i8** %6
%41 = call i32 @usage(i8* %40)
store i32 1, i32* %3
br label %95
42: ; preds = %35, %37
br label %30
43: ; preds = %30
%44 = load i8*, i8** %8
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i8*, i8** %6
%48 = call i32 @usage(i8* %47)
store i32 1, i32* %3
br label %95
49: ; preds = %43
%50 = load i8*, i8** %8
%51 = call i32 @icmp_socket(i8* %50)
store i32 %51, i32* %9
%52 = load i32, i32* %9
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %55
54: ; preds = %49
store i32 1, i32* %3
br label %95
55: ; preds = %49
%56 = load i32, i32* %9
%57 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%58 = call i32 @send_ra_solicit(i32 %56, i8* %57)
store i32 %58, i32* %7
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %55
store i32 1, i32* %3
br label %95
61: ; preds = %55
%62 = load i32, i32* %9
%63 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %11, i32 0, i32 0
store i32 %62, i32* %63
%64 = load i32, i32* @POLLIN
%65 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %11, i32 0, i32 2
store i32 %64, i32* %65
%66 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %11, i32 0, i32 1
store i64 0, i64* %66
%67 = call i32 @poll(%struct.pollfd* %11, i32 1, i32 2000)
store i32 %67, i32* %12
%68 = load i32, i32* %12
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %93
70: ; preds = %61
%71 = getelementptr inbounds %struct.iovec, %struct.iovec* %14, i32 0, i32 0
store i32 4096, i32* %71
%72 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%73 = getelementptr inbounds %struct.iovec, %struct.iovec* %14, i32 0, i32 1
store i8* %72, i8** %73
%74 = call i32 @memset(%struct.msghdr* %15, i32 0, i32 48)
%75 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 5
store i32* null, i32** %75
%76 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 4
store i64 0, i64* %76
%77 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 3
store %struct.iovec* %14, %struct.iovec** %77
%78 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 0
store i32 1, i32* %78
%79 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%80 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 1
store i8* %79, i8** %80
%81 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 2
store i32 4096, i32* %81
%82 = load i32, i32* %9
%83 = load i32, i32* @MSG_DONTWAIT
%84 = call i32 @recvmsg(i32 %82, %struct.msghdr* %15, i32 %83)
store i32 %84, i32* %16
%85 = load i32, i32* %16
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %70
%88 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %95
89: ; preds = %70
%90 = load i32, i32* %16
%91 = call i32 @parse_reply(%struct.msghdr* %15, i32 %90)
br label %92
92: ; preds = %89
br label %94
93: ; preds = %61
store i32 1, i32* %3
br label %95
94: ; preds = %92
store i32 0, i32* %3
br label %95
95: ; preds = %94, %93, %87, %60, %54, %46, %39
%96 = load i32, i32* %3
ret i32 %96
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i64, i32 }
%struct.iovec = type { i32, i8* }
%struct.msghdr = type { i32, i8*, i32, %struct.iovec*, i64, i32* }
@.str = [4 x i8] c"i:h\00"
@optarg = global i8* null
@POLLIN = global i32 0
@MSG_DONTWAIT = global i32 0
@.str.1 = [9 x i8] c"recvmsg:\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [2048 x i8]
%4 = alloca %struct.pollfd
%5 = alloca [4096 x i8]
%6 = alloca %struct.iovec
%7 = alloca %struct.msghdr
%8 = load i8*, i8** %1
%9 = tail call i8* @strrchr(i8* dereferenceable(1) %8, i8 signext 47)
%10 = icmp eq i8* %9, null
%11 = getelementptr inbounds i8, i8* %9, i64 1
%12 = select i1 %10, i8* %8, i8* %11
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %2, %22
%16 = phi i32 [ %24, %22 ], [ %13, %2 ]
%17 = phi i8* [ %23, %22 ], [ null, %2 ]
switch i32 %16, label %22 [
i32 105, label %18
i32 104, label %20
]
18: ; preds = %15
%19 = load i8*, i8** @optarg
br label %22
20: ; preds = %15
%21 = tail call i32 @usage(i8* %12)
br label %71
22: ; preds = %15, %18
%23 = phi i8* [ %17, %15 ], [ %19, %18 ]
%24 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%25 = icmp sgt i32 %24, 0
br i1 %25, label %15, label %26
26: ; preds = %22
%27 = icmp eq i8* %23, null
br i1 %27, label %28, label %30
28: ; preds = %2, %26
%29 = tail call i32 @usage(i8* %12)
br label %71
30: ; preds = %26
%31 = tail call i32 @icmp_socket(i8* %23)
%32 = icmp eq i32 %31, -1
br i1 %32, label %71, label %33
33: ; preds = %30
%34 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%35 = call i32 @send_ra_solicit(i32 %31, i8* %34)
%36 = icmp slt i32 %35, 0
br i1 %36, label %69, label %37
37: ; preds = %33
%38 = bitcast %struct.pollfd* %4 to i8*
%39 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i64 0, i32 0
store i32 %31, i32* %39
%40 = load i32, i32* @POLLIN
%41 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i64 0, i32 2
store i32 %40, i32* %41
%42 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i64 0, i32 1
store i64 0, i64* %42
%43 = call i32 @poll(%struct.pollfd* %4, i32 1, i32 2000)
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %67
45: ; preds = %37
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%47 = bitcast %struct.iovec* %6 to i8*
%48 = bitcast %struct.msghdr* %7 to i8*
%49 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i64 0, i32 0
store i32 4096, i32* %49
%50 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i64 0, i32 1
store i8* %46, i8** %50
%51 = call i32 @memset(%struct.msghdr* %7, i32 0, i32 48)
%52 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i64 0, i32 4
%53 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i64 0, i32 3
%54 = bitcast i64* %52 to i8*
store %struct.iovec* %6, %struct.iovec** %53
%55 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i64 0, i32 0
store i32 1, i32* %55
%56 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i64 0, i32 1
store i8* %46, i8** %56
%57 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i64 0, i32 2
store i32 4096, i32* %57
%58 = load i32, i32* @MSG_DONTWAIT
%59 = call i32 @recvmsg(i32 %31, %struct.msghdr* %7, i32 %58)
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %45
%62 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %65
63: ; preds = %45
%64 = call i32 @parse_reply(%struct.msghdr* %7, i32 %59)
br label %65
65: ; preds = %63, %61
%66 = phi i32 [ 0, %63 ], [ 1, %61 ]
br label %67
67: ; preds = %65, %37
%68 = phi i32 [ 1, %37 ], [ %66, %65 ]
br label %69
69: ; preds = %33, %67
%70 = phi i32 [ %68, %67 ], [ 1, %33 ]
br label %71
71: ; preds = %69, %30, %28, %20
%72 = phi i32 [ 1, %20 ], [ 1, %28 ], [ %70, %69 ], [ 1, %30 ]
ret i32 %72
}