#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 */

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  void *sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
void *htons(int);
int /*<<< orphan*/ inet_pton(void *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                  struct sockaddr *, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  int sockfd;
  struct sockaddr_in group_addr, my_addr;
  char buf[511 - 1];
  int rcvlen;
  socklen_t addrlen;
  if (argc != 3) {
    usage();
    exit(errno);
  }
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    fprintf(stderr, "Error: socket() failed!\n");
    exit(errno);
  }
  memset(&group_addr, 0, sizeof(struct sockaddr_in));
  group_addr.sin_family = AF_INET;
  group_addr.sin_port = htons(atoi(argv[2]));
  inet_pton(AF_INET, argv[1], &group_addr.sin_addr);
  memset(&my_addr, 0, sizeof(struct sockaddr_in));
  my_addr.sin_family = AF_INET;
  my_addr.sin_port = htons(7878);
  inet_pton(AF_INET, "192.168.0.104", &my_addr.sin_addr);
  if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) ==
      -1) {
    fprintf(stderr, "Error: bind() failed!\n error code:%s\n", strerror(errno));
    exit(errno);
  }
  while (1) {
    bzero(buf, sizeof(buf));
    usleep(5000);
    strcpy(buf, "Hello world!");
    if (sendto(sockfd, buf, strlen(buf), 0, (struct sockaddr *)&group_addr,
               sizeof(struct sockaddr)) < 0) {
      fprintf(stderr, "Error: send() failed!\n errno:%s\n", strerror(errno));
      exit(errno);
    }
    printf("Send Message Success!\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1238 <main+0x38>
mov    $0x0,%al
call   10b0 <usage@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%rdi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1283 <main+0x83>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %rax,-0x28(%rbp)
mov    0x2d28(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x30(%rbp),%rdx
call   10a0 <inet_pton@plt>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2cfd(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    $0x1ec6,%edi
call   1050 <htons@plt>
mov    %rax,-0x40(%rbp)
mov    0x2ce1(%rip),%rax
mov    (%rax),%rdi
lea    -0x48(%rbp),%rdx
lea    0xd04(%rip),%rsi
call   10a0 <inet_pton@plt>
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0x4,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1376 <main+0x176>
mov    0x2c95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x25c(%rbp)
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x25c(%rbp),%edi
mov    %rax,%rdx
lea    0xcc6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2c59(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
jmp    137b <main+0x17b>
lea    -0x250(%rbp),%rdi
mov    $0x1fe,%esi
call   10d0 <bzero@plt>
mov    $0x1388,%edi
call   1110 <usleep@plt>
lea    -0x250(%rbp),%rdi
lea    0xca9(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x26c(%rbp)
lea    -0x250(%rbp),%rax
mov    %rax,-0x268(%rbp)
lea    -0x250(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x26c(%rbp),%edi
mov    -0x268(%rbp),%rsi
mov    %eax,%edx
lea    -0x30(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1080 <sendto@plt>
cmp    $0x0,%rax
jge    1438 <main+0x238>
mov    0x2bd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x270(%rbp)
mov    0x2bbc(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x270(%rbp),%edi
mov    %rax,%rdx
lea    0xc37(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2b97(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    0xc3c(%rip),%rdi
call   1060 <printf@plt>
jmp    137b <main+0x17b>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x230,%rsp
cmp    $0x3,%edi
jne    124f <main+0x4f>
mov    %rsi,%rbx
mov    0x2dca(%rip),%rbp
mov    0x0(%rbp),%rdi
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
test   %eax,%eax
jns    1264 <main+0x64>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
lea    0xdba(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1256 <main+0x56>
xor    %eax,%eax
call   10b0 <usage@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    %eax,%r14d
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x0(%rbp),%rax
mov    %rax,0x10(%rsp)
mov    0x10(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %rax,0x8(%rsp)
mov    0x0(%rbp),%rdi
mov    0x8(%rbx),%rsi
mov    %r15,%rdx
call   10a0 <inet_pton@plt>
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x0(%rbp),%rax
mov    %rax,0x28(%rsp)
mov    $0x1ec6,%edi
call   1060 <htons@plt>
mov    %rax,0x20(%rsp)
mov    0x0(%rbp),%rdi
lea    0xd3b(%rip),%rsi
mov    %rbx,%rdx
call   10a0 <inet_pton@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    131f <main+0x11f>
mov    0x2cce(%rip),%rax
mov    (%rax),%ebx
mov    0x2cbd(%rip),%rbp
mov    0x0(%rbp),%edi
call   1100 <strerror@plt>
lea    0xd0d(%rip),%rsi
jmp    13b0 <main+0x1b0>
lea    0x30(%rsp),%rbx
lea    0xd22(%rip),%r15
mov    %rsp,%r12
lea    0xd46(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x1fe,%esi
call   10d0 <bzero@plt>
mov    $0x1388,%edi
call   1110 <usleep@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0x4,%r9d
call   1080 <sendto@plt>
test   %rax,%rax
js     1391 <main+0x191>
mov    %rbp,%rdi
call   1040 <puts@plt>
jmp    1340 <main+0x140>
mov    0x2c38(%rip),%rax
mov    (%rax),%ebx
mov    0x2c27(%rip),%rbp
mov    0x0(%rbp),%edi
call   1100 <strerror@plt>
lea    0xcaa(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x0(%rbp),%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i8*, i8* }
%struct.sockaddr = type { i32 }
@errno = global i32 0
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"Error: socket() failed!\0A\00"
@.str.1 = [14 x i8] c"192.168.0.104\00"
@.str.2 = [38 x i8] c"Error: bind() failed!\0A error code:%s\0A\00"
@.str.3 = [13 x i8] c"Hello world!\00"
@.str.4 = [33 x i8] c"Error: send() failed!\0A errno:%s\0A\00"
@.str.5 = [23 x i8] c"Send Message Success!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = alloca [510 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = call i32 (...) @usage()
%16 = load i32, i32* @errno
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = load i8*, i8** @AF_INET
%20 = load i32, i32* @SOCK_DGRAM
%21 = call i32 @socket(i8* %19, i32 %20, i32 0)
store i32 %21, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @errno
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %18
%29 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 24)
%30 = load i8*, i8** @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i8* %30, i8** %31
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
%36 = call i8* @htons(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i8* %36, i8** %37
%38 = load i8*, i8** @AF_INET
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%43 = call i32 @inet_pton(i8* %38, i8* %41, i32* %42)
%44 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 24)
%45 = load i8*, i8** @AF_INET
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i8* %45, i8** %46
%47 = call i8* @htons(i32 7878)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i8* %47, i8** %48
%49 = load i8*, i8** @AF_INET
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%51 = call i32 @inet_pton(i8* %49, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %50)
%52 = load i32, i32* %6
%53 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%54 = call i32 @bind(i32 %52, %struct.sockaddr* %53, i32 4)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %63
56: ; preds = %28
%57 = load i32, i32* @stderr
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %59)
%61 = load i32, i32* @errno
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %28
br label %64
64: ; preds = %63, %84
%65 = getelementptr inbounds [510 x i8], [510 x i8]* %9, i64 0, i64 0
%66 = call i32 @bzero(i8* %65, i32 510)
%67 = call i32 @usleep(i32 5000)
%68 = getelementptr inbounds [510 x i8], [510 x i8]* %9, i64 0, i64 0
%69 = call i32 @strcpy(i8* %68, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%70 = load i32, i32* %6
%71 = getelementptr inbounds [510 x i8], [510 x i8]* %9, i64 0, i64 0
%72 = getelementptr inbounds [510 x i8], [510 x i8]* %9, i64 0, i64 0
%73 = call i32 @strlen(i8* %72)
%74 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%75 = call i64 @sendto(i32 %70, i8* %71, i32 %73, i32 0, %struct.sockaddr* %74, i32 4)
%76 = icmp slt i64 %75, 0
br i1 %76, label %77, label %84
77: ; preds = %64
%78 = load i32, i32* @stderr
%79 = load i32, i32* @errno
%80 = call i8* @strerror(i32 %79)
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %80)
%82 = load i32, i32* @errno
%83 = call i32 @exit(i32 %82)
unreachable
84: ; preds = %64
%85 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %64
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i8*, i8* }
%struct.sockaddr = type { i32 }
@errno = global i32 0
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"Error: socket() failed!\0A\00"
@.str.1 = [14 x i8] c"192.168.0.104\00"
@.str.2 = [38 x i8] c"Error: bind() failed!\0A error code:%s\0A\00"
@.str.3 = [13 x i8] c"Hello world!\00"
@.str.4 = [33 x i8] c"Error: send() failed!\0A errno:%s\0A\00"
@str = [22 x i8] c"Send Message Success!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca [510 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = getelementptr inbounds [510 x i8], [510 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 3
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = tail call i32 (...) @usage()
%12 = load i32, i32* @errno
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i8*, i8** @AF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = tail call i32 @socket(i8* %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @errno
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %14
%25 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 24)
%26 = load i8*, i8** @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i8* %26, i8** %27
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
%31 = call i8* @htons(i32 %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i8* %31, i8** %32
%33 = load i8*, i8** @AF_INET
%34 = getelementptr inbounds i8*, i8** %1, i64 1
%35 = load i8*, i8** %34
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%37 = call i32 @inet_pton(i8* %33, i8* %35, i32* %36)
%38 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 24)
%39 = load i8*, i8** @AF_INET
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i8* %39, i8** %40
%41 = call i8* @htons(i32 7878)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i8* %41, i8** %42
%43 = load i8*, i8** @AF_INET
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%45 = call i32 @inet_pton(i8* %43, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %44)
%46 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%47 = call i32 @bind(i32 %17, %struct.sockaddr* %46, i32 4)
%48 = icmp eq i32 %47, -1
br i1 %48, label %51, label %49
49: ; preds = %24
%50 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %58
51: ; preds = %24
%52 = load i32, i32* @stderr
%53 = load i32, i32* @errno
%54 = call i8* @strerror(i32 %53)
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %54)
%56 = load i32, i32* @errno
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %49, %72
%59 = call i32 @bzero(i8* %8, i32 510)
%60 = call i32 @usleep(i32 5000)
%61 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%62 = call i32 @strlen(i8* %8)
%63 = call i64 @sendto(i32 %17, i8* %8, i32 %62, i32 0, %struct.sockaddr* %50, i32 4)
%64 = icmp slt i64 %63, 0
br i1 %64, label %65, label %72
65: ; preds = %58
%66 = load i32, i32* @stderr
%67 = load i32, i32* @errno
%68 = call i8* @strerror(i32 %67)
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %68)
%70 = load i32, i32* @errno
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %58
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %58
}