#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*/ mcastTTL;
typedef int /*<<< orphan*/ mcastAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ IP_MULTICAST_TTL;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
void *atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htons(unsigned int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int sendto(int, char *, unsigned int, int /*<<< orphan*/, struct sockaddr *,
           int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, void *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
unsigned int strlen(char *);
int main(int argc, char *argv[]) {
  char *mcastIP;
  unsigned int mcastPort;
  char *sendString;
  unsigned int sendStringLen;
  int sock;
  unsigned char mcastTTL;
  struct sockaddr_in mcastAddr;
  int sendMsgLen;
  if ((argc < 4) || (argc > 5)) {
    fprintf(stderr,
            "Usage: %s <Multicast IP Address> <Port> <Send String> [<TTL>]\n",
            argv[0]);
    exit(1);
  }
  mcastIP = argv[1];
  mcastPort = atoi(argv[2]);
  sendString = argv[3];
  sendStringLen = strlen(sendString);
  if (argc == 5) {
    mcastTTL = atoi(argv[4]);
  } else {
    mcastTTL = 1;
  }
  sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if (sock < 0) {
    fprintf(stderr, "socket() failed\n");
    exit(1);
  }
  if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, (void *)&mcastTTL,
                 sizeof(mcastTTL)) < 0) {
    fprintf(stderr, "setsockopt() failed\n");
    exit(1);
  }
  memset(&mcastAddr, 0, sizeof(mcastAddr));
  mcastAddr.sin_family = AF_INET;
  mcastAddr.sin_addr.s_addr = inet_addr(mcastIP);
  mcastAddr.sin_port = htons(mcastPort);
  sendMsgLen = sendto(sock, sendString, sendStringLen, 0,
                      (struct sockaddr *)&mcastAddr, sizeof(mcastAddr));
  if (sendMsgLen != sendStringLen) {
    fprintf(stderr,
            "sendto() sent a different number of bytes than expected\n");
    exit(1);
  }
  close(sock);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     11da <main+0x2a>
cmpl   $0x5,-0x8(%rbp)
jle    1202 <main+0x52>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe0f(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x5,-0x8(%rbp)
jne    1255 <main+0xa5>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10b0 <atoi@plt>
mov    %al,-0x31(%rbp)
jmp    1259 <main+0xa9>
movb   $0x1,-0x31(%rbp)
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
mov    0x2d36(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    12a7 <main+0xf7>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x30(%rbp),%edi
mov    0x2d2f(%rip),%rax
mov    (%rax),%esi
mov    0x2d06(%rip),%rax
mov    (%rax),%edx
lea    -0x31(%rbp),%rcx
mov    $0x1,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    12f6 <main+0x146>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
lea    0xd6b(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2cdb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    -0x40(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x2c(%rbp),%eax
je     1374 <main+0x1c4>
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
lea    0xd02(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x30(%rbp),%edi
call   1080 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    -0x6(%rbx),%eax
cmp    $0xfffffffd,%eax
ja     11f0 <main+0x40>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xe21(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x8(%rbp),%r14
mov    0x10(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %rax,%r15
mov    0x18(%rbp),%r13
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    $0x1,%al
cmp    $0x5,%ebx
jne    121f <main+0x6f>
mov    0x20(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %al,0x7(%rsp)
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
mov    0x2d6c(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
test   %eax,%eax
jns    125c <main+0xac>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
jmp    130d <main+0x15d>
mov    %eax,%ebp
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
mov    0x2d52(%rip),%rax
mov    (%rax),%edx
lea    0x7(%rsp),%rcx
mov    %ebp,%edi
mov    $0x1,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jns    1299 <main+0xe9>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
jmp    130d <main+0x15d>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %r14,%rdi
call   1090 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    %r15d,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r12d,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
cmp    %r12d,%eax
jne    12fd <main+0x14d>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
lea    0xd58(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%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 }
@stderr = global i32 0
@.str = [63 x i8] c"Usage: %s <Multicast IP Address> <Port> <Send String> [<TTL>]\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [17 x i8] c"socket() failed\0A\00"
@IPPROTO_IP = global i32 0
@IP_MULTICAST_TTL = global i32 0
@.str.2 = [21 x i8] c"setsockopt() failed\0A\00"
@AF_INET = global i32 0
@.str.3 = [57 x i8] c"sendto() sent a different number of bytes than expected\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 4
br i1 %15, label %19, label %16
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 5
br i1 %18, label %19, label %26
19: ; preds = %16, %2
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %16
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
store i8* %29, i8** %6
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i8* @atoi(i8* %32)
%34 = ptrtoint i8* %33 to i32
store i32 %34, i32* %7
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 3
%37 = load i8*, i8** %36
store i8* %37, i8** %8
%38 = load i8*, i8** %8
%39 = call i32 @strlen(i8* %38)
store i32 %39, i32* %9
%40 = load i32, i32* %4
%41 = icmp eq i32 %40, 5
br i1 %41, label %42, label %48
42: ; preds = %26
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 4
%45 = load i8*, i8** %44
%46 = call i8* @atoi(i8* %45)
%47 = ptrtoint i8* %46 to i8
store i8 %47, i8* %11
br label %49
48: ; preds = %26
store i8 1, i8* %11
br label %49
49: ; preds = %48, %42
%50 = load i32, i32* @PF_INET
%51 = load i32, i32* @SOCK_DGRAM
%52 = load i32, i32* @IPPROTO_UDP
%53 = call i32 @socket(i32 %50, i32 %51, i32 %52)
store i32 %53, i32* %10
%54 = load i32, i32* %10
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %49
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %49
%61 = load i32, i32* %10
%62 = load i32, i32* @IPPROTO_IP
%63 = load i32, i32* @IP_MULTICAST_TTL
%64 = call i64 @setsockopt(i32 %61, i32 %62, i32 %63, i8* %11, i32 1)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %60
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %60
%71 = call i32 @memset(%struct.sockaddr_in* %12, i32 0, i32 12)
%72 = load i32, i32* @AF_INET
%73 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %72, i32* %73
%74 = load i8*, i8** %6
%75 = call i32 @inet_addr(i8* %74)
%76 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%77 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %76, i32 0, i32 0
store i32 %75, i32* %77
%78 = load i32, i32* %7
%79 = call i32 @htons(i32 %78)
%80 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
store i32 %79, i32* %80
%81 = load i32, i32* %10
%82 = load i8*, i8** %8
%83 = load i32, i32* %9
%84 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%85 = call i32 @sendto(i32 %81, i8* %82, i32 %83, i32 0, %struct.sockaddr* %84, i32 12)
store i32 %85, i32* %13
%86 = load i32, i32* %13
%87 = load i32, i32* %9
%88 = icmp ne i32 %86, %87
br i1 %88, label %89, label %93
89: ; preds = %70
%90 = load i32, i32* @stderr
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0))
%92 = call i32 @exit(i32 1)
unreachable
93: ; preds = %70
%94 = load i32, i32* %10
%95 = call i32 @close(i32 %94)
%96 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [63 x i8] c"Usage: %s <Multicast IP Address> <Port> <Send String> [<TTL>]\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [17 x i8] c"socket() failed\0A\00"
@IPPROTO_IP = global i32 0
@IP_MULTICAST_TTL = global i32 0
@.str.2 = [21 x i8] c"setsockopt() failed\0A\00"
@AF_INET = global i32 0
@.str.3 = [57 x i8] c"sendto() sent a different number of bytes than expected\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.sockaddr_in* %4 to i8*
%6 = add i32 %0, -6
%7 = icmp ult i32 %6, -2
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i8* @atoi(i8* %17)
%19 = ptrtoint i8* %18 to i64
%20 = trunc i64 %19 to i32
%21 = getelementptr inbounds i8*, i8** %1, i64 3
%22 = load i8*, i8** %21
%23 = tail call i32 @strlen(i8* %22)
%24 = icmp eq i32 %0, 5
br i1 %24, label %25, label %31
25: ; preds = %13
%26 = getelementptr inbounds i8*, i8** %1, i64 4
%27 = load i8*, i8** %26
%28 = tail call i8* @atoi(i8* %27)
%29 = ptrtoint i8* %28 to i64
%30 = trunc i64 %29 to i8
br label %31
31: ; preds = %13, %25
%32 = phi i8 [ %30, %25 ], [ 1, %13 ]
store i8 %32, i8* %3
%33 = load i32, i32* @PF_INET
%34 = load i32, i32* @SOCK_DGRAM
%35 = load i32, i32* @IPPROTO_UDP
%36 = tail call i32 @socket(i32 %33, i32 %34, i32 %35)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %31
%43 = load i32, i32* @IPPROTO_IP
%44 = load i32, i32* @IP_MULTICAST_TTL
%45 = call i64 @setsockopt(i32 %36, i32 %43, i32 %44, i8* %3, i32 1)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %42
%52 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%53 = load i32, i32* @AF_INET
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %53, i32* %54
%55 = call i32 @inet_addr(i8* %15)
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %55, i32* %56
%57 = call i32 @htons(i32 %20)
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %57, i32* %58
%59 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%60 = call i32 @sendto(i32 %36, i8* %22, i32 %23, i32 0, %struct.sockaddr* %59, i32 12)
%61 = icmp eq i32 %60, %23
br i1 %61, label %66, label %62
62: ; preds = %51
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %51
%67 = call i32 @close(i32 %36)
%68 = call i32 @exit(i32 0)
unreachable
}