#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr {
  int dummy;
};
struct iphdr {
  int protocol;
  int /*<<< orphan*/ daddr;
  int /*<<< orphan*/ saddr;
};
struct ifreq {
  int /*<<< orphan*/ ifr_name;
};
struct icmphdr {
  int /*<<< orphan*/ type;
};
typedef int /*<<< orphan*/ src_addr;
typedef int socklen_t;
typedef int /*<<< orphan*/ inpack;
typedef int /*<<< orphan*/ ifr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ ICMP_ECHOREPLY;
int /*<<< orphan*/ INET6_ADDRSTRLEN;
int /*<<< orphan*/ IPPROTO_IPIP;
int IP_MAXPACKET;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BINDTODEVICE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int getopt(int, char **, char *);
int /*<<< orphan*/ *inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                              int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
char *optarg;
scalar_t__ optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, int /*<<< orphan*/ *, int, int /*<<< orphan*/,
             struct sockaddr *, int *);
scalar_t__ sendto(int, int /*<<< orphan*/ *, int, int /*<<< orphan*/,
                  struct sockaddr *, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, void *, int);
int /*<<< orphan*/ snprintf(int /*<<< orphan*/, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int sd, ch;
  uint8_t *opt, *pkt;
  struct ifreq ifr;
  char *interface = NULL;
  bool debug = false;
  while ((ch = getopt(argc, argv,
                      "h?"
                      "I:"
                      "d")) != EOF) {
    switch (ch) {
    case 'I':
      interface = optarg;
      break;
    case 'd':
      debug = true;
      break;
    default:
      usage();
      break;
    }
  }
  argc -= optind;
  argv += optind;
  if (!interface)
    usage();
  if ((sd = socket(AF_INET6, SOCK_RAW, IPPROTO_IPIP)) < 0) {
    perror("Failed to get socket descriptor ");
    exit(EXIT_FAILURE);
  }
  memset(&ifr, 0, sizeof(ifr));
  snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", interface);
  if (setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) <
      0) {
    perror("SO_BINDTODEVICE failed");
    exit(EXIT_FAILURE);
  }
  if (debug)
    printf("Binding to interface %s\n", interface);
  while (1) {
    struct sockaddr_in6 src_addr;
    socklen_t addrlen = sizeof(src_addr);
    char source[INET6_ADDRSTRLEN + 1];
    int len;
    uint8_t inpack[IP_MAXPACKET];
    if ((len = recvfrom(sd, inpack, sizeof(inpack), 0,
                        (struct sockaddr *)&src_addr, &addrlen)) < 0) {
      perror("recvfrom failed ");
    }
    if (inet_ntop(AF_INET6, &src_addr.sin6_addr, source, INET6_ADDRSTRLEN) ==
        NULL) {
      perror("inet_ntop() failed.");
      exit(EXIT_FAILURE);
    }
    struct iphdr *ip = (struct iphdr *)inpack;
    uint32_t saddr;
    struct icmphdr *icmp;
    saddr = ip->saddr;
    ip->saddr = ip->daddr;
    ip->daddr = saddr;
    switch (ip->protocol) {
    case 1:
      if (debug)
        printf("ICMP Echo request from %s\n", source);
      icmp = (struct icmphdr *)&ip[1];
      icmp->type = ICMP_ECHOREPLY;
      break;
    default:
      fprintf(stderr, "Unsupported protocol %d", ip->protocol);
    }
    if (len = sendto(sd, inpack, len, 0, (struct sockaddr *)&src_addr,
                     addrlen) < 0) {
      perror("sendto failed ");
    }
  }
  close(sd);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdfa(%rip),%rdx
call   10d0 <getopt@plt>
mov    %eax,-0x18(%rbp)
mov    0x2dab(%rip),%rcx
cmp    (%rcx),%eax
je     1273 <main+0xa3>
mov    -0x18(%rbp),%eax
mov    %eax,-0x84(%rbp)
sub    $0x49,%eax
je     1248 <main+0x78>
jmp    1234 <main+0x64>
mov    -0x84(%rbp),%eax
sub    $0x64,%eax
je     125b <main+0x8b>
jmp    1267 <main+0x97>
mov    0x2da9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    126e <main+0x9e>
movl   $0x1,-0x3c(%rbp)
jmp    126e <main+0x9e>
mov    $0x0,%al
call   10b0 <usage@plt>
jmp    11f8 <main+0x28>
mov    0x2d3e(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12af <main+0xdf>
mov    $0x0,%al
call   10b0 <usage@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
mov    0x2d09(%rip),%rax
mov    (%rax),%esi
mov    0x2cd8(%rip),%rax
mov    (%rax),%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    12f5 <main+0x125>
lea    0xd24(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
mov    -0x30(%rbp),%edi
mov    -0x38(%rbp),%rcx
mov    $0x4,%esi
lea    0xd0f(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x14(%rbp),%edi
mov    0x2cb1(%rip),%rax
mov    (%rax),%esi
mov    0x2c58(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    1365 <main+0x195>
lea    0xcd8(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
cmpl   $0x0,-0x3c(%rbp)
je     137f <main+0x1af>
mov    -0x38(%rbp),%rsi
lea    0xcc7(%rip),%rdi
call   1050 <printf@plt>
jmp    1384 <main+0x1b4>
movl   $0x4,-0x44(%rbp)
mov    0x2c3e(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x98(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
mov    0x2c2c(%rip),%rax
mov    (%rax),%eax
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x90(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x68(%rbp)
mov    -0x14(%rbp),%edi
shl    $0x2,%rax
mov    %eax,%edx
lea    -0x40(%rbp),%r8
xor    %ecx,%ecx
lea    -0x44(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,-0x5c(%rbp)
cmp    $0x0,%eax
jge    1416 <main+0x246>
lea    0xc49(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x98(%rbp),%rdx
mov    0x2b8c(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
mov    0x2b9f(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    145c <main+0x28c>
lea    0xc22(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2b3b(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x90(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x70(%rbp),%rax
mov    0x4(%rax),%ecx
mov    %ecx,0x8(%rax)
mov    -0x74(%rbp),%ecx
mov    -0x70(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x70(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
jne    14d6 <main+0x306>
jmp    1499 <main+0x2c9>
cmpl   $0x0,-0x3c(%rbp)
je     14b6 <main+0x2e6>
mov    -0x98(%rbp),%rsi
lea    0xbce(%rip),%rdi
call   1050 <printf@plt>
mov    -0x70(%rbp),%rax
add    $0xc,%rax
mov    %rax,-0x80(%rbp)
mov    0x2ab7(%rip),%rax
mov    (%rax),%ecx
mov    -0x80(%rbp),%rax
mov    %ecx,(%rax)
jmp    14f1 <main+0x321>
mov    0x2abb(%rip),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%rax
mov    (%rax),%edx
lea    0xbae(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x90(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    -0x5c(%rbp),%edx
lea    -0x40(%rbp),%r8
mov    -0x44(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x5c(%rbp)
test   $0x1,%al
jne    152c <main+0x35c>
jmp    1538 <main+0x368>
lea    0xb7f(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
jmp    1384 <main+0x1b4>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe13(%rip),%rdx
call   10d0 <getopt@plt>
mov    0x2dc7(%rip),%r13
movl   $0x0,-0x2c(%rbp)
cmp    0x0(%r13),%eax
je     125e <main+0x8e>
lea    0xdf3(%rip),%r12
xor    %r15d,%r15d
movl   $0x0,-0x2c(%rbp)
jmp    123a <main+0x6a>
nopl   0x0(%rax)
xor    %eax,%eax
call   10b0 <usage@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r12,%rdx
call   10d0 <getopt@plt>
cmp    0x0(%r13),%eax
je     1259 <main+0x89>
cmp    $0x64,%eax
je     1250 <main+0x80>
cmp    $0x49,%eax
jne    1220 <main+0x50>
mov    0x2dad(%rip),%rax
mov    (%rax),%r15
jmp    1227 <main+0x57>
movl   $0x1,-0x2c(%rbp)
jmp    1227 <main+0x57>
test   %r15,%r15
jne    1268 <main+0x98>
xor    %r15d,%r15d
xor    %eax,%eax
call   10b0 <usage@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
mov    0x2d50(%rip),%rax
mov    (%rax),%esi
mov    0x2d27(%rip),%rax
mov    (%rax),%edx
call   10f0 <socket@plt>
test   %eax,%eax
jns    1298 <main+0xc8>
lea    0xd73(%rip),%rdi
jmp    1445 <main+0x275>
mov    %eax,%ebx
lea    -0x40(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
mov    -0x40(%rbp),%edi
lea    0xd70(%rip),%rdx
mov    $0x4,%esi
mov    %r15,%rcx
call   1060 <snprintf@plt>
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
mov    0x2cbc(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
jns    12f7 <main+0x127>
lea    0xd38(%rip),%rdi
jmp    1445 <main+0x275>
mov    %ebx,-0x30(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     130f <main+0x13f>
lea    0xd3a(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    0x2cba(%rip),%r14
lea    -0x50(%rbp),%rbx
jmp    135f <main+0x18f>
nopl   0x0(%rax)
mov    0x2c79(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x30(%rbp),%edi
mov    -0x48(%rbp),%r12
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%r9d
mov    %r13,%rsi
xor    %ecx,%ecx
mov    %r15,%rbx
mov    %r15,%r8
call   1080 <sendto@plt>
test   %rax,%rax
js     142d <main+0x25d>
mov    %r12,%rsp
mov    %rsp,-0x48(%rbp)
movl   $0x4,-0x38(%rbp)
mov    (%r14),%eax
add    $0x1,%eax
mov    %r14,%r15
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2c65(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r13
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r13
mov    %r13,%rsp
lea    0x0(,%rax,4),%edx
mov    -0x30(%rbp),%edi
mov    %r13,%rsi
xor    %ecx,%ecx
mov    %rbx,%r8
lea    -0x38(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,-0x34(%rbp)
test   %eax,%eax
js     141f <main+0x24f>
mov    0x2bed(%rip),%rax
mov    (%rax),%edi
mov    %r15,%r14
mov    (%r15),%ecx
mov    %rbx,%r15
mov    %rbx,%rsi
mov    %r12,%rdx
call   1030 <inet_ntop@plt>
test   %rax,%rax
je     143e <main+0x26e>
rolq   $0x20,0x4(%r13)
mov    0x0(%r13),%edx
cmp    $0x1,%edx
jne    1320 <main+0x150>
cmpl   $0x0,-0x2c(%rbp)
je     140d <main+0x23d>
lea    0xc7a(%rip),%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
mov    0x2b74(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%r13)
jmp    1335 <main+0x165>
lea    0xc34(%rip),%rdi
call   10c0 <perror@plt>
jmp    13c4 <main+0x1f4>
lea    0xc7e(%rip),%rdi
call   10c0 <perror@plt>
jmp    135c <main+0x18c>
lea    0xc26(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2b47(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.ifreq = type { i32 }
%struct.sockaddr_in6 = type { i32 }
%struct.iphdr = type { i32, i32, i32 }
%struct.icmphdr = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [6 x i8] c"h?I:d\00"
@EOF = global i32 0
@optarg = global i8* null
@optind = global i64 0
@AF_INET6 = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_IPIP = global i32 0
@.str.1 = [33 x i8] c"Failed to get socket descriptor \00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@SOL_SOCKET = global i32 0
@SO_BINDTODEVICE = global i32 0
@.str.3 = [23 x i8] c"SO_BINDTODEVICE failed\00"
@.str.4 = [25 x i8] c"Binding to interface %s\0A\00"
@INET6_ADDRSTRLEN = global i32 0
@IP_MAXPACKET = global i32 0
@.str.5 = [17 x i8] c"recvfrom failed \00"
@.str.6 = [20 x i8] c"inet_ntop() failed.\00"
@.str.7 = [27 x i8] c"ICMP Echo request from %s\0A\00"
@ICMP_ECHOREPLY = global i32 0
@stderr = global i32 0
@.str.8 = [24 x i8] c"Unsupported protocol %d\00"
@.str.9 = [15 x i8] c"sendto failed \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca %struct.ifreq
%11 = alloca i8*
%12 = alloca i32
%13 = alloca %struct.sockaddr_in6
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i32
%18 = alloca i64
%19 = alloca %struct.iphdr*
%20 = alloca i32
%21 = alloca %struct.icmphdr*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %11
store i32 0, i32* %12
br label %22
22: ; preds = %35, %2
%23 = load i32, i32* %4
%24 = load i8**, i8*** %5
%25 = call i32 @getopt(i32 %23, i8** %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %25, i32* %7
%26 = load i32, i32* @EOF
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %36
28: ; preds = %22
%29 = load i32, i32* %7
switch i32 %29, label %33 [
i32 73, label %30
i32 100, label %32
]
30: ; preds = %28
%31 = load i8*, i8** @optarg
store i8* %31, i8** %11
br label %35
32: ; preds = %28
store i32 1, i32* %12
br label %35
33: ; preds = %28
%34 = call i32 (...) @usage()
br label %35
35: ; preds = %33, %32, %30
br label %22
36: ; preds = %22
%37 = load i64, i64* @optind
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = sub nsw i64 %39, %37
%41 = trunc i64 %40 to i32
store i32 %41, i32* %4
%42 = load i64, i64* @optind
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 %42
store i8** %44, i8*** %5
%45 = load i8*, i8** %11
%46 = icmp ne i8* %45, null
br i1 %46, label %49, label %47
47: ; preds = %36
%48 = call i32 (...) @usage()
br label %49
49: ; preds = %47, %36
%50 = load i32, i32* @AF_INET6
%51 = load i32, i32* @SOCK_RAW
%52 = load i32, i32* @IPPROTO_IPIP
%53 = call i32 @socket(i32 %50, i32 %51, i32 %52)
store i32 %53, i32* %6
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %49
%56 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %49
%60 = call i32 @memset(%struct.ifreq* %10, i32 0, i32 4)
%61 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %10, i32 0, i32 0
%62 = load i32, i32* %61
%63 = load i8*, i8** %11
%64 = call i32 @snprintf(i32 %62, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %63)
%65 = load i32, i32* %6
%66 = load i32, i32* @SOL_SOCKET
%67 = load i32, i32* @SO_BINDTODEVICE
%68 = bitcast %struct.ifreq* %10 to i8*
%69 = call i64 @setsockopt(i32 %65, i32 %66, i32 %67, i8* %68, i32 4)
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %59
%72 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %59
%76 = load i32, i32* %12
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %75
%79 = load i8*, i8** %11
%80 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %79)
br label %81
81: ; preds = %78, %75
br label %82
82: ; preds = %81, %153
store i32 4, i32* %14
%83 = load i32, i32* @INET6_ADDRSTRLEN
%84 = add nsw i32 %83, 1
%85 = zext i32 %84 to i64
%86 = call i8* @llvm.stacksave()
store i8* %86, i8** %15
%87 = alloca i8, i64 %85
store i64 %85, i64* %16
%88 = load i32, i32* @IP_MAXPACKET
%89 = zext i32 %88 to i64
%90 = alloca i32, i64 %89
store i64 %89, i64* %18
%91 = load i32, i32* %6
%92 = mul nuw i64 4, %89
%93 = trunc i64 %92 to i32
%94 = bitcast %struct.sockaddr_in6* %13 to %struct.sockaddr*
%95 = call i32 @recvfrom(i32 %91, i32* %90, i32 %93, i32 0, %struct.sockaddr* %94, i32* %14)
store i32 %95, i32* %17
%96 = icmp slt i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %82
%98 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %99
99: ; preds = %97, %82
%100 = load i32, i32* @AF_INET6
%101 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %13, i32 0, i32 0
%102 = load i32, i32* @INET6_ADDRSTRLEN
%103 = call i32* @inet_ntop(i32 %100, i32* %101, i8* %87, i32 %102)
%104 = icmp eq i32* %103, null
br i1 %104, label %105, label %109
105: ; preds = %99
%106 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%107 = load i32, i32* @EXIT_FAILURE
%108 = call i32 @exit(i32 %107)
unreachable
109: ; preds = %99
%110 = bitcast i32* %90 to %struct.iphdr*
store %struct.iphdr* %110, %struct.iphdr** %19
%111 = load %struct.iphdr*, %struct.iphdr** %19
%112 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %111, i32 0, i32 2
%113 = load i32, i32* %112
store i32 %113, i32* %20
%114 = load %struct.iphdr*, %struct.iphdr** %19
%115 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %114, i32 0, i32 1
%116 = load i32, i32* %115
%117 = load %struct.iphdr*, %struct.iphdr** %19
%118 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %117, i32 0, i32 2
store i32 %116, i32* %118
%119 = load i32, i32* %20
%120 = load %struct.iphdr*, %struct.iphdr** %19
%121 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %120, i32 0, i32 1
store i32 %119, i32* %121
%122 = load %struct.iphdr*, %struct.iphdr** %19
%123 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %122, i32 0, i32 0
%124 = load i32, i32* %123
switch i32 %124, label %137 [
i32 1, label %125
]
125: ; preds = %109
%126 = load i32, i32* %12
%127 = icmp ne i32 %126, 0
br i1 %127, label %128, label %130
128: ; preds = %125
%129 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %87)
br label %130
130: ; preds = %128, %125
%131 = load %struct.iphdr*, %struct.iphdr** %19
%132 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %131, i64 1
%133 = bitcast %struct.iphdr* %132 to %struct.icmphdr*
store %struct.icmphdr* %133, %struct.icmphdr** %21
%134 = load i32, i32* @ICMP_ECHOREPLY
%135 = load %struct.icmphdr*, %struct.icmphdr** %21
%136 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %135, i32 0, i32 0
store i32 %134, i32* %136
br label %143
137: ; preds = %109
%138 = load i32, i32* @stderr
%139 = load %struct.iphdr*, %struct.iphdr** %19
%140 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %139, i32 0, i32 0
%141 = load i32, i32* %140
%142 = call i32 @fprintf(i32 %138, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i32 %141)
br label %143
143: ; preds = %137, %130
%144 = load i32, i32* %6
%145 = load i32, i32* %17
%146 = bitcast %struct.sockaddr_in6* %13 to %struct.sockaddr*
%147 = load i32, i32* %14
%148 = call i64 @sendto(i32 %144, i32* %90, i32 %145, i32 0, %struct.sockaddr* %146, i32 %147)
%149 = icmp slt i64 %148, 0
%150 = zext i1 %149 to i32
store i32 %150, i32* %17
br i1 %149, label %151, label %153
151: ; preds = %143
%152 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %153
153: ; preds = %151, %143
%154 = load i8*, i8** %15
br label %82
}

LLVM IR (-O2):
%struct.ifreq = type { i32 }
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [6 x i8] c"h?I:d\00"
@EOF = global i32 0
@optarg = global i8* null
@optind = global i64 0
@AF_INET6 = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_IPIP = global i32 0
@.str.1 = [33 x i8] c"Failed to get socket descriptor \00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@SOL_SOCKET = global i32 0
@SO_BINDTODEVICE = global i32 0
@.str.3 = [23 x i8] c"SO_BINDTODEVICE failed\00"
@.str.4 = [25 x i8] c"Binding to interface %s\0A\00"
@INET6_ADDRSTRLEN = global i32 0
@IP_MAXPACKET = global i32 0
@.str.5 = [17 x i8] c"recvfrom failed \00"
@.str.6 = [20 x i8] c"inet_ntop() failed.\00"
@.str.7 = [27 x i8] c"ICMP Echo request from %s\0A\00"
@ICMP_ECHOREPLY = global i32 0
@stderr = global i32 0
@.str.8 = [24 x i8] c"Unsupported protocol %d\00"
@.str.9 = [15 x i8] c"sendto failed \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.ifreq
%4 = alloca %struct.sockaddr_in6
%5 = alloca i32
%6 = bitcast %struct.ifreq* %3 to i8*
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %26, label %10
10: ; preds = %2, %18
%11 = phi i32 [ %21, %18 ], [ %7, %2 ]
%12 = phi i8* [ %20, %18 ], [ null, %2 ]
%13 = phi i32 [ %19, %18 ], [ 0, %2 ]
switch i32 %11, label %16 [
i32 73, label %14
i32 100, label %18
]
14: ; preds = %10
%15 = load i8*, i8** @optarg
br label %18
16: ; preds = %10
%17 = tail call i32 (...) @usage()
br label %18
18: ; preds = %10, %16, %14
%19 = phi i32 [ %13, %16 ], [ %13, %14 ], [ 1, %10 ]
%20 = phi i8* [ %12, %16 ], [ %15, %14 ], [ %12, %10 ]
%21 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %10
24: ; preds = %18
%25 = icmp eq i8* %20, null
br i1 %25, label %26, label %29
26: ; preds = %2, %24
%27 = phi i32 [ %19, %24 ], [ 0, %2 ]
%28 = tail call i32 (...) @usage()
br label %29
29: ; preds = %26, %24
%30 = phi i8* [ null, %26 ], [ %20, %24 ]
%31 = phi i32 [ %27, %26 ], [ %19, %24 ]
%32 = load i32, i32* @AF_INET6
%33 = load i32, i32* @SOCK_RAW
%34 = load i32, i32* @IPPROTO_IPIP
%35 = tail call i32 @socket(i32 %32, i32 %33, i32 %34)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %29
%38 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = tail call i32 @exit(i32 %39)
unreachable
41: ; preds = %29
%42 = call i32 @memset(%struct.ifreq* %3, i32 0, i32 4)
%43 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
%44 = load i32, i32* %43
%45 = call i32 @snprintf(i32 %44, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%46 = load i32, i32* @SOL_SOCKET
%47 = load i32, i32* @SO_BINDTODEVICE
%48 = call i64 @setsockopt(i32 %35, i32 %46, i32 %47, i8* %6, i32 4)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %41
%51 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %41
%55 = icmp eq i32 %31, 0
br i1 %55, label %58, label %56
56: ; preds = %54
%57 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %30)
br label %58
58: ; preds = %56, %54
%59 = bitcast %struct.sockaddr_in6* %4 to i8*
%60 = bitcast i32* %5 to i8*
%61 = bitcast %struct.sockaddr_in6* %4 to %struct.sockaddr*
%62 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 0
br label %63
63: ; preds = %108, %58
store i32 4, i32* %5
%64 = load i32, i32* @INET6_ADDRSTRLEN
%65 = add nsw i32 %64, 1
%66 = zext i32 %65 to i64
%67 = call i8* @llvm.stacksave()
%68 = alloca i8, i64 %66
%69 = load i32, i32* @IP_MAXPACKET
%70 = zext i32 %69 to i64
%71 = alloca i32, i64 %70
%72 = shl i32 %69, 2
%73 = call i32 @recvfrom(i32 %35, i32* %71, i32 %72, i32 0, %struct.sockaddr* %61, i32* %5)
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %63
%76 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %77
77: ; preds = %75, %63
%78 = load i32, i32* @AF_INET6
%79 = load i32, i32* @INET6_ADDRSTRLEN
%80 = call i32* @inet_ntop(i32 %78, i32* %62, i8* %68, i32 %79)
%81 = icmp eq i32* %80, null
br i1 %81, label %82, label %86
82: ; preds = %77
%83 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%84 = load i32, i32* @EXIT_FAILURE
%85 = call i32 @exit(i32 %84)
unreachable
86: ; preds = %77
%87 = getelementptr inbounds i32, i32* %71, i64 2
%88 = load i32, i32* %87
%89 = getelementptr inbounds i32, i32* %71, i64 1
%90 = load i32, i32* %89
store i32 %90, i32* %87
store i32 %88, i32* %89
%91 = load i32, i32* %71
%92 = icmp eq i32 %91, 1
br i1 %92, label %93, label %99
93: ; preds = %86
br i1 %55, label %96, label %94
94: ; preds = %93
%95 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %68)
br label %96
96: ; preds = %94, %93
%97 = getelementptr inbounds i32, i32* %71, i64 3
%98 = load i32, i32* @ICMP_ECHOREPLY
store i32 %98, i32* %97
br label %102
99: ; preds = %86
%100 = load i32, i32* @stderr
%101 = call i32 @fprintf(i32 %100, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i32 %91)
br label %102
102: ; preds = %99, %96
%103 = load i32, i32* %5
%104 = call i64 @sendto(i32 %35, i32* %71, i32 %73, i32 0, %struct.sockaddr* %61, i32 %103)
%105 = icmp slt i64 %104, 0
br i1 %105, label %106, label %108
106: ; preds = %102
%107 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %108
108: ; preds = %106, %102
br label %63
}