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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ 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 /*<<< orphan*/, int /*<<< orphan*/,
                  struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ strlen(char *);
int main() {
  int rsfd;
  rsfd = socket(AF_INET, SOCK_RAW, 148);
  if (rsfd < 0) {
    perror("socket() ");
  }
  struct sockaddr_in addr;
  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");
  char buf[128];
  while (1) {
    printf("Enter Ad: ");
    scanf("%s", buf);
    if (sendto(rsfd, buf, strlen(buf), 0, (struct sockaddr *)&addr,
               sizeof addr) < 0) {
      perror("sendto() ");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
mov    $0x94,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11c7 <main+0x47>
lea    0xe3e(%rip),%rdi
call   1090 <perror@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe18(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
lea    0xe13(%rip),%rdi
call   1040 <printf@plt>
lea    -0xa0(%rbp),%rsi
lea    0xe0b(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xac(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xac(%rbp),%edi
mov    -0xa8(%rbp),%rsi
mov    %eax,%edx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0x18,%r9d
call   1060 <sendto@plt>
cmp    $0x0,%rax
jge    1272 <main+0xf2>
lea    0xdb5(%rip),%rdi
call   1090 <perror@plt>
jmp    11fa <main+0x7a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    0x2e50(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
mov    $0x94,%edx
call   10a0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1251 <main+0xd1>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe29(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x8(%rsp)
lea    0xe23(%rip),%r15
lea    0xe27(%rip),%r12
lea    0x20(%rsp),%rbx
lea    0xe1e(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0x18,%r9d
call   1060 <sendto@plt>
test   %rax,%rax
jns    1210 <main+0x90>
mov    %r13,%rdi
call   1090 <perror@plt>
jmp    1210 <main+0x90>
lea    0xda8(%rip),%rdi
call   1090 <perror@plt>
jmp    11b7 <main+0x37>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, 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 = [11 x i8] c"Enter Ad: \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [10 x i8] c"sendto() \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [128 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_RAW
%7 = call i32 @socket(i32 %5, i32 %6, i32 148)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = bitcast %struct.sockaddr_in* %3 to i8*
%14 = call i32 @memset(i8* %13, i32 0, i32 24)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i64 0, i64* %17
%18 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
br label %21
21: ; preds = %12, %34
%22 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %2
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%30 = call i64 @sendto(i32 %25, i8* %26, i32 %28, i32 0, %struct.sockaddr* %29, i32 24)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %21
br label %21
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, 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 = [11 x i8] c"Enter Ad: \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [10 x i8] c"sendto() \00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [128 x i8]
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_RAW
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 148)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = bitcast %struct.sockaddr_in* %1 to i8*
%11 = call i32 @memset(i8* %10, i32 0, i32 24)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i64 0, i64* %14
%15 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %15, i32* %16
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%18 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
br label %19
19: ; preds = %27, %9
%20 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%22 = call i32 @strlen(i8* %17)
%23 = call i64 @sendto(i32 %5, i8* %17, i32 %22, i32 0, %struct.sockaddr* %18, i32 24)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
br label %19
}