#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int s_addr;
};
struct sockaddr_in {
  TYPE_2__ sin_addr;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
struct TYPE_3__ {
  int /*<<< orphan*/ s_addr;
};
struct ip_mreq {
  TYPE_2__ imr_multiaddr;
  TYPE_1__ imr_interface;
};
typedef int /*<<< orphan*/ one;
typedef int /*<<< orphan*/ mreq;

/* Variables and functions */
scalar_t__ EADDRNOTAVAIL;
void *INADDR_ANY;
scalar_t__ IN_CLASSD(int /*<<< orphan*/);
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_ADD_MEMBERSHIP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
scalar_t__ bind(int, struct sockaddr *, int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htonl(void *);
int /*<<< orphan*/ htons(scalar_t__);
int /*<<< orphan*/ ntohl(int);
scalar_t__ ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage(char *);
int open_network(char *host, int data, int sock[], struct sockaddr_in *sin) {
  struct ip_mreq mreq;
  int i;
  int nfds = 0;
  extern int hpt(char *h, struct sockaddr *sa, unsigned char *ttl);
  if (hpt(host, (struct sockaddr *)sin, 0) < 0) {
    usage("");
    exit(1);
  }
  if (sin->sin_addr.s_addr == -1) {
    fprintf(stderr, "Invalid multicast.\n");
    usage("");
    exit(1);
  }
  if (host) {
    mreq.imr_multiaddr = sin->sin_addr;
    mreq.imr_interface.s_addr = htonl(INADDR_ANY);
    sin->sin_addr = mreq.imr_multiaddr;
  } else {
    mreq.imr_multiaddr.s_addr = INADDR_ANY;
    sin->sin_addr.s_addr = INADDR_ANY;
  }
  for (i = 0; i < 2; i++) {
    int one = 1;
    sock[i] = -1;
    if (!data && i == 0)
      continue;
    sock[i] = socket(PF_INET, SOCK_DGRAM, 0);
    if (sock[i] < 0) {
      perror("socket");
      exit(1);
    }
    if (sock[i] > nfds)
      nfds = sock[i];
    if (IN_CLASSD(ntohl(mreq.imr_multiaddr.s_addr))) {
      if (setsockopt(sock[i], SOL_SOCKET, SO_REUSEADDR, (char *)&one,
                     sizeof(one)) == -1)
        perror("setsockopt: reuseaddr");
    }
    sin->sin_port = htons(ntohs(sin->sin_port) + i);
    if (bind(sock[i], (struct sockaddr *)sin, sizeof(*sin)) < 0) {
      if (errno == EADDRNOTAVAIL) {
        sin->sin_addr.s_addr = INADDR_ANY;
        if (bind(sock[i], (struct sockaddr *)sin, sizeof(*sin)) < 0) {
          perror("bind");
          exit(1);
        }
      } else {
        perror("bind");
        exit(1);
      }
    }
    if (IN_CLASSD(ntohl(mreq.imr_multiaddr.s_addr))) {
      if (setsockopt(sock[i], IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&mreq,
                     sizeof(mreq)) < 0) {
        perror("IP_ADD_MEMBERSHIP");
        exit(1);
      }
    }
  }
  return nfds;
}


x86 assembly (clang, -O0):
<open_network>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10b0 <hpt@plt>
cmp    $0x0,%eax
jge    121e <open_network+0x4e>
lea    0xe04(%rip),%rdi
call   1080 <usage@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    1256 <open_network+0x86>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xdcc(%rip),%rdi
call   1080 <usage@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpq   $0x0,-0x8(%rbp)
je     128a <open_network+0xba>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d57(%rip),%rax
mov    (%rax),%rdi
call   1050 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %ecx,(%rax)
jmp    12a9 <open_network+0xd9>
mov    0x2d37(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x28(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x2,-0x2c(%rbp)
jge    1500 <open_network+0x330>
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
cmpl   $0x0,-0xc(%rbp)
jne    12e9 <open_network+0x119>
cmpl   $0x0,-0x2c(%rbp)
jne    12e9 <open_network+0x119>
jmp    14f2 <open_network+0x322>
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
mov    0x2cc7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jge    1337 <open_network+0x167>
lea    0xcec(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x30(%rbp),%eax
jle    1359 <open_network+0x189>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%edi
call   10d0 <ntohl@plt>
mov    %eax,%edi
call   10f0 <IN_CLASSD@plt>
cmp    $0x0,%rax
je     13b8 <open_network+0x1e8>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    0x2c64(%rip),%rax
mov    (%rax),%esi
mov    0x2c0b(%rip),%rax
mov    (%rax),%edx
lea    -0x34(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    13b3 <open_network+0x1e3>
lea    0xc6d(%rip),%rdi
call   10a0 <perror@plt>
jmp    13b8 <open_network+0x1e8>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
call   1070 <ntohs@plt>
mov    %rax,%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
call   1040 <htons@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1090 <bind@plt>
cmp    $0x0,%rax
jge    1484 <open_network+0x2b4>
mov    0x2ba2(%rip),%rax
mov    (%rax),%rax
mov    0x2bc8(%rip),%rcx
cmp    (%rcx),%rax
jne    1469 <open_network+0x299>
mov    0x2ba8(%rip),%rax
mov    (%rax),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1090 <bind@plt>
cmp    $0x0,%rax
jge    1464 <open_network+0x294>
lea    0xbdc(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    147f <open_network+0x2af>
lea    0xbc1(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    1484 <open_network+0x2b4>
mov    -0x28(%rbp),%edi
call   10d0 <ntohl@plt>
mov    %eax,%edi
call   10f0 <IN_CLASSD@plt>
cmp    $0x0,%rax
je     14ed <open_network+0x31d>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    0x2b21(%rip),%rax
mov    (%rax),%esi
mov    0x2b28(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%eax
jge    14e8 <open_network+0x318>
lea    0xb5d(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    14ed <open_network+0x31d>
jmp    14f2 <open_network+0x322>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12b0 <open_network+0xe0>
mov    -0x30(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_network>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r15
mov    %rcx,%rsi
xor    %edx,%edx
call   10b0 <hpt@plt>
test   %eax,%eax
js     13f1 <open_network+0x221>
mov    (%r14),%r12d
cmp    $0xffffffff,%r12d
je     13dc <open_network+0x20c>
mov    0x2db9(%rip),%rax
mov    (%rax),%rdi
test   %r15,%r15
je     1222 <open_network+0x52>
call   1050 <htonl@plt>
mov    %eax,0xc(%rsp)
jmp    1225 <open_network+0x55>
mov    %edi,%r12d
mov    %r12d,0x8(%rsp)
mov    %r12d,(%r14)
xor    %r12d,%r12d
mov    $0x1,%r15b
xor    %r13d,%r13d
jmp    1256 <open_network+0x86>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%r12d
test   $0x1,%r15b
mov    $0x0,%r15d
je     13a2 <open_network+0x1d2>
movl   $0x1,0x14(%rsp)
movl   $0xffffffff,(%rbx,%r12,4)
ff
test   %ebp,%ebp
jne    1270 <open_network+0xa0>
test   $0x1,%r15b
jne    1240 <open_network+0x70>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,(%rbx,%r12,4)
test   %eax,%eax
js     13b4 <open_network+0x1e4>
cmp    %r13d,%eax
cmovg  %eax,%r13d
mov    0x8(%rsp),%edi
call   10d0 <ntohl@plt>
mov    %eax,%edi
call   10f0 <IN_CLASSD@plt>
test   %rax,%rax
je     12e0 <open_network+0x110>
mov    (%rbx,%r12,4),%edi
mov    0x2d2c(%rip),%rax
mov    (%rax),%esi
mov    0x2cd3(%rip),%rax
mov    (%rax),%edx
lea    0x14(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1391 <open_network+0x1c1>
mov    0x4(%r14),%edi
call   1070 <ntohs@plt>
lea    (%rax,%r12,1),%rdi
call   1040 <htons@plt>
mov    %eax,0x4(%r14)
mov    (%rbx,%r12,4),%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1090 <bind@plt>
test   %rax,%rax
jns    1348 <open_network+0x178>
mov    0x2c95(%rip),%rax
mov    (%rax),%rax
mov    0x2cbb(%rip),%rcx
cmp    (%rcx),%rax
jne    13bd <open_network+0x1ed>
mov    0x2c9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r14)
mov    (%rbx,%r12,4),%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1090 <bind@plt>
test   %rax,%rax
js     13bd <open_network+0x1ed>
mov    0x8(%rsp),%edi
call   10d0 <ntohl@plt>
mov    %eax,%edi
call   10f0 <IN_CLASSD@plt>
test   %rax,%rax
je     1240 <open_network+0x70>
mov    (%rbx,%r12,4),%edi
mov    0x2c64(%rip),%rax
mov    (%rax),%esi
mov    0x2c6b(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
jns    1240 <open_network+0x70>
jmp    13c6 <open_network+0x1f6>
lea    0xc83(%rip),%rdi
call   10a0 <perror@plt>
jmp    12e0 <open_network+0x110>
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc59(%rip),%rdi
jmp    13cd <open_network+0x1fd>
lea    0xc6d(%rip),%rdi
jmp    13cd <open_network+0x1fd>
lea    0xc69(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2bcd(%rip),%rax
mov    (%rax),%edi
lea    0xc14(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xc1b(%rip),%rdi
call   1080 <usage@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.ip_mreq = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [20 x i8] c"Invalid multicast.\0A\00"
@INADDR_ANY = global i8* null
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [22 x i8] c"setsockopt: reuseaddr\00"
@errno = global i64 0
@EADDRNOTAVAIL = global i64 0
@.str.4 = [5 x i8] c"bind\00"
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
@.str.5 = [18 x i8] c"IP_ADD_MEMBERSHIP\00"
define i32 @open_network(i8* %0, i32 %1, i32* %2, %struct.sockaddr_in* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.sockaddr_in*
%9 = alloca %struct.ip_mreq
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store %struct.sockaddr_in* %3, %struct.sockaddr_in** %8
store i32 0, i32* %11
%13 = load i8*, i8** %5
%14 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%15 = bitcast %struct.sockaddr_in* %14 to %struct.sockaddr*
%16 = call i32 @hpt(i8* %13, %struct.sockaddr* %15, i8* null)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = call i32 @usage(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %4
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %32
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @usage(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %21
%33 = load i8*, i8** %5
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %50
35: ; preds = %32
%36 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %9, i32 0, i32 0
%37 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %37, i32 0, i32 0
%39 = bitcast %struct.TYPE_4__* %36 to i8*
%40 = bitcast %struct.TYPE_4__* %38 to i8*
%41 = load i8*, i8** @INADDR_ANY
%42 = call i32 @htonl(i8* %41)
%43 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %9, i32 0, i32 1
%44 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %43, i32 0, i32 0
store i32 %42, i32* %44
%45 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %45, i32 0, i32 0
%47 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %9, i32 0, i32 0
%48 = bitcast %struct.TYPE_4__* %46 to i8*
%49 = bitcast %struct.TYPE_4__* %47 to i8*
br label %60
50: ; preds = %32
%51 = load i8*, i8** @INADDR_ANY
%52 = ptrtoint i8* %51 to i32
%53 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %9, i32 0, i32 0
%54 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %53, i32 0, i32 0
store i32 %52, i32* %54
%55 = load i8*, i8** @INADDR_ANY
%56 = ptrtoint i8* %55 to i32
%57 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %57, i32 0, i32 0
%59 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %58, i32 0, i32 0
store i32 %56, i32* %59
br label %60
60: ; preds = %50, %35
store i32 0, i32* %10
br label %61
61: ; preds = %197, %60
%62 = load i32, i32* %10
%63 = icmp slt i32 %62, 2
br i1 %63, label %64, label %200
64: ; preds = %61
store i32 1, i32* %12
%65 = load i32*, i32** %7
%66 = load i32, i32* %10
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i32, i32* %65, i64 %67
store i32 -1, i32* %68
%69 = load i32, i32* %6
%70 = icmp ne i32 %69, 0
br i1 %70, label %75, label %71
71: ; preds = %64
%72 = load i32, i32* %10
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %75
74: ; preds = %71
br label %197
75: ; preds = %71, %64
%76 = load i32, i32* @PF_INET
%77 = load i32, i32* @SOCK_DGRAM
%78 = call i32 @socket(i32 %76, i32 %77, i32 0)
%79 = load i32*, i32** %7
%80 = load i32, i32* %10
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %79, i64 %81
store i32 %78, i32* %82
%83 = load i32*, i32** %7
%84 = load i32, i32* %10
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i32, i32* %83, i64 %85
%87 = load i32, i32* %86
%88 = icmp slt i32 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %75
%90 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%91 = call i32 @exit(i32 1)
unreachable
92: ; preds = %75
%93 = load i32*, i32** %7
%94 = load i32, i32* %10
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i32, i32* %93, i64 %95
%97 = load i32, i32* %96
%98 = load i32, i32* %11
%99 = icmp sgt i32 %97, %98
br i1 %99, label %100, label %106
100: ; preds = %92
%101 = load i32*, i32** %7
%102 = load i32, i32* %10
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i32, i32* %101, i64 %103
%105 = load i32, i32* %104
store i32 %105, i32* %11
br label %106
106: ; preds = %100, %92
%107 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %9, i32 0, i32 0
%108 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %107, i32 0, i32 0
%109 = load i32, i32* %108
%110 = call i32 @ntohl(i32 %109)
%111 = call i64 @IN_CLASSD(i32 %110)
%112 = icmp ne i64 %111, 0
br i1 %112, label %113, label %127
113: ; preds = %106
%114 = load i32*, i32** %7
%115 = load i32, i32* %10
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i32, i32* %114, i64 %116
%118 = load i32, i32* %117
%119 = load i32, i32* @SOL_SOCKET
%120 = load i32, i32* @SO_REUSEADDR
%121 = bitcast i32* %12 to i8*
%122 = call i32 @setsockopt(i32 %118, i32 %119, i32 %120, i8* %121, i32 4)
%123 = icmp eq i32 %122, -1
br i1 %123, label %124, label %126
124: ; preds = %113
%125 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %126
126: ; preds = %124, %113
br label %127
127: ; preds = %126, %106
%128 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%129 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %128, i32 0, i32 1
%130 = load i32, i32* %129
%131 = call i64 @ntohs(i32 %130)
%132 = load i32, i32* %10
%133 = sext i32 %132 to i64
%134 = add nsw i64 %131, %133
%135 = call i32 @htons(i64 %134)
%136 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%137 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %136, i32 0, i32 1
store i32 %135, i32* %137
%138 = load i32*, i32** %7
%139 = load i32, i32* %10
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds i32, i32* %138, i64 %140
%142 = load i32, i32* %141
%143 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%144 = bitcast %struct.sockaddr_in* %143 to %struct.sockaddr*
%145 = call i64 @bind(i32 %142, %struct.sockaddr* %144, i32 8)
%146 = icmp slt i64 %145, 0
br i1 %146, label %147, label %174
147: ; preds = %127
%148 = load i64, i64* @errno
%149 = load i64, i64* @EADDRNOTAVAIL
%150 = icmp eq i64 %148, %149
br i1 %150, label %151, label %170
151: ; preds = %147
%152 = load i8*, i8** @INADDR_ANY
%153 = ptrtoint i8* %152 to i32
%154 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%155 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %154, i32 0, i32 0
%156 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %155, i32 0, i32 0
store i32 %153, i32* %156
%157 = load i32*, i32** %7
%158 = load i32, i32* %10
%159 = sext i32 %158 to i64
%160 = getelementptr inbounds i32, i32* %157, i64 %159
%161 = load i32, i32* %160
%162 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%163 = bitcast %struct.sockaddr_in* %162 to %struct.sockaddr*
%164 = call i64 @bind(i32 %161, %struct.sockaddr* %163, i32 8)
%165 = icmp slt i64 %164, 0
br i1 %165, label %166, label %169
166: ; preds = %151
%167 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%168 = call i32 @exit(i32 1)
unreachable
169: ; preds = %151
br label %173
170: ; preds = %147
%171 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%172 = call i32 @exit(i32 1)
unreachable
173: ; preds = %169
br label %174
174: ; preds = %173, %127
%175 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %9, i32 0, i32 0
%176 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %175, i32 0, i32 0
%177 = load i32, i32* %176
%178 = call i32 @ntohl(i32 %177)
%179 = call i64 @IN_CLASSD(i32 %178)
%180 = icmp ne i64 %179, 0
br i1 %180, label %181, label %196
181: ; preds = %174
%182 = load i32*, i32** %7
%183 = load i32, i32* %10
%184 = sext i32 %183 to i64
%185 = getelementptr inbounds i32, i32* %182, i64 %184
%186 = load i32, i32* %185
%187 = load i32, i32* @IPPROTO_IP
%188 = load i32, i32* @IP_ADD_MEMBERSHIP
%189 = bitcast %struct.ip_mreq* %9 to i8*
%190 = call i32 @setsockopt(i32 %186, i32 %187, i32 %188, i8* %189, i32 8)
%191 = icmp slt i32 %190, 0
br i1 %191, label %192, label %195
192: ; preds = %181
%193 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%194 = call i32 @exit(i32 1)
unreachable
195: ; preds = %181
br label %196
196: ; preds = %195, %174
br label %197
197: ; preds = %196, %74
%198 = load i32, i32* %10
%199 = add nsw i32 %198, 1
store i32 %199, i32* %10
br label %61
200: ; preds = %61
%201 = load i32, i32* %11
ret i32 %201
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.ip_mreq = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [20 x i8] c"Invalid multicast.\0A\00"
@INADDR_ANY = global i8* null
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [22 x i8] c"setsockopt: reuseaddr\00"
@errno = global i64 0
@EADDRNOTAVAIL = global i64 0
@.str.4 = [5 x i8] c"bind\00"
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
@.str.5 = [18 x i8] c"IP_ADD_MEMBERSHIP\00"
define i32 @open_network(i8* %0, i32 %1, i32* nocapture %2, %struct.sockaddr_in* %3) {
%5 = alloca %struct.ip_mreq
%6 = alloca i32
%7 = bitcast %struct.ip_mreq* %5 to i8*
%8 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%9 = tail call i32 @hpt(i8* %0, %struct.sockaddr* %8, i8* null)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %4
%12 = tail call i32 @usage(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %4
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @usage(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = icmp eq i8* %0, null
%25 = load i8*, i8** @INADDR_ANY
br i1 %24, label %29, label %26
26: ; preds = %23
%27 = tail call i32 @htonl(i8* %25)
%28 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %5, i64 0, i32 1, i32 0
store i32 %27, i32* %28
br label %32
29: ; preds = %23
%30 = ptrtoint i8* %25 to i64
%31 = trunc i64 %30 to i32
br label %32
32: ; preds = %29, %26
%33 = phi i32 [ %31, %29 ], [ %16, %26 ]
%34 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %5, i64 0, i32 0, i32 0
store i32 %33, i32* %34
store i32 %33, i32* %15
%35 = bitcast i32* %6 to i8*
%36 = icmp eq i32 %1, 0
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
br label %38
38: ; preds = %32, %106
%39 = phi i1 [ true, %32 ], [ false, %106 ]
%40 = phi i64 [ 0, %32 ], [ 1, %106 ]
%41 = phi i32 [ 0, %32 ], [ %107, %106 ]
store i32 1, i32* %6
%42 = getelementptr inbounds i32, i32* %2, i64 %40
store i32 -1, i32* %42
%43 = and i1 %36, %39
br i1 %43, label %106, label %44
44: ; preds = %38
%45 = load i32, i32* @PF_INET
%46 = load i32, i32* @SOCK_DGRAM
%47 = call i32 @socket(i32 %45, i32 %46, i32 0)
store i32 %47, i32* %42
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %44
%53 = icmp sgt i32 %47, %41
%54 = select i1 %53, i32 %47, i32 %41
%55 = load i32, i32* %34
%56 = call i32 @ntohl(i32 %55)
%57 = call i64 @IN_CLASSD(i32 %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %67, label %59
59: ; preds = %52
%60 = load i32, i32* %42
%61 = load i32, i32* @SOL_SOCKET
%62 = load i32, i32* @SO_REUSEADDR
%63 = call i32 @setsockopt(i32 %60, i32 %61, i32 %62, i8* %35, i32 4)
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %67
65: ; preds = %59
%66 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %67
67: ; preds = %59, %65, %52
%68 = load i32, i32* %37
%69 = call i64 @ntohs(i32 %68)
%70 = add nsw i64 %69, %40
%71 = call i32 @htons(i64 %70)
store i32 %71, i32* %37
%72 = load i32, i32* %42
%73 = call i64 @bind(i32 %72, %struct.sockaddr* %8, i32 8)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %92
75: ; preds = %67
%76 = load i64, i64* @errno
%77 = load i64, i64* @EADDRNOTAVAIL
%78 = icmp eq i64 %76, %77
br i1 %78, label %79, label %89
79: ; preds = %75
%80 = load i8*, i8** @INADDR_ANY
%81 = ptrtoint i8* %80 to i64
%82 = trunc i64 %81 to i32
store i32 %82, i32* %15
%83 = load i32, i32* %42
%84 = call i64 @bind(i32 %83, %struct.sockaddr* %8, i32 8)
%85 = icmp slt i64 %84, 0
br i1 %85, label %86, label %92
86: ; preds = %79
%87 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %75
%90 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%91 = call i32 @exit(i32 1)
unreachable
92: ; preds = %79, %67
%93 = load i32, i32* %34
%94 = call i32 @ntohl(i32 %93)
%95 = call i64 @IN_CLASSD(i32 %94)
%96 = icmp eq i64 %95, 0
br i1 %96, label %106, label %97
97: ; preds = %92
%98 = load i32, i32* %42
%99 = load i32, i32* @IPPROTO_IP
%100 = load i32, i32* @IP_ADD_MEMBERSHIP
%101 = call i32 @setsockopt(i32 %98, i32 %99, i32 %100, i8* %7, i32 8)
%102 = icmp slt i32 %101, 0
br i1 %102, label %103, label %106
103: ; preds = %97
%104 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%105 = call i32 @exit(i32 1)
unreachable
106: ; preds = %92, %97, %38
%107 = phi i32 [ %41, %38 ], [ %54, %97 ], [ %54, %92 ]
br i1 %39, label %38, label %108
108: ; preds = %106
ret i32 %107
}