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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ PF_UNSPEC;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int, int, char *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char const *argv[]) {
  int s = 0;
  int n = 0;
  int port = 1995;
  struct sockaddr_in srv;
  char *addr = "127.0.0.1";
  char buf[256] = {0};
  if (argc == 2) {
    addr = (char *)argv[1];
  }
  bzero(&srv, sizeof(srv));
  srv.sin_family = PF_INET;
  srv.sin_addr.s_addr = inet_addr(addr);
  srv.sin_port = htons(port);
  s = socket(AF_INET, SOCK_DGRAM, PF_UNSPEC);
  if (s < 0) {
    perror("socket");
    return -1;
  }
  while (1) {
    memset(buf, 0, 256);
    fgets(buf, 256, stdin);
    if ((n = sendto(s, buf, strlen(buf), 0, (struct sockaddr *)&srv,
                    sizeof(struct sockaddr))) < 0) {
      perror("sendto");
      return -1;
    } else {
      printf("send to %s(port=%d) len %d:%s\n", addr, port, n, buf);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x7cb,-0x1c(%rbp)
lea    0xe2b(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
jne    1202 <main+0x62>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    0x2d8d(%rip),%rax
mov    (%rax),%esi
mov    0x2d9c(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1278 <main+0xd8>
lea    0xda3(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1333 <main+0x193>
jmp    127d <main+0xdd>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x130(%rbp),%rdi
mov    0x2d3a(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1080 <fgets@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x13c(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x13c(%rbp),%edi
mov    -0x138(%rbp),%rsi
mov    %eax,%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1070 <sendto@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1311 <main+0x171>
lea    0xd11(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1333 <main+0x193>
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    -0x130(%rbp),%r8
lea    0xcef(%rip),%rdi
call   1050 <printf@plt>
jmp    127d <main+0xdd>
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
cmp    $0x2,%edi
jne    122a <main+0x8a>
mov    0x8(%rsi),%r14
jmp    1231 <main+0x91>
lea    0xdcf(%rip),%r14
mov    %rsp,%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %r14,%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x7cb,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
mov    0x2d5c(%rip),%rax
mov    (%rax),%esi
mov    0x2d6b(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
test   %eax,%eax
jns    1294 <main+0xf4>
lea    0xd7b(%rip),%rdi
jmp    1311 <main+0x171>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
mov    0x2d36(%rip),%r13
mov    %rsp,%r15
lea    0xd6c(%rip),%r12
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x4,%r9d
call   1070 <sendto@plt>
test   %eax,%eax
js     130a <main+0x16a>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x7cb,%edx
mov    %eax,%ecx
mov    %rbx,%r8
call   1050 <printf@plt>
jmp    12b0 <main+0x110>
lea    0xd00(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@PF_INET = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@PF_UNSPEC = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@stdin = global i32 0
@.str.2 = [7 x i8] c"sendto\00"
@.str.3 = [31 x i8] c"send to %s(port=%d) len %d:%s\0A\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 %struct.sockaddr_in
%10 = alloca i8*
%11 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 1995, i32* %8
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %10
%12 = bitcast [256 x i8]* %11 to i8*
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %10
br label %19
19: ; preds = %15, %2
%20 = call i32 @bzero(%struct.sockaddr_in* %9, i32 12)
%21 = load i32, i32* @PF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %21, i32* %22
%23 = load i8*, i8** %10
%24 = call i32 @inet_addr(i8* %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = load i32, i32* %8
%28 = call i32 @htons(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %28, i32* %29
%30 = load i32, i32* @AF_INET
%31 = load i32, i32* @SOCK_DGRAM
%32 = load i32, i32* @PF_UNSPEC
%33 = call i32 @socket(i32 %30, i32 %31, i32 %32)
store i32 %33, i32* %6
%34 = load i32, i32* %6
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %19
%37 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %61
38: ; preds = %19
br label %39
39: ; preds = %38, %60
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%41 = call i32 @memset(i8* %40, i32 0, i32 256)
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%43 = load i32, i32* @stdin
%44 = call i32 @fgets(i8* %42, i32 256, i32 %43)
%45 = load i32, i32* %6
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
%49 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%50 = call i32 @sendto(i32 %45, i8* %46, i32 %48, i32 0, %struct.sockaddr* %49, i32 4)
store i32 %50, i32* %7
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %39
%53 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %61
54: ; preds = %39
%55 = load i8*, i8** %10
%56 = load i32, i32* %8
%57 = load i32, i32* %7
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%59 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %55, i32 %56, i32 %57, i8* %58)
br label %60
60: ; preds = %54
br label %39
61: ; preds = %52, %36
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@PF_INET = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@PF_UNSPEC = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@stdin = global i32 0
@.str.2 = [7 x i8] c"sendto\00"
@.str.3 = [31 x i8] c"send to %s(port=%d) len %d:%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
br label %11
11: ; preds = %8, %2
%12 = phi i8* [ %10, %8 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %2 ]
%13 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%14 = load i32, i32* @PF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %14, i32* %15
%16 = tail call i32 @inet_addr(i8* %12)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %16, i32* %17
%18 = tail call i32 @htons(i32 1995)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_DGRAM
%22 = load i32, i32* @PF_UNSPEC
%23 = tail call i32 @socket(i32 %20, i32 %21, i32 %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %11
%26 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %29
27: ; preds = %11
%28 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %40
29: ; preds = %25, %38
%30 = call i32 @memset(i8* %6, i32 0, i32 256)
%31 = load i32, i32* @stdin
%32 = call i32 @fgets(i8* %6, i32 256, i32 %31)
%33 = call i32 @strlen(i8* %6)
%34 = call i32 @sendto(i32 %23, i8* %6, i32 %33, i32 0, %struct.sockaddr* %26, i32 4)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %40
38: ; preds = %29
%39 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %12, i32 1995, i32 %34, i8* %6)
br label %29
40: ; preds = %36, %27
ret i32 -1
}