#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__ {
  void *s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct in_addr {
  void *s_addr;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ UsbipGroupSock;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
char *get_iface_addr();
int /*<<< orphan*/ htons(int);
void *inet_addr(char const *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ multicast_set_ip_iface(int, struct in_addr *);
int /*<<< orphan*/ multicast_set_socket_timeout(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sendto(int, char **, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int announce_client_event(void) {
  struct in_addr LocalIface;
  struct sockaddr_in UsbipGroupSock;
  int sockfd;
  int ret = 0;
  char ack[] = "1";
  const char *iface_name;
  socklen_t socklen;
  memset(&UsbipGroupSock, 0, sizeof(UsbipGroupSock));
  iface_name = get_iface_addr();
  if (iface_name == NULL) {
    printf("Can't find wireless interface\n");
    return -1;
  }
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd < 0) {
    perror("failed to create socket");
    return -1;
  }
  UsbipGroupSock.sin_family = AF_INET;
  UsbipGroupSock.sin_port = htons(10297);
  UsbipGroupSock.sin_addr.s_addr = inet_addr("239.255.0.1");
  LocalIface.s_addr = inet_addr(iface_name);
  multicast_set_ip_iface(sockfd, &LocalIface);
  multicast_set_socket_timeout(sockfd, 1, 0);
  socklen = sizeof(UsbipGroupSock);
  if ((ret = sendto(sockfd, &ack, strlen(ack), 0,
                    (struct sockaddr *)&UsbipGroupSock, socklen)) < 0) {
    printf("multicast_event: sendto error\n");
  }
  close(sockfd);
  return ret;
}


x86 assembly (clang, -O0):
<announce_client_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x28(%rbp)
mov    0xe6b(%rip),%ax
mov    %ax,-0x2a(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    $0x0,%al
call   10d0 <get_iface_addr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1218 <announce_client_event+0x58>
lea    0xdf9(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <announce_client_event+0x143>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1256 <announce_client_event+0x96>
lea    0xdda(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <announce_client_event+0x143>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x2839,%edi
call   1050 <htons@plt>
mov    %eax,-0x18(%rbp)
lea    0xdc1(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   10b0 <multicast_set_ip_iface@plt>
mov    -0x24(%rbp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <multicast_set_socket_timeout@plt>
movl   $0x10,-0x3c(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    -0x2a(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x2a(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
lea    -0x20(%rbp),%r8
mov    -0x3c(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    12f5 <announce_client_event+0x135>
lea    0xd53(%rip),%rdi
call   1060 <printf@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<announce_client_event>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movw   $0x31,0x6(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
xor    %eax,%eax
call   10d0 <get_iface_addr@plt>
test   %rax,%rax
je     12a5 <announce_client_event+0xe5>
mov    %rax,%rbx
mov    0x2dee(%rip),%r14
mov    (%r14),%edi
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     12c1 <announce_client_event+0x101>
mov    %eax,%ebp
mov    (%r14),%eax
mov    %eax,0x14(%rsp)
mov    $0x2839,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0xde5(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,0x8(%rsp)
mov    %rbx,%rdi
call   10a0 <inet_addr@plt>
mov    %rax,0x18(%rsp)
lea    0x18(%rsp),%rsi
mov    %ebp,%edi
call   10b0 <multicast_set_ip_iface@plt>
mov    %ebp,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <multicast_set_socket_timeout@plt>
lea    0x6(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x8(%rsp),%r8
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1080 <sendto@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    129c <announce_client_event+0xdc>
lea    0xd8d(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   1090 <close@plt>
jmp    12b6 <announce_client_event+0xf6>
lea    0xd96(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd38(%rip),%rdi
call   10c0 <perror@plt>
jmp    12b1 <announce_client_event+0xf1>

LLVM IR (-O0):
%struct.in_addr = type { i8* }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@__const.announce_client_event.ack = [2 x i8] c"1\00"
@.str = [31 x i8] c"Can't find wireless interface\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [24 x i8] c"failed to create socket\00"
@.str.2 = [12 x i8] c"239.255.0.1\00"
@.str.3 = [31 x i8] c"multicast_event: sendto error\0A\00"
define i32 @announce_client_event() {
%1 = alloca i32
%2 = alloca %struct.in_addr
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x i8]
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %5
%9 = bitcast [2 x i8]* %6 to i8*
%10 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 16)
%11 = call i8* (...) @get_iface_addr()
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %53
16: ; preds = %0
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_DGRAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %53
24: ; preds = %16
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %25, i32* %26
%27 = call i32 @htons(i32 10297)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %27, i32* %28
%29 = call i8* @inet_addr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
store i8* %29, i8** %31
%32 = load i8*, i8** %7
%33 = call i8* @inet_addr(i8* %32)
%34 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i32 0, i32 0
store i8* %33, i8** %34
%35 = load i32, i32* %4
%36 = call i32 @multicast_set_ip_iface(i32 %35, %struct.in_addr* %2)
%37 = load i32, i32* %4
%38 = call i32 @multicast_set_socket_timeout(i32 %37, i32 1, i32 0)
store i32 16, i32* %8
%39 = load i32, i32* %4
%40 = bitcast [2 x i8]* %6 to i8**
%41 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%44 = load i32, i32* %8
%45 = call i32 @sendto(i32 %39, i8** %40, i32 %42, i32 0, %struct.sockaddr* %43, i32 %44)
store i32 %45, i32* %5
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %24
%48 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %24
%50 = load i32, i32* %4
%51 = call i32 @close(i32 %50)
%52 = load i32, i32* %5
store i32 %52, i32* %1
br label %53
53: ; preds = %49, %22, %14
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
%struct.in_addr = type { i8* }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [24 x i8] c"failed to create socket\00"
@.str.2 = [12 x i8] c"239.255.0.1\00"
@str = [30 x i8] c"multicast_event: sendto error\00"
@str.4 = [30 x i8] c"Can't find wireless interface\00"
define i32 @announce_client_event() {
%1 = alloca %struct.in_addr
%2 = alloca %struct.sockaddr_in
%3 = alloca i16
%4 = bitcast %struct.in_addr* %1 to i8*
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = bitcast i16* %3 to i8*
store i16 49, i16* %3
%7 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 16)
%8 = call i8* (...) @get_iface_addr()
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.4, i64 0, i64 0))
br label %39
12: ; preds = %0
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %39
19: ; preds = %12
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @htons(i32 10297)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %22, i32* %23
%24 = call i8* @inet_addr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i8* %24, i8** %25
%26 = call i8* @inet_addr(i8* %8)
%27 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %1, i64 0, i32 0
store i8* %26, i8** %27
%28 = call i32 @multicast_set_ip_iface(i32 %15, %struct.in_addr* %1)
%29 = call i32 @multicast_set_socket_timeout(i32 %15, i32 1, i32 0)
%30 = bitcast i16* %3 to i8**
%31 = call i32 @strlen(i8* %6)
%32 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%33 = call i32 @sendto(i32 %15, i8** %30, i32 %31, i32 0, %struct.sockaddr* %32, i32 16)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %19
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %37
37: ; preds = %35, %19
%38 = call i32 @close(i32 %15)
br label %39
39: ; preds = %37, %17, %10
%40 = phi i32 [ -1, %10 ], [ -1, %17 ], [ %33, %37 ]
ret i32 %40
}