#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;
};
struct ip_mreq {
  int dummy;
};
typedef int /*<<< orphan*/ addr;

/* 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 *);
scalar_t__ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                  struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
main(int argc, char *argv[]) {
  struct sockaddr_in addr;
  int fd, cnt;
  struct ip_mreq mreq;
  if (argc != 2) {
    printf("bad argument\n");
    exit(1);
  }
  if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("socket");
    exit(1);
  }
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = inet_addr("225.0.0.37");
  addr.sin_port = htons(12346);
  if (sendto(fd, argv[1], strlen(argv[1]), 0, (struct sockaddr *)&addr,
             sizeof(addr)) < 0) {
    perror("sendto");
    exit(1);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
je     11cf <main+0x2f>
lea    0xe40(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    120a <main+0x6a>
lea    0xe13(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xde8(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x303a,%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
cmp    $0x0,%rax
jge    129b <main+0xfb>
lea    0xd94(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    124d <main+0xad>
mov    %rsi,%r14
mov    0x2e2b(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     1263 <main+0xc3>
mov    %eax,%ebp
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
lea    0xe0d(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    $0x303a,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x8(%r14),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
test   %rax,%rax
js     126c <main+0xcc>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd96(%rip),%rdi
jmp    1273 <main+0xd3>
lea    0xd9f(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.ip_mreq = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"bad argument\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [11 x i8] c"225.0.0.37\00"
@.str.3 = [7 x i8] c"sendto\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.ip_mreq
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
store i32 %17, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 12)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %24, i32* %25
%26 = call i32 @inet_addr(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
store i32 %26, i32* %28
%29 = call i32 @htons(i32 12346)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i32 %29, i32* %30
%31 = load i32, i32* %6
%32 = load i8**, i8*** %4
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = load i8**, i8*** %4
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @strlen(i8* %37)
%39 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%40 = call i64 @sendto(i32 %31, i8* %34, i32 %38, i32 0, %struct.sockaddr* %39, i32 12)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %22
%43 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %22
%46 = load i32, i32* %6
%47 = call i32 @close(i32 %46)
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.1 = [7 x i8] c"socket\00"
@.str.2 = [11 x i8] c"225.0.0.37\00"
@.str.3 = [7 x i8] c"sendto\00"
@str = [13 x i8] c"bad argument\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %19, i32* %20
%21 = call i32 @inet_addr(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %21, i32* %22
%23 = call i32 @htons(i32 12346)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %23, i32* %24
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strlen(i8* %26)
%28 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%29 = call i64 @sendto(i32 %12, i8* %26, i32 %27, i32 0, %struct.sockaddr* %28, i32 12)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %17
%32 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %17
%35 = call i32 @close(i32 %12)
ret i32 0
}