#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*/ send_buf;
typedef int /*<<< orphan*/ addr_serv;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int);
int main(int argc, char *argv[]) {
  int sock_fd;
  int send_num;
  int dst_len;
  char send_buf[20] = {0};
  char recv_buf[20] = {0};
  struct sockaddr_in addr_serv;
  sock_fd = socket(AF_INET, SOCK_DGRAM, 17);
  memset(&addr_serv, 0, sizeof(addr_serv));
  addr_serv.sin_family = AF_INET;
  addr_serv.sin_addr.s_addr = inet_addr("127.0.0.1");
  addr_serv.sin_port = htons(3000);
  dst_len = sizeof(struct sockaddr_in);
  printf("input message: ");
  scanf("%s", send_buf);
  puts("begin send:\n");
  send_num = sendto(sock_fd, send_buf, sizeof(send_buf), 0,
                    (struct sockaddr *)&addr_serv, dst_len);
  if (send_num < 0) {
    perror("sendto\n");
    exit(-1);
  } else {
    printf("send sucessful: %s\n", send_buf);
  }
  close(sock_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    $0x11,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
lea    0xdd8(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x5c(%rbp)
mov    $0xbb8,%edi
call   1040 <htons@plt>
mov    %eax,-0x60(%rbp)
movl   $0xc,-0x1c(%rbp)
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xdbd(%rip),%rdi
call   10a0 <scanf@plt>
lea    0xdb4(%rip),%rdi
call   1030 <puts@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x60(%rbp),%r8
mov    -0x1c(%rbp),%r9d
mov    $0x14,%edx
xor    %ecx,%ecx
call   1070 <sendto@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12ac <main+0xfc>
lea    0xd8d(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
lea    -0x30(%rbp),%rsi
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
mov    0x2e19(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
mov    $0x11,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xdfb(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0xbb8,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
lea    0xde8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdea(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   10a0 <scanf@plt>
lea    0xdd9(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x14,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
test   %eax,%eax
js     128c <main+0xdc>
lea    0xdc4(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd97(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <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_DGRAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [16 x i8] c"input message: \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [13 x i8] c"begin send:\0A\00"
@.str.4 = [8 x i8] c"sendto\0A\00"
@.str.5 = [20 x i8] c"send sucessful: %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 [20 x i8]
%10 = alloca [20 x i8]
%11 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [20 x i8]* %9 to i8*
%13 = bitcast [20 x i8]* %10 to i8*
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 17)
store i32 %16, i32* %6
%17 = call i32 @memset(%struct.sockaddr_in* %11, i32 0, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = call i32 @htons(i32 3000)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %23, i32* %24
store i32 12, i32* %8
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* %6
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%31 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%32 = load i32, i32* %8
%33 = call i32 @sendto(i32 %29, i8* %30, i32 20, i32 0, %struct.sockaddr* %31, i32 %32)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %2
%37 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @exit(i32 -1)
unreachable
39: ; preds = %2
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %39
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
ret i32 0
}

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_DGRAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [16 x i8] c"input message: \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [13 x i8] c"begin send:\0A\00"
@.str.4 = [8 x i8] c"sendto\0A\00"
@.str.5 = [20 x i8] c"send sucessful: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [20 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 17)
%10 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %11, i32* %12
%13 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %13, i32* %14
%15 = call i32 @htons(i32 3000)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %15, i32* %16
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%20 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%21 = call i32 @sendto(i32 %9, i8* %5, i32 20, i32 0, %struct.sockaddr* %20, i32 12)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %2
%24 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %2
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%28 = call i32 @close(i32 %9)
ret i32 0
}