#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__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_RAW;
int atoi(char const *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
scalar_t__ sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int);
int main(int argc, char const *argv[]) {
  struct sockaddr_in addr;
  int rsfd, n = 1, len;
  char buffer[1024];
  rsfd = socket(AF_INET, SOCK_RAW, 146);
  if (rsfd < 0) {
    perror("socket() ");
    exit(1);
  }
  memset((char *)&addr, 0, sizeof addr);
  addr.sin_family = AF_INET;
  addr.sin_port = argc == 1 ? 8001 : atoi(argv[1]);
  addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  while (1) {
    if (sendto(rsfd, "Rajmani Arya", 13, 0, (struct sockaddr *)&addr,
               sizeof addr) < 0) {
      perror("sendto() ");
    }
    printf("Packet Sent %d \n", n++);
    sleep(3);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x28(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
mov    $0x92,%edx
call   10b0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11ef <main+0x5f>
lea    0xe20(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1225 <main+0x95>
mov    $0x1f41,%eax
mov    %eax,-0x434(%rbp)
jmp    1238 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x434(%rbp)
mov    -0x434(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    0xdc2(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%r8
lea    0xdb6(%rip),%rsi
mov    $0xd,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
cmp    $0x0,%rax
jge    1286 <main+0xf6>
lea    0xda0(%rip),%rdi
call   1070 <perror@plt>
mov    -0x28(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
lea    0xd93(%rip),%rdi
call   1030 <printf@plt>
mov    $0x3,%edi
call   10a0 <sleep@plt>
jmp    1250 <main+0xc0>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e3e(%rip),%r15
mov    (%r15),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    $0x92,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     1278 <main+0xe8>
mov    %eax,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    $0x1f41,%eax
cmp    $0x1,%ebp
je     11f5 <main+0x65>
mov    0x8(%r14),%rdi
call   1080 <atoi@plt>
mov    %eax,0x8(%rsp)
lea    0xe0a(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    $0x1,%ebp
lea    0xdff(%rip),%r14
lea    0x8(%rsp),%r15
lea    0xe0a(%rip),%r13
jmp    124b <main+0xbb>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x1(%rbp),%r12d
mov    %r13,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    $0x3,%edi
call   10a0 <sleep@plt>
mov    %r12d,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xd,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
test   %rax,%rax
jns    1230 <main+0xa0>
lea    0xdb0(%rip),%rdi
call   1070 <perror@plt>
jmp    1230 <main+0xa0>
lea    0xd81(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@.str = [10 x i8] c"socket() \00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [13 x i8] c"Rajmani Arya\00"
@.str.3 = [10 x i8] c"sendto() \00"
@.str.4 = [17 x i8] c"Packet Sent %d \0A\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 [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %8
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_RAW
%13 = call i32 @socket(i32 %11, i32 %12, i32 146)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = bitcast %struct.sockaddr_in* %6 to i8*
%21 = call i32 @memset(i8* %20, i32 0, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %22, i32* %23
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %27
26: ; preds = %19
br label %32
27: ; preds = %19
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
br label %32
32: ; preds = %27, %26
%33 = phi i32 [ 8001, %26 ], [ %31, %27 ]
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %33, i32* %34
%35 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
store i32 %35, i32* %37
br label %38
38: ; preds = %32, %45
%39 = load i32, i32* %7
%40 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%41 = call i64 @sendto(i32 %39, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 13, i32 0, %struct.sockaddr* %40, i32 12)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %45
45: ; preds = %43, %38
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
%48 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%49 = call i32 @sleep(i32 3)
br label %38
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@.str = [10 x i8] c"socket() \00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [13 x i8] c"Rajmani Arya\00"
@.str.3 = [10 x i8] c"sendto() \00"
@.str.4 = [17 x i8] c"Packet Sent %d \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_RAW
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 146)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = call i32 @memset(i8* %4, i32 0, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %14, i32* %15
%16 = icmp eq i32 %0, 1
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
br label %21
21: ; preds = %12, %17
%22 = phi i32 [ %20, %17 ], [ 8001, %12 ]
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %22, i32* %23
%24 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %24, i32* %25
%26 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %27
27: ; preds = %33, %21
%28 = phi i32 [ 1, %21 ], [ %34, %33 ]
%29 = call i64 @sendto(i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 13, i32 0, %struct.sockaddr* %26, i32 12)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = add nuw nsw i32 %28, 1
%35 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%36 = call i32 @sleep(i32 3)
br label %27
}