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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(unsigned short);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(int argc, char *argv[]) {
  int sockfd = 0;
  char buf[1024] = "";
  unsigned short port = 8000;
  struct sockaddr_in send_addr;
  bzero(&send_addr, sizeof(send_addr));
  send_addr.sin_family = AF_INET;
  send_addr.sin_port = htons(port);
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd < 0) {
    perror("socket");
    exit(-1);
  }
  if (argc > 1) {
    send_addr.sin_addr.s_addr = inet_addr(argv[1]);
  } else {
    printf("not have the server ip !!!!\n");
    exit(-1);
  }
  int yes = 1;
  setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(yes));
  while (1) {
    fgets(buf, sizeof(buf), stdin);
    buf[strlen(buf) - 1] = '\0';
    int len = sendto(sockfd, buf, strlen(buf), 0, (struct sockaddr *)&send_addr,
                     sizeof(send_addr));
    if (len < 0) {
      printf("send error!!!\n");
      close(sockfd);
      exit(-1);
    }
    printf("send success!!!!\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
movw   $0x1f40,-0x422(%rbp)
40 1f
lea    -0x430(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
movzwl -0x422(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x42c(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    127a <main+0xaa>
lea    0xd95(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
cmpl   $0x1,-0x8(%rbp)
jle    129c <main+0xcc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,-0x430(%rbp)
jmp    12b2 <main+0xe2>
lea    0xd64(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
movl   $0x1,-0x434(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d22(%rip),%rax
mov    (%rax),%esi
mov    0x2cf9(%rip),%rax
mov    (%rax),%edx
lea    -0x434(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    -0x420(%rbp),%rdi
mov    0x2ce7(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   10a0 <fgets@plt>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x420(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
mov    %eax,-0x444(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x440(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x444(%rbp),%edi
mov    -0x440(%rbp),%rsi
mov    %eax,%edx
lea    -0x430(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1080 <sendto@plt>
mov    %eax,-0x438(%rbp)
cmpl   $0x0,-0x438(%rbp)
jge    138d <main+0x1bd>
lea    0xcae(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
lea    0xc9f(%rip),%rdi
call   1060 <printf@plt>
jmp    12e3 <main+0x113>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x420,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
lea    0x20(%rsp),%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
lea    0x10(%rsp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2dd1(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0x1f40,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x0(%rbp),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
jns    1251 <main+0x81>
lea    0xdbe(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
cmp    $0x2,%r15d
jl     12fd <main+0x12d>
mov    %eax,%ebp
mov    0x8(%r14),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x10(%rsp)
movl   $0x1,0xc(%rsp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
mov    0x2d46(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    0x2d3b(%rip),%r12
lea    0x10(%rsp),%r14
lea    0xd7a(%rip),%r15
nopl   0x0(%rax)
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   10a0 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1080 <sendto@plt>
test   %eax,%eax
js     1313 <main+0x143>
mov    %r15,%rdi
call   1030 <puts@plt>
jmp    12b0 <main+0xe0>
lea    0xd03(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
lea    0xd1a(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [29 x i8] c"not have the server ip !!!!\0A\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@stdin = global i32 0
@.str.2 = [15 x i8] c"send error!!!\0A\00"
@.str.3 = [18 x i8] c"send success!!!!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i16
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%12 = bitcast [1024 x i8]* %7 to i8*
store i16 8000, i16* %8
%13 = call i32 @bzero(%struct.sockaddr_in* %9, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %14, i32* %15
%16 = load i16, i16* %8
%17 = call i32 @htons(i16 zeroext %16)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @AF_INET
%20 = load i32, i32* @SOCK_DGRAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %2
%25 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %2
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 1
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @inet_addr(i8* %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%36 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %35, i32 0, i32 0
store i32 %34, i32* %36
br label %40
37: ; preds = %27
%38 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %30
store i32 1, i32* %10
%41 = load i32, i32* %6
%42 = load i32, i32* @SOL_SOCKET
%43 = load i32, i32* @SO_BROADCAST
%44 = call i32 @setsockopt(i32 %41, i32 %42, i32 %43, i32* %10, i32 4)
br label %45
45: ; preds = %40, %67
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%47 = load i32, i32* @stdin
%48 = call i32 @fgets(i8* %46, i32 1024, i32 %47)
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %52
store i8 0, i8* %53
%54 = load i32, i32* %6
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%57 = call i32 @strlen(i8* %56)
%58 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%59 = call i32 @sendto(i32 %54, i8* %55, i32 %57, i32 0, %struct.sockaddr* %58, i32 12)
store i32 %59, i32* %11
%60 = load i32, i32* %11
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %45
%63 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%64 = load i32, i32* %6
%65 = call i32 @close(i32 %64)
%66 = call i32 @exit(i32 -1)
unreachable
67: ; preds = %45
%68 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %45
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@stdin = global i32 0
@str = [28 x i8] c"not have the server ip !!!!\00"
@str.4 = [17 x i8] c"send success!!!!\00"
@str.5 = [14 x i8] c"send error!!!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %9, i32* %10
%11 = tail call i32 @htons(i16 zeroext 8000)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %11, i32* %12
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = icmp sgt i32 %0, 1
br i1 %21, label %22, label %32
22: ; preds = %20
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i32 @inet_addr(i8* %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %25, i32* %26
%27 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%28 = load i32, i32* @SOL_SOCKET
%29 = load i32, i32* @SO_BROADCAST
%30 = call i32 @setsockopt(i32 %15, i32 %28, i32 %29, i32* %5, i32 4)
%31 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %35
32: ; preds = %20
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%34 = tail call i32 @exit(i32 -1)
unreachable
35: ; preds = %49, %22
%36 = load i32, i32* @stdin
%37 = call i32 @fgets(i8* %6, i32 1024, i32 %36)
%38 = call i32 @strlen(i8* %6)
%39 = add nsw i32 %38, -1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %40
store i8 0, i8* %41
%42 = call i32 @strlen(i8* %6)
%43 = call i32 @sendto(i32 %15, i8* %6, i32 %42, i32 0, %struct.sockaddr* %31, i32 12)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %35
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0))
%47 = call i32 @close(i32 %15)
%48 = call i32 @exit(i32 -1)
unreachable
49: ; preds = %35
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0))
br label %35
}