#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 */
typedef int /*<<< orphan*/ val;
struct TYPE_2__ {
  void *s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  scalar_t__ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct iphdr {
  int version;
  int ihl;
  int ttl;
  int protocol;
  int /*<<< orphan*/ tot_len;
  void *daddr;
  void *saddr;
  scalar_t__ frag_off;
  scalar_t__ tos;
};
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_HDRINCL;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(scalar_t__);
void *inet_addr(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int main(int argc, char const *argv[]) {
  struct sockaddr_in addr;
  int rsfd, n, len, val = 1;
  char buffer[1024], buf[128];
  rsfd = socket(AF_INET, SOCK_RAW, 146);
  if (rsfd < 0) {
    perror("socket() ");
    exit(1);
  }
  if (setsockopt(rsfd, IPPROTO_IP, IP_HDRINCL, &val, sizeof(val)) < 0) {
    perror("setsockopt() ");
  }
  memset((char *)&addr, 0, sizeof addr);
  addr.sin_family = AF_INET;
  addr.sin_port = 0;
  addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  struct iphdr *iph;
  while (1) {
    memset(buf, 0, 128);
    printf("Enter Message to Send: ");
    scanf("%s", buf);
    memset(buffer, 0, 1024);
    iph = (struct iphdr *)buffer;
    iph->version = 4;
    iph->ihl = 5;
    iph->tos = 0;
    iph->frag_off = 0;
    iph->ttl = 8;
    iph->protocol = 146;
    iph->saddr = inet_addr("127.0.1.1");
    iph->daddr = inet_addr("127.0.0.1");
    strcpy(buffer + sizeof(struct iphdr), buf);
    iph->tot_len = htons(sizeof(struct iphdr) + strlen(buf));
    if (sendto(rsfd, buffer, sizeof(buffer), 0, (struct sockaddr *)&addr,
               sizeof addr) < 0) {
      perror("sendto() ");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x38(%rbp)
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
mov    $0x92,%edx
call   10e0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    121f <main+0x5f>
lea    0xdf0(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x2c(%rbp),%edi
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
mov    0x2dbe(%rip),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    1259 <main+0x99>
lea    0xdb6(%rip),%rdi
call   10c0 <perror@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xd94(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,-0x28(%rbp)
lea    -0x4c0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1080 <memset@plt>
lea    0xd7b(%rip),%rdi
call   1070 <printf@plt>
lea    -0x4c0(%rbp),%rsi
lea    0xd80(%rip),%rdi
call   10b0 <scanf@plt>
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
lea    -0x440(%rbp),%rax
mov    %rax,-0x4c8(%rbp)
mov    -0x4c8(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x4c8(%rbp),%rax
movl   $0x5,0x4(%rax)
mov    -0x4c8(%rbp),%rax
movq   $0x0,0x30(%rax)
mov    -0x4c8(%rbp),%rax
movq   $0x0,0x28(%rax)
mov    -0x4c8(%rbp),%rax
movl   $0x8,0x8(%rax)
mov    -0x4c8(%rbp),%rax
movl   $0x92,0xc(%rax)
lea    0xd01(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,%rcx
mov    -0x4c8(%rbp),%rax
mov    %rcx,0x20(%rax)
lea    0xcc2(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,%rcx
mov    -0x4c8(%rbp),%rax
mov    %rcx,0x18(%rax)
lea    -0x440(%rbp),%rdi
add    $0x38,%rdi
lea    -0x4c0(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x4c0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x38,%rdi
call   1060 <htons@plt>
mov    %eax,%ecx
mov    -0x4c8(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x2c(%rbp),%edi
lea    -0x440(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
mov    $0x18,%r9d
call   1090 <sendto@plt>
cmp    $0x0,%rax
jge    13da <main+0x21a>
lea    0xc72(%rip),%rdi
call   10c0 <perror@plt>
jmp    128d <main+0xcd>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4a8,%rsp
movl   $0x1,0x4(%rsp)
mov    0x2e00(%rip),%rbx
mov    (%rbx),%edi
mov    0x2def(%rip),%rax
mov    (%rax),%esi
mov    $0x92,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     1361 <main+0x1a1>
mov    %eax,%ebp
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
mov    0x2de1(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
js     1350 <main+0x190>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xde5(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,0x8(%rsp)
lea    0x20(%rsp),%rbx
lea    0xdd9(%rip),%r13
lea    0xdea(%rip),%r14
lea    0xa0(%rsp),%r15
lea    0xdde(%rip),%r12
nop
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1080 <memset@plt>
mov    %r13,%rdi
call   1070 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
lea    0xc8(%rsp),%rax
xorps  %xmm0,%xmm0
movups %xmm0,(%rax)
movaps 0xd3a(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
mov    %r12,%rdi
call   10a0 <inet_addr@plt>
mov    %rax,0xc0(%rsp)
lea    0xd53(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,0xb8(%rsp)
lea    0xd8(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x38(%rax),%rdi
call   1060 <htons@plt>
mov    %eax,0xb0(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
lea    0x8(%rsp),%r8
mov    $0x18,%r9d
call   1090 <sendto@plt>
test   %rax,%rax
jns    1280 <main+0xc0>
lea    0xd21(%rip),%rdi
call   10c0 <perror@plt>
jmp    1280 <main+0xc0>
lea    0xcd3(%rip),%rdi
call   10c0 <perror@plt>
jmp    122c <main+0x6c>
lea    0xcb8(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.iphdr = type { i32, i32, i32, i32, i32, i8*, i8*, i64, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@.str = [10 x i8] c"socket() \00"
@IPPROTO_IP = global i32 0
@IP_HDRINCL = global i32 0
@.str.1 = [14 x i8] c"setsockopt() \00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [24 x i8] c"Enter Message to Send: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [10 x i8] c"127.0.1.1\00"
@.str.6 = [10 x i8] c"sendto() \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1024 x i8]
%12 = alloca [128 x i8]
%13 = alloca %struct.iphdr*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %10
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_RAW
%16 = call i32 @socket(i32 %14, i32 %15, i32 146)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i32, i32* %7
%24 = load i32, i32* @IPPROTO_IP
%25 = load i32, i32* @IP_HDRINCL
%26 = call i64 @setsockopt(i32 %23, i32 %24, i32 %25, i32* %10, i32 4)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %22
%31 = bitcast %struct.sockaddr_in* %6 to i8*
%32 = call i32 @memset(i8* %31, i32 0, i32 24)
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %33, i32* %34
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i64 0, i64* %35
%36 = call i8* @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %37, i32 0, i32 0
store i8* %36, i8** %38
br label %39
39: ; preds = %30, %84
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%41 = call i32 @memset(i8* %40, i32 0, i32 128)
%42 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%44 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %43)
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%46 = call i32 @memset(i8* %45, i32 0, i32 1024)
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%48 = bitcast i8* %47 to %struct.iphdr*
store %struct.iphdr* %48, %struct.iphdr** %13
%49 = load %struct.iphdr*, %struct.iphdr** %13
%50 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %49, i32 0, i32 0
store i32 4, i32* %50
%51 = load %struct.iphdr*, %struct.iphdr** %13
%52 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %51, i32 0, i32 1
store i32 5, i32* %52
%53 = load %struct.iphdr*, %struct.iphdr** %13
%54 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %53, i32 0, i32 8
store i64 0, i64* %54
%55 = load %struct.iphdr*, %struct.iphdr** %13
%56 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %55, i32 0, i32 7
store i64 0, i64* %56
%57 = load %struct.iphdr*, %struct.iphdr** %13
%58 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %57, i32 0, i32 2
store i32 8, i32* %58
%59 = load %struct.iphdr*, %struct.iphdr** %13
%60 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %59, i32 0, i32 3
store i32 146, i32* %60
%61 = call i8* @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%62 = load %struct.iphdr*, %struct.iphdr** %13
%63 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %62, i32 0, i32 6
store i8* %61, i8** %63
%64 = call i8* @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%65 = load %struct.iphdr*, %struct.iphdr** %13
%66 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %65, i32 0, i32 5
store i8* %64, i8** %66
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%68 = getelementptr inbounds i8, i8* %67, i64 56
%69 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%70 = call i32 @strcpy(i8* %68, i8* %69)
%71 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%72 = call i64 @strlen(i8* %71)
%73 = add i64 56, %72
%74 = call i32 @htons(i64 %73)
%75 = load %struct.iphdr*, %struct.iphdr** %13
%76 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %75, i32 0, i32 4
store i32 %74, i32* %76
%77 = load i32, i32* %7
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%79 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%80 = call i64 @sendto(i32 %77, i8* %78, i32 1024, i32 0, %struct.sockaddr* %79, i32 24)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %39
%83 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %84
84: ; preds = %82, %39
br label %39
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@.str = [10 x i8] c"socket() \00"
@IPPROTO_IP = global i32 0
@IP_HDRINCL = global i32 0
@.str.1 = [14 x i8] c"setsockopt() \00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [24 x i8] c"Enter Message to Send: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [10 x i8] c"127.0.1.1\00"
@.str.6 = [10 x i8] c"sendto() \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca [128 x i8]
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_RAW
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 146)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i32, i32* @IPPROTO_IP
%20 = load i32, i32* @IP_HDRINCL
%21 = call i64 @setsockopt(i32 %13, i32 %19, i32 %20, i32* %4, i32 4)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %18
%26 = call i32 @memset(i8* %7, i32 0, i32 24)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %27, i32* %28
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i64 0, i64* %29
%30 = call i8* @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i8* %30, i8** %31
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 40
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 32
%34 = bitcast i8* %33 to i8**
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 24
%36 = bitcast i8* %35 to i8**
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 56
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 16
%39 = bitcast i8* %38 to i32*
%40 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%41 = bitcast [1024 x i8]* %5 to <4 x i32>*
br label %42
42: ; preds = %57, %25
%43 = call i32 @memset(i8* %10, i32 0, i32 128)
%44 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%46 = call i32 @memset(i8* %9, i32 0, i32 1024)
store <4 x i32> <i32 4, i32 5, i32 8, i32 146>, <4 x i32>* %41
%47 = call i8* @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
store i8* %47, i8** %34
%48 = call i8* @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i8* %48, i8** %36
%49 = call i32 @strcpy(i8* %37, i8* %10)
%50 = call i64 @strlen(i8* %10)
%51 = add i64 %50, 56
%52 = call i32 @htons(i64 %51)
store i32 %52, i32* %39
%53 = call i64 @sendto(i32 %13, i8* %9, i32 1024, i32 0, %struct.sockaddr* %40, i32 24)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %42
%56 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %57
57: ; preds = %55, %42
br label %42
}