#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct pollfd {
  int fd;
  int /*<<< orphan*/ events;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ s;
typedef int /*<<< orphan*/ enable;
typedef int /*<<< orphan*/ d;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_BROADCAST;
int /*<<< orphan*/ POLLIN;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ close(int);
scalar_t__ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recvfrom(int, char *, int, int /*<<< orphan*/,
                            struct sockaddr *, int *);
scalar_t__ sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              void const *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  printf("Get IP of Squeezebox Server in Network\n");
  printf("Usage: %s [-d]\n", argv[0]);
  printf(" -d Enable DEBUG output\n\n");
  struct sockaddr_in d;
  struct sockaddr_in s;
  char *buf;
  struct pollfd pollinfo;
  int disc_sock = socket(AF_INET, SOCK_DGRAM, 0);
  socklen_t enable = 1;
  setsockopt(disc_sock, SOL_SOCKET, SO_BROADCAST, (const void *)&enable,
             sizeof(enable));
  buf = "e";
  memset(&d, 0, sizeof(d));
  d.sin_family = AF_INET;
  d.sin_port = htons(3483);
  d.sin_addr.s_addr = htonl(INADDR_BROADCAST);
  pollinfo.fd = disc_sock;
  pollinfo.events = POLLIN;
  int test = 0;
  do {
    test++;
    memset(&s, 0, sizeof(s));
    if (sendto(disc_sock, buf, 1, 0, (struct sockaddr *)&d, sizeof(d)) < 0) {
      printf("ERROR sending disovery\n");
    }
    if (poll(&pollinfo, 1, 5000) == 1) {
      char readbuf[10];
      socklen_t slen = sizeof(s);
      recvfrom(disc_sock, readbuf, 10, 0, (struct sockaddr *)&s, &slen);
      printf("SERVER:%s\n", inet_ntoa(s.sin_addr));
    }
  } while (s.sin_addr.s_addr == 0 && test < 3);
  close(disc_sock);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x44(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x44(%rbp),%edi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
mov    0x2d9b(%rip),%rax
mov    (%rax),%edx
lea    -0x48(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    0xe0d(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0xd9b,%edi
call   1050 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %rax,-0x20(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2d2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    -0x44(%rbp),%edi
mov    -0x38(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x1,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1090 <sendto@plt>
cmp    $0x0,%rax
jge    12eb <main+0x13b>
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x1,%esi
mov    $0x1388,%edx
call   10c0 <poll@plt>
cmp    $0x1,%eax
jne    1343 <main+0x193>
movl   $0x10,-0x5c(%rbp)
mov    -0x44(%rbp),%edi
lea    -0x56(%rbp),%rsi
lea    -0x30(%rbp),%r8
mov    $0xa,%edx
xor    %ecx,%ecx
lea    -0x5c(%rbp),%r9
call   10b0 <recvfrom@plt>
mov    -0x30(%rbp),%rdi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xd30(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1348 <main+0x198>
xor    %eax,%eax
cmpq   $0x0,-0x30(%rbp)
mov    %al,-0x5d(%rbp)
jne    1362 <main+0x1b2>
cmpl   $0x3,-0x4c(%rbp)
setl   %al
mov    %al,-0x5d(%rbp)
mov    -0x5d(%rbp),%al
test   $0x1,%al
jne    129d <main+0xed>
mov    -0x44(%rbp),%edi
call   10a0 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rsi
lea    0xe19(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2ddf(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
movl   $0x1,0xc(%rsp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
mov    0x2d9a(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
lea    0x18(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x24(%rsp)
mov    $0xd9b,%edi
call   1060 <htons@plt>
mov    %eax,0x20(%rsp)
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %rax,0x18(%rsp)
mov    %ebx,0x10(%rsp)
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
lea    0x28(%rsp),%r15
lea    0xd75(%rip),%r12
lea    0x10(%rsp),%rbp
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <memset@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0x10,%r9d
call   10a0 <sendto@plt>
test   %rax,%rax
jns    12ea <main+0x12a>
lea    0xd78(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x1388,%edx
call   10d0 <poll@plt>
cmp    $0x1,%eax
jne    133f <main+0x17f>
movl   $0x10,0x8(%rsp)
mov    %ebx,%edi
lea    0x3e(%rsp),%rsi
mov    $0xa,%edx
xor    %ecx,%ecx
mov    %r15,%r8
lea    0x8(%rsp),%r9
call   10c0 <recvfrom@plt>
mov    0x28(%rsp),%rdi
call   1050 <inet_ntoa@plt>
lea    0xcdd(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
cmpq   $0x0,0x28(%rsp)
jne    1358 <main+0x198>
lea    0x1(%r13),%eax
cmp    $0x2,%r13d
mov    %eax,%r13d
jb     12b0 <main+0xf0>
mov    %ebx,%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.pollfd = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [40 x i8] c"Get IP of Squeezebox Server in Network\0A\00"
@.str.1 = [16 x i8] c"Usage: %s [-d]\0A\00"
@.str.2 = [26 x i8] c" -d Enable DEBUG output\0A\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.3 = [2 x i8] c"e\00"
@INADDR_BROADCAST = global i32 0
@POLLIN = global i32 0
@.str.4 = [24 x i8] c"ERROR sending disovery\0A\00"
@.str.5 = [11 x i8] c"SERVER:%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i8*
%9 = alloca %struct.pollfd
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [10 x i8]
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %10
store i32 1, i32* %11
%24 = load i32, i32* %10
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_BROADCAST
%27 = bitcast i32* %11 to i8*
%28 = call i32 @setsockopt(i32 %24, i32 %25, i32 %26, i8* %27, i32 4)
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %8
%29 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 16)
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %30, i32* %31
%32 = call i32 @htons(i32 3483)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %32, i32* %33
%34 = load i32, i32* @INADDR_BROADCAST
%35 = call i64 @htonl(i32 %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
store i64 %35, i64* %37
%38 = load i32, i32* %10
%39 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %9, i32 0, i32 0
store i32 %38, i32* %39
%40 = load i32, i32* @POLLIN
%41 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %9, i32 0, i32 1
store i32 %40, i32* %41
store i32 0, i32* %12
br label %42
42: ; preds = %75, %2
%43 = load i32, i32* %12
%44 = add nsw i32 %43, 1
store i32 %44, i32* %12
%45 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 16)
%46 = load i32, i32* %10
%47 = load i8*, i8** %8
%48 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%49 = call i64 @sendto(i32 %46, i8* %47, i32 1, i32 0, %struct.sockaddr* %48, i32 16)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %42
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %51, %42
%54 = call i32 @poll(%struct.pollfd* %9, i32 1, i32 5000)
%55 = icmp eq i32 %54, 1
br i1 %55, label %56, label %66
56: ; preds = %53
store i32 16, i32* %14
%57 = load i32, i32* %10
%58 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 0
%59 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%60 = call i32 @recvfrom(i32 %57, i8* %58, i32 10, i32 0, %struct.sockaddr* %59, i32* %14)
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%62 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %61, i32 0, i32 0
%63 = load i64, i64* %62
%64 = call i8* @inet_ntoa(i64 %63)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %64)
br label %66
66: ; preds = %56, %53
br label %67
67: ; preds = %66
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%69 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %68, i32 0, i32 0
%70 = load i64, i64* %69
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %67
%73 = load i32, i32* %12
%74 = icmp slt i32 %73, 3
br label %75
75: ; preds = %72, %67
%76 = phi i1 [ false, %67 ], [ %74, %72 ]
br i1 %76, label %42, label %77
77: ; preds = %75
%78 = load i32, i32* %10
%79 = call i32 @close(i32 %78)
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.pollfd = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str.1 = [16 x i8] c"Usage: %s [-d]\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.3 = [2 x i8] c"e\00"
@INADDR_BROADCAST = global i32 0
@POLLIN = global i32 0
@.str.5 = [11 x i8] c"SERVER:%s\0A\00"
@str = [39 x i8] c"Get IP of Squeezebox Server in Network\00"
@str.6 = [25 x i8] c" -d Enable DEBUG output\0A\00"
@str.7 = [23 x i8] c"ERROR sending disovery\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.pollfd
%6 = alloca i32
%7 = alloca [10 x i8]
%8 = alloca i32
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%10 = load i8*, i8** %1
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
%13 = bitcast %struct.sockaddr_in* %3 to i8*
%14 = bitcast %struct.sockaddr_in* %4 to i8*
%15 = bitcast %struct.pollfd* %5 to i8*
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_DGRAM
%18 = tail call i32 @socket(i32 %16, i32 %17, i32 0)
%19 = bitcast i32* %6 to i8*
store i32 1, i32* %6
%20 = load i32, i32* @SOL_SOCKET
%21 = load i32, i32* @SO_BROADCAST
%22 = call i32 @setsockopt(i32 %18, i32 %20, i32 %21, i8* %19, i32 4)
%23 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 16)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %24, i32* %25
%26 = call i32 @htons(i32 3483)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* @INADDR_BROADCAST
%29 = call i64 @htonl(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i64 %29, i64* %30
%31 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 0, i32 0
store i32 %18, i32* %31
%32 = load i32, i32* @POLLIN
%33 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 0, i32 1
store i32 %32, i32* %33
%34 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%36 = bitcast i32* %8 to i8*
%37 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
br label %39
39: ; preds = %55, %2
%40 = phi i32 [ 0, %2 ], [ %41, %55 ]
%41 = add nuw nsw i32 %40, 1
%42 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 16)
%43 = call i64 @sendto(i32 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 0, %struct.sockaddr* %34, i32 16)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %39
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
br label %47
47: ; preds = %45, %39
%48 = call i32 @poll(%struct.pollfd* %5, i32 1, i32 5000)
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %55
50: ; preds = %47
store i32 16, i32* %8
%51 = call i32 @recvfrom(i32 %18, i8* %35, i32 10, i32 0, %struct.sockaddr* %37, i32* %8)
%52 = load i64, i64* %38
%53 = call i8* @inet_ntoa(i64 %52)
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %47, %50
%56 = load i64, i64* %38
%57 = icmp eq i64 %56, 0
%58 = icmp ult i32 %40, 2
%59 = select i1 %57, i1 %58, i1 false
br i1 %59, label %39, label %60
60: ; preds = %55
%61 = call i32 @close(i32 %18)
ret i32 0
}