#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_6__ TYPE_3__;
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  void *s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct TYPE_6__ {
  scalar_t__ s_addr;
};
struct TYPE_5__ {
  void *s_addr;
};
struct ip_mreq {
  TYPE_3__ imr_interface;
  TYPE_2__ imr_multiaddr;
};
typedef int /*<<< orphan*/ sin;
typedef int /*<<< orphan*/ blub;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_ADD_MEMBERSHIP;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(unsigned short);
void *inet_addr(char *);
int makesocket(char *, unsigned short, int, struct sockaddr_in *);
int ntohl(unsigned int);
int /*<<< orphan*/ perror(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                      struct ip_mreq *, int);
int makeclientsocket(char *szAddr, unsigned short port, int TTL,
                     struct sockaddr_in *sSockAddr) {
  int socket = makesocket(szAddr, port, TTL, sSockAddr);
  struct ip_mreq blub;
  struct sockaddr_in sin;
  unsigned int tempaddr;
  sin.sin_family = AF_INET;
  sin.sin_port = htons(port);
  sin.sin_addr.s_addr = inet_addr(szAddr);
  if (bind(socket, (struct sockaddr *)&sin, sizeof(sin))) {
    perror("bind failed");
    exit(1);
  }
  tempaddr = inet_addr(szAddr);
  if ((ntohl(tempaddr) >> 28) == 0xe) {
    blub.imr_multiaddr.s_addr = inet_addr(szAddr);
    blub.imr_interface.s_addr = 0;
    if (setsockopt(socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &blub,
                   sizeof(blub))) {
      perror("setsockopt IP_ADD_MEMBERSHIP failed (multicast kernel?)");
      exit(1);
    }
  }
  return socket;
}


x86 assembly (clang, -O0):
<makeclientsocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xa(%rbp),%ax
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
movzwl %ax,%esi
call   1040 <makesocket@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
movzwl -0xa(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <inet_addr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
je     120a <makeclientsocket+0x8a>
lea    0xe05(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
call   10a0 <ntohl@plt>
sar    $0x1c,%eax
cmp    $0xe,%eax
jne    1288 <makeclientsocket+0x108>
mov    -0x8(%rbp),%rdi
call   1060 <inet_addr@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
mov    0x2d96(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     1283 <makeclientsocket+0x103>
lea    0xd98(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1288 <makeclientsocket+0x108>
mov    -0x1c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeclientsocket>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <makesocket@plt>
mov    %eax,%r14d
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %ebp,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %rbx,%rdi
call   1050 <inet_addr@plt>
mov    %rax,(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x10,%edx
call   1060 <bind@plt>
test   %rax,%rax
jne    11d9 <makeclientsocket+0x69>
mov    %rbx,%rdi
call   1050 <inet_addr@plt>
mov    %eax,%edi
call   1090 <ntohl@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe20(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_4__, i32, i32 }
%struct.TYPE_4__ = type { i8* }
%struct.ip_mreq = type { %struct.TYPE_6__, %struct.TYPE_5__ }
%struct.TYPE_6__ = type { i64 }
%struct.TYPE_5__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [12 x i8] c"bind failed\00"
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
@.str.1 = [56 x i8] c"setsockopt IP_ADD_MEMBERSHIP failed (multicast kernel?)\00"
define i32 @makeclientsocket(i8* %0, i16 zeroext %1, i32 %2, %struct.sockaddr_in* %3) {
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i32
%8 = alloca %struct.sockaddr_in*
%9 = alloca i32
%10 = alloca %struct.ip_mreq
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
store i8* %0, i8** %5
store i16 %1, i16* %6
store i32 %2, i32* %7
store %struct.sockaddr_in* %3, %struct.sockaddr_in** %8
%13 = load i8*, i8** %5
%14 = load i16, i16* %6
%15 = load i32, i32* %7
%16 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%17 = call i32 @makesocket(i8* %13, i16 zeroext %14, i32 %15, %struct.sockaddr_in* %16)
store i32 %17, i32* %9
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %18, i32* %19
%20 = load i16, i16* %6
%21 = call i32 @htons(i16 zeroext %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %21, i32* %22
%23 = load i8*, i8** %5
%24 = call i8* @inet_addr(i8* %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %25, i32 0, i32 0
store i8* %24, i8** %26
%27 = load i32, i32* %9
%28 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%29 = call i64 @bind(i32 %27, %struct.sockaddr* %28, i32 16)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %4
%32 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %4
%35 = load i8*, i8** %5
%36 = call i8* @inet_addr(i8* %35)
%37 = ptrtoint i8* %36 to i32
store i32 %37, i32* %12
%38 = load i32, i32* %12
%39 = call i32 @ntohl(i32 %38)
%40 = ashr i32 %39, 28
%41 = icmp eq i32 %40, 14
br i1 %41, label %42, label %58
42: ; preds = %34
%43 = load i8*, i8** %5
%44 = call i8* @inet_addr(i8* %43)
%45 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %10, i32 0, i32 1
%46 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %45, i32 0, i32 0
store i8* %44, i8** %46
%47 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %10, i32 0, i32 0
%48 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %47, i32 0, i32 0
store i64 0, i64* %48
%49 = load i32, i32* %9
%50 = load i32, i32* @IPPROTO_IP
%51 = load i32, i32* @IP_ADD_MEMBERSHIP
%52 = call i64 @setsockopt(i32 %49, i32 %50, i32 %51, %struct.ip_mreq* %10, i32 16)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %42
%55 = call i32 @perror(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %42
br label %58
58: ; preds = %57, %34
%59 = load i32, i32* %9
ret i32 %59
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_4__, i32, i32 }
%struct.TYPE_4__ = type { i8* }
%struct.ip_mreq = type { %struct.TYPE_6__, %struct.TYPE_5__ }
%struct.TYPE_6__ = type { i64 }
%struct.TYPE_5__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [12 x i8] c"bind failed\00"
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
define i32 @makeclientsocket(i8* %0, i16 zeroext %1, i32 %2, %struct.sockaddr_in* %3) {
%5 = alloca %struct.sockaddr_in
%6 = tail call i32 @makesocket(i8* %0, i16 zeroext %1, i32 %2, %struct.sockaddr_in* %3)
%7 = bitcast %struct.sockaddr_in* %5 to i8*
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %8, i32* %9
%10 = tail call i32 @htons(i16 zeroext %1)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %10, i32* %11
%12 = tail call i8* @inet_addr(i8* %0)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i8* %12, i8** %13
%14 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%15 = call i64 @bind(i32 %6, %struct.sockaddr* %14, i32 16)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %4
%18 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %4
%21 = call i8* @inet_addr(i8* %0)
%22 = ptrtoint i8* %21 to i64
%23 = trunc i64 %22 to i32
%24 = call i32 @ntohl(i32 %23)
ret i32 %6
}