#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__ {
  scalar_t__ s_addr;
};
struct sockaddr_in {
  short sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ echoserver;
typedef int /*<<< orphan*/ echoclient;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ Die(char *);
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ MSG_DONTWAIT;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
short multicast();
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
             unsigned int *);
unsigned int sendto(int, char *, unsigned int, int /*<<< orphan*/,
                    struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
unsigned int strlen(char *);
int main(int argc, char *argv[]) {
  int sock;
  short port;
  struct sockaddr_in echoserver;
  struct sockaddr_in echoclient;
  char buffer[255];
  unsigned int echolen, clientlen;
  int received = 0;
  if (argc != 3) {
    fprintf(stderr, "USAGE: %s <server_ip> <word> \n", argv[0]);
    exit(1);
  }
  port = multicast();
  if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
    Die("Failed to create socket");
  }
  memset(&echoserver, 0, sizeof(echoserver));
  echoserver.sin_family = AF_INET;
  echoserver.sin_addr.s_addr = inet_addr(argv[1]);
  echoserver.sin_port = port;
  echolen = strlen(argv[2]);
  if (sendto(sock, argv[2], echolen, MSG_DONTWAIT,
             (struct sockaddr *)&echoserver, sizeof(echoserver)) != echolen) {
    Die("Mismatch in number of sent bytes");
  }
  fprintf(stdout, "Received: ");
  clientlen = sizeof(echoclient);
  if ((received = recvfrom(sock, buffer, 255, 0, (struct sockaddr *)&echoclient,
                           &clientlen)) != echolen) {
    Die("Mismatch in number of received bytes");
  }
  if (echoserver.sin_addr.s_addr != echoclient.sin_addr.s_addr) {
    Die("Received a packet from an unexpected server");
  }
  buffer[received] = '\0';
  fprintf(stdout, buffer);
  fprintf(stdout, "\n");
  close(sock);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x15c(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1205 <main+0x55>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   10a0 <multicast@plt>
mov    %ax,-0x16(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
mov    0x2d7f(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1248 <main+0x98>
lea    0xddc(%rip),%rdi
call   10b0 <Die@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <inet_addr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x16(%rbp),%ax
mov    %ax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x154(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x154(%rbp),%edx
mov    0x2d18(%rip),%rax
mov    (%rax),%ecx
lea    -0x30(%rbp),%r8
mov    $0x18,%r9d
call   1050 <sendto@plt>
cmp    -0x154(%rbp),%eax
je     12d1 <main+0x121>
lea    0xd6b(%rip),%rdi
call   10b0 <Die@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x18,-0x158(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x150(%rbp),%rsi
lea    -0x48(%rbp),%r8
mov    $0xff,%edx
xor    %ecx,%ecx
lea    -0x158(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0x15c(%rbp)
cmp    -0x154(%rbp),%eax
je     1331 <main+0x181>
lea    0xd37(%rip),%rdi
call   10b0 <Die@plt>
mov    -0x28(%rbp),%rax
cmp    -0x40(%rbp),%rax
je     134b <main+0x19b>
lea    0xd42(%rip),%rdi
call   10b0 <Die@plt>
movslq -0x15c(%rbp),%rax
movb   $0x0,-0x150(%rbp,%rax,1)
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
lea    -0x150(%rbp),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c40(%rip),%rax
mov    (%rax),%edi
lea    0xc9c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x148,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1313 <main+0x163>
xor    %eax,%eax
call   10a0 <multicast@plt>
mov    %eax,%ebp
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    0x2dbd(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1205 <main+0x55>
lea    0xe1f(%rip),%rdi
call   10b0 <Die@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x8(%rbx),%rdi
call   1070 <inet_addr@plt>
mov    %rax,0x18(%rsp)
mov    %bp,0x10(%rsp)
mov    0x10(%rbx),%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rsi
mov    0x2d71(%rip),%rax
mov    (%rax),%ecx
mov    %r14d,%edi
mov    %ebp,%edx
mov    %r15,%r8
mov    $0x18,%r9d
call   1050 <sendto@plt>
cmp    %ebp,%eax
je     1274 <main+0xc4>
lea    0xdc8(%rip),%rdi
call   10b0 <Die@plt>
mov    0x2d3d(%rip),%r15
mov    (%r15),%edi
lea    0xdd3(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
movl   $0x18,0xc(%rsp)
lea    0x40(%rsp),%rsi
lea    0x28(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r14d,%edi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1090 <recvfrom@plt>
mov    %eax,%ebx
cmp    %ebp,%eax
je     12c4 <main+0x114>
lea    0xda4(%rip),%rdi
call   10b0 <Die@plt>
mov    0x18(%rsp),%rax
cmp    0x30(%rsp),%rax
je     12dc <main+0x12c>
lea    0xdb1(%rip),%rdi
call   10b0 <Die@plt>
movslq %ebx,%rax
movb   $0x0,0x40(%rsp,%rax,1)
mov    (%r15),%edi
lea    0x40(%rsp),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r15),%edi
lea    0xd20(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14d,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xcda(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i16, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"USAGE: %s <server_ip> <word> \0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [24 x i8] c"Failed to create socket\00"
@AF_INET = global i32 0
@MSG_DONTWAIT = global i32 0
@.str.2 = [33 x i8] c"Mismatch in number of sent bytes\00"
@stdout = global i32 0
@.str.3 = [11 x i8] c"Received: \00"
@.str.4 = [37 x i8] c"Mismatch in number of received bytes\00"
@.str.5 = [44 x i8] c"Received a packet from an unexpected server\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i16
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca [255 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %13
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = call signext i16 (...) @multicast()
store i16 %24, i16* %7
%25 = load i32, i32* @PF_INET
%26 = load i32, i32* @SOCK_DGRAM
%27 = load i32, i32* @IPPROTO_UDP
%28 = call i32 @socket(i32 %25, i32 %26, i32 %27)
store i32 %28, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = call i32 @Die(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %23
%33 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 24)
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %34, i32* %35
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i64 @inet_addr(i8* %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%41 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %40, i32 0, i32 0
store i64 %39, i64* %41
%42 = load i16, i16* %7
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i16 %42, i16* %43
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @strlen(i8* %46)
store i32 %47, i32* %11
%48 = load i32, i32* %6
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = load i32, i32* %11
%53 = load i32, i32* @MSG_DONTWAIT
%54 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%55 = call i32 @sendto(i32 %48, i8* %51, i32 %52, i32 %53, %struct.sockaddr* %54, i32 24)
%56 = load i32, i32* %11
%57 = icmp ne i32 %55, %56
br i1 %57, label %58, label %60
58: ; preds = %32
%59 = call i32 @Die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %60
60: ; preds = %58, %32
%61 = load i32, i32* @stdout
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i32 24, i32* %12
%63 = load i32, i32* %6
%64 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%65 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%66 = call i32 @recvfrom(i32 %63, i8* %64, i32 255, i32 0, %struct.sockaddr* %65, i32* %12)
store i32 %66, i32* %13
%67 = load i32, i32* %11
%68 = icmp ne i32 %66, %67
br i1 %68, label %69, label %71
69: ; preds = %60
%70 = call i32 @Die(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %71
71: ; preds = %69, %60
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%73 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %72, i32 0, i32 0
%74 = load i64, i64* %73
%75 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%76 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %75, i32 0, i32 0
%77 = load i64, i64* %76
%78 = icmp ne i64 %74, %77
br i1 %78, label %79, label %81
79: ; preds = %71
%80 = call i32 @Die(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
br label %81
81: ; preds = %79, %71
%82 = load i32, i32* %13
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 %83
store i8 0, i8* %84
%85 = load i32, i32* @stdout
%86 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* %86)
%88 = load i32, i32* @stdout
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%90 = load i32, i32* %6
%91 = call i32 @close(i32 %90)
%92 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i16, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"USAGE: %s <server_ip> <word> \0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [24 x i8] c"Failed to create socket\00"
@AF_INET = global i32 0
@MSG_DONTWAIT = global i32 0
@.str.2 = [33 x i8] c"Mismatch in number of sent bytes\00"
@stdout = global i32 0
@.str.3 = [11 x i8] c"Received: \00"
@.str.4 = [37 x i8] c"Mismatch in number of received bytes\00"
@.str.5 = [44 x i8] c"Received a packet from an unexpected server\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca [255 x i8]
%6 = alloca i32
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%10 = bitcast i32* %6 to i8*
%11 = icmp eq i32 %0, 3
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = tail call signext i16 (...) @multicast()
%19 = load i32, i32* @PF_INET
%20 = load i32, i32* @SOCK_DGRAM
%21 = load i32, i32* @IPPROTO_UDP
%22 = tail call i32 @socket(i32 %19, i32 %20, i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = tail call i32 @Die(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %17
%27 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 24)
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %28, i32* %29
%30 = getelementptr inbounds i8*, i8** %1, i64 1
%31 = load i8*, i8** %30
%32 = call i64 @inet_addr(i8* %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i64 %32, i64* %33
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i16 %18, i16* %34
%35 = getelementptr inbounds i8*, i8** %1, i64 2
%36 = load i8*, i8** %35
%37 = call i32 @strlen(i8* %36)
%38 = load i8*, i8** %35
%39 = load i32, i32* @MSG_DONTWAIT
%40 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%41 = call i32 @sendto(i32 %22, i8* %38, i32 %37, i32 %39, %struct.sockaddr* %40, i32 24)
%42 = icmp eq i32 %41, %37
br i1 %42, label %45, label %43
43: ; preds = %26
%44 = call i32 @Die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %26
%46 = load i32, i32* @stdout
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i32 24, i32* %6
%48 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%49 = call i32 @recvfrom(i32 %22, i8* %9, i32 255, i32 0, %struct.sockaddr* %48, i32* %6)
%50 = icmp eq i32 %49, %37
br i1 %50, label %53, label %51
51: ; preds = %45
%52 = call i32 @Die(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %51, %45
%54 = load i64, i64* %33
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%56 = load i64, i64* %55
%57 = icmp eq i64 %54, %56
br i1 %57, label %60, label %58
58: ; preds = %53
%59 = call i32 @Die(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
br label %60
60: ; preds = %58, %53
%61 = sext i32 %49 to i64
%62 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 %61
store i8 0, i8* %62
%63 = load i32, i32* @stdout
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* %9)
%65 = load i32, i32* @stdout
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%67 = call i32 @close(i32 %22)
%68 = call i32 @exit(i32 0)
unreachable
}