#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 */

/* Type definitions */
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_addrtype;
  scalar_t__ *h_addr_list;
};
typedef int /*<<< orphan*/ on;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ INADDR_ANY;
int PF_UNSPEC;
int SOCK_DGRAM;
int SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
scalar_t__ bind(int, struct sockaddr *, int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ dsm_close(int);
scalar_t__ errno;
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int, int);
int dsm_client_open(int type, int port, int broadcast, char *dest,
                    struct sockaddr_in *gaddr) {
  struct hostent *hp;
  int s;
  int prot;
  char on;
  struct sockaddr_in laddr, *saddr;
  saddr = (gaddr != NULL ? gaddr : &laddr);
  prot = (type == SOCK_DGRAM ? 0 : PF_UNSPEC);
  memset(saddr, 0, sizeof(struct sockaddr_in));
  if (!(hp = gethostbyname(dest))) {
    perror("gethostbyname");
    return (0);
  }
  saddr->sin_addr = *(struct in_addr *)*hp->h_addr_list;
  saddr->sin_family = hp->h_addrtype;
  saddr->sin_port = htons(port);
  if ((s = socket(hp->h_addrtype, type, prot)) < 0) {
    perror("socket error");
    return (0);
  }
  on = 1;
  if (broadcast &&
      setsockopt(s, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) < 0) {
    perror("setsockopt broadcast error");
    return (0);
  }
  if (broadcast)
    saddr->sin_addr.s_addr = htonl(INADDR_ANY);
  if (broadcast && bind(s, (struct sockaddr *)saddr, sizeof(struct sockaddr))) {
    perror("bind error");
    return (0);
  }
  if ((type == SOCK_STREAM))
    while (connect(s, (struct sockaddr *)saddr, sizeof(struct sockaddr)))
      if (errno != EINTR) {
        perror("connect error");
        dsm_close(s);
        return (0);
      }
  return (s);
}


x86 assembly (clang, -O0):
<dsm_client_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d1 <dsm_client_open+0x31>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    11de <dsm_client_open+0x3e>
lea    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    11de <dsm_client_open+0x3e>
mov    -0x50(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2de0(%rip),%rcx
cmp    (%rcx),%eax
jne    1202 <dsm_client_open+0x62>
xor    %eax,%eax
mov    %eax,-0x54(%rbp)
jmp    120e <dsm_client_open+0x6e>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
call   1070 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1253 <dsm_client_open+0xb3>
lea    0xdbe(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    13e6 <dsm_client_open+0x246>
mov    -0x48(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    0x8(%rcx),%rcx
mov    (%rcx),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
mov    -0x48(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0xc(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
mov    -0x30(%rbp),%edx
call   10c0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    12b9 <dsm_client_open+0x119>
lea    0xd66(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    13e6 <dsm_client_open+0x246>
movb   $0x1,-0x31(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     130d <dsm_client_open+0x16d>
mov    -0x2c(%rbp),%edi
mov    0x2d17(%rip),%rax
mov    (%rax),%esi
mov    0x2cee(%rip),%rax
mov    (%rax),%edx
lea    -0x31(%rbp),%rcx
mov    $0x1,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    130d <dsm_client_open+0x16d>
lea    0xd1f(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    13e6 <dsm_client_open+0x246>
cmpl   $0x0,-0x10(%rbp)
je     132d <dsm_client_open+0x18d>
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x10(%rbp)
je     136a <dsm_client_open+0x1ca>
mov    -0x2c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    $0x4,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
je     136a <dsm_client_open+0x1ca>
lea    0xcdd(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    13e6 <dsm_client_open+0x246>
mov    -0x8(%rbp),%eax
mov    0x2c44(%rip),%rcx
cmp    (%rcx),%eax
jne    13e0 <dsm_client_open+0x240>
jmp    1381 <dsm_client_open+0x1e1>
mov    -0x2c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <connect@plt>
cmp    $0x0,%rax
je     13db <dsm_client_open+0x23b>
mov    0x2c0d(%rip),%rax
mov    (%rax),%rax
mov    0x2bfb(%rip),%rcx
cmp    (%rcx),%rax
je     13d6 <dsm_client_open+0x236>
lea    0xc84(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x2c(%rbp),%edi
call   1090 <dsm_close@plt>
movl   $0x0,-0x4(%rbp)
jmp    13e6 <dsm_client_open+0x246>
jmp    1381 <dsm_client_open+0x1e1>
jmp    13e0 <dsm_client_open+0x240>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dsm_client_open>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%rbx
mov    %rcx,%r12
mov    %edx,0xc(%rsp)
mov    %esi,0x14(%rsp)
mov    %edi,0x8(%rsp)
test   %r8,%r8
lea    0x18(%rsp),%rbp
mov    %r8,%r14
cmove  %rbp,%r14
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%r15d
xor    %r13d,%r13d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    %r12,%rdi
call   1070 <gethostbyname@plt>
test   %rax,%rax
je     1314 <dsm_client_open+0x174>
mov    %rax,%r12
mov    0x8(%rsp),%eax
cmp    %eax,0x10(%rsp)
cmove  %r13d,%r15d
test   %rbx,%rbx
mov    0x8(%r12),%rax
mov    (%rax),%rax
cmovne %rbx,%rbp
mov    (%rax),%eax
mov    %eax,0x0(%rbp)
mov    (%r12),%eax
mov    %eax,0x8(%rbp)
mov    0x14(%rsp),%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rbp)
mov    (%r12),%edi
mov    0x8(%rsp),%ebx
mov    %ebx,%esi
mov    %r15d,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     1322 <dsm_client_open+0x182>
mov    %eax,%r13d
movb   $0x1,0x7(%rsp)
cmpl   $0x0,0xc(%rsp)
je     12bc <dsm_client_open+0x11c>
mov    0x2d79(%rip),%rax
mov    (%rax),%esi
mov    0x2d50(%rip),%rax
mov    (%rax),%edx
lea    0x7(%rsp),%rcx
mov    %r13d,%edi
mov    $0x1,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     132b <dsm_client_open+0x18b>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x0(%rbp)
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1080 <bind@plt>
test   %rax,%rax
jne    1334 <dsm_client_open+0x194>
mov    0x2cf5(%rip),%rax
cmp    %ebx,(%rax)
jne    1343 <dsm_client_open+0x1a3>
mov    0x2ce2(%rip),%rbp
mov    0x2cd3(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   10b0 <connect@plt>
test   %rax,%rax
je     1343 <dsm_client_open+0x1a3>
mov    0x0(%rbp),%rax
cmp    (%rbx),%rax
je     12e0 <dsm_client_open+0x140>
lea    0xd3c(%rip),%rdi
call   10a0 <perror@plt>
mov    %r13d,%edi
call   1090 <dsm_close@plt>
jmp    1340 <dsm_client_open+0x1a0>
lea    0xce5(%rip),%rdi
call   10a0 <perror@plt>
jmp    1343 <dsm_client_open+0x1a3>
lea    0xce5(%rip),%rdi
jmp    133b <dsm_client_open+0x19b>
lea    0xce9(%rip),%rdi
jmp    133b <dsm_client_open+0x19b>
lea    0xcfb(%rip),%rdi
call   10a0 <perror@plt>
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i32, i64* }
%struct.sockaddr = type { i32 }
@SOCK_DGRAM = global i32 0
@PF_UNSPEC = global i32 0
@.str = [14 x i8] c"gethostbyname\00"
@.str.1 = [13 x i8] c"socket error\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.2 = [27 x i8] c"setsockopt broadcast error\00"
@INADDR_ANY = global i32 0
@.str.3 = [11 x i8] c"bind error\00"
@SOCK_STREAM = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str.4 = [14 x i8] c"connect error\00"
define i32 @dsm_client_open(i32 %0, i32 %1, i32 %2, i8* %3, %struct.sockaddr_in* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca %struct.sockaddr_in*
%12 = alloca %struct.hostent*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8
%16 = alloca %struct.sockaddr_in
%17 = alloca %struct.sockaddr_in*
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store %struct.sockaddr_in* %4, %struct.sockaddr_in** %11
%18 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
%19 = icmp ne %struct.sockaddr_in* %18, null
br i1 %19, label %20, label %22
20: ; preds = %5
%21 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
br label %23
22: ; preds = %5
br label %23
23: ; preds = %22, %20
%24 = phi %struct.sockaddr_in* [ %21, %20 ], [ %16, %22 ]
store %struct.sockaddr_in* %24, %struct.sockaddr_in** %17
%25 = load i32, i32* %7
%26 = load i32, i32* @SOCK_DGRAM
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %23
br label %31
29: ; preds = %23
%30 = load i32, i32* @PF_UNSPEC
br label %31
31: ; preds = %29, %28
%32 = phi i32 [ 0, %28 ], [ %30, %29 ]
store i32 %32, i32* %14
%33 = load %struct.sockaddr_in*, %struct.sockaddr_in** %17
%34 = call i32 @memset(%struct.sockaddr_in* %33, i32 0, i32 12)
%35 = load i8*, i8** %10
%36 = call %struct.hostent* @gethostbyname(i8* %35)
store %struct.hostent* %36, %struct.hostent** %12
%37 = icmp ne %struct.hostent* %36, null
br i1 %37, label %40, label %38
38: ; preds = %31
%39 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %122
40: ; preds = %31
%41 = load %struct.sockaddr_in*, %struct.sockaddr_in** %17
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %41, i32 0, i32 0
%43 = load %struct.hostent*, %struct.hostent** %12
%44 = getelementptr inbounds %struct.hostent, %struct.hostent* %43, i32 0, i32 1
%45 = load i64*, i64** %44
%46 = load i64, i64* %45
%47 = inttoptr i64 %46 to %struct.in_addr*
%48 = bitcast %struct.in_addr* %42 to i8*
%49 = bitcast %struct.in_addr* %47 to i8*
%50 = load %struct.hostent*, %struct.hostent** %12
%51 = getelementptr inbounds %struct.hostent, %struct.hostent* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = load %struct.sockaddr_in*, %struct.sockaddr_in** %17
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %53, i32 0, i32 2
store i32 %52, i32* %54
%55 = load i32, i32* %8
%56 = call i32 @htons(i32 %55)
%57 = load %struct.sockaddr_in*, %struct.sockaddr_in** %17
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %57, i32 0, i32 1
store i32 %56, i32* %58
%59 = load %struct.hostent*, %struct.hostent** %12
%60 = getelementptr inbounds %struct.hostent, %struct.hostent* %59, i32 0, i32 0
%61 = load i32, i32* %60
%62 = load i32, i32* %7
%63 = load i32, i32* %14
%64 = call i32 @socket(i32 %61, i32 %62, i32 %63)
store i32 %64, i32* %13
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %40
%67 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %122
68: ; preds = %40
store i8 1, i8* %15
%69 = load i32, i32* %9
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %79
71: ; preds = %68
%72 = load i32, i32* %13
%73 = load i32, i32* @SOL_SOCKET
%74 = load i32, i32* @SO_BROADCAST
%75 = call i64 @setsockopt(i32 %72, i32 %73, i32 %74, i8* %15, i32 1)
%76 = icmp slt i64 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %71
%78 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %6
br label %122
79: ; preds = %71, %68
%80 = load i32, i32* %9
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %88
82: ; preds = %79
%83 = load i32, i32* @INADDR_ANY
%84 = call i32 @htonl(i32 %83)
%85 = load %struct.sockaddr_in*, %struct.sockaddr_in** %17
%86 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %85, i32 0, i32 0
%87 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %86, i32 0, i32 0
store i32 %84, i32* %87
br label %88
88: ; preds = %82, %79
%89 = load i32, i32* %9
%90 = icmp ne i32 %89, 0
br i1 %90, label %91, label %99
91: ; preds = %88
%92 = load i32, i32* %13
%93 = load %struct.sockaddr_in*, %struct.sockaddr_in** %17
%94 = bitcast %struct.sockaddr_in* %93 to %struct.sockaddr*
%95 = call i64 @bind(i32 %92, %struct.sockaddr* %94, i32 4)
%96 = icmp ne i64 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %91
%98 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %122
99: ; preds = %91, %88
%100 = load i32, i32* %7
%101 = load i32, i32* @SOCK_STREAM
%102 = icmp eq i32 %100, %101
br i1 %102, label %103, label %120
103: ; preds = %99
br label %104
104: ; preds = %118, %103
%105 = load i32, i32* %13
%106 = load %struct.sockaddr_in*, %struct.sockaddr_in** %17
%107 = bitcast %struct.sockaddr_in* %106 to %struct.sockaddr*
%108 = call i64 @connect(i32 %105, %struct.sockaddr* %107, i32 4)
%109 = icmp ne i64 %108, 0
br i1 %109, label %110, label %119
110: ; preds = %104
%111 = load i64, i64* @errno
%112 = load i64, i64* @EINTR
%113 = icmp ne i64 %111, %112
br i1 %113, label %114, label %118
114: ; preds = %110
%115 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%116 = load i32, i32* %13
%117 = call i32 @dsm_close(i32 %116)
store i32 0, i32* %6
br label %122
118: ; preds = %110
br label %104
119: ; preds = %104
br label %120
120: ; preds = %119, %99
%121 = load i32, i32* %13
store i32 %121, i32* %6
br label %122
122: ; preds = %120, %114, %97, %77, %66, %38
%123 = load i32, i32* %6
ret i32 %123
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i32, i64* }
%struct.sockaddr = type { i32 }
@SOCK_DGRAM = global i32 0
@PF_UNSPEC = global i32 0
@.str = [14 x i8] c"gethostbyname\00"
@.str.1 = [13 x i8] c"socket error\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.2 = [27 x i8] c"setsockopt broadcast error\00"
@INADDR_ANY = global i32 0
@.str.3 = [11 x i8] c"bind error\00"
@SOCK_STREAM = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str.4 = [14 x i8] c"connect error\00"
define i32 @dsm_client_open(i32 %0, i32 %1, i32 %2, i8* %3, %struct.sockaddr_in* %4) {
%6 = alloca i8
%7 = alloca %struct.sockaddr_in
%8 = bitcast %struct.sockaddr_in* %7 to i8*
%9 = icmp eq %struct.sockaddr_in* %4, null
%10 = select i1 %9, %struct.sockaddr_in* %7, %struct.sockaddr_in* %4
%11 = load i32, i32* @SOCK_DGRAM
%12 = load i32, i32* @PF_UNSPEC
%13 = call i32 @memset(%struct.sockaddr_in* %10, i32 0, i32 12)
%14 = call %struct.hostent* @gethostbyname(i8* %3)
%15 = icmp eq %struct.hostent* %14, null
br i1 %15, label %16, label %18
16: ; preds = %5
%17 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %75
18: ; preds = %5
%19 = icmp eq i32 %11, %0
%20 = select i1 %19, i32 0, i32 %12
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %14, i64 0, i32 1
%22 = load i64*, i64** %21
%23 = load i64, i64* %22
%24 = inttoptr i64 %23 to i32*
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0, i32 0
%26 = getelementptr %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
%27 = select i1 %9, i32* %25, i32* %26
%28 = load i32, i32* %24
store i32 %28, i32* %27
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %14, i64 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
%33 = select i1 %9, i32* %31, i32* %32
store i32 %30, i32* %33
%34 = call i32 @htons(i32 %1)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%37 = select i1 %9, i32* %35, i32* %36
store i32 %34, i32* %37
%38 = load i32, i32* %29
%39 = call i32 @socket(i32 %38, i32 %0, i32 %20)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %18
%42 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %75
43: ; preds = %18
store i8 1, i8* %6
%44 = icmp eq i32 %2, 0
br i1 %44, label %60, label %45
45: ; preds = %43
%46 = load i32, i32* @SOL_SOCKET
%47 = load i32, i32* @SO_BROADCAST
%48 = call i64 @setsockopt(i32 %39, i32 %46, i32 %47, i8* %6, i32 1)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %75
52: ; preds = %45
%53 = load i32, i32* @INADDR_ANY
%54 = call i32 @htonl(i32 %53)
store i32 %54, i32* %27
%55 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%56 = call i64 @bind(i32 %39, %struct.sockaddr* %55, i32 4)
%57 = icmp eq i64 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %52
%59 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %75
60: ; preds = %43, %52
%61 = load i32, i32* @SOCK_STREAM
%62 = icmp eq i32 %61, %0
br i1 %62, label %63, label %75
63: ; preds = %60
%64 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
br label %65
65: ; preds = %63, %68
%66 = call i64 @connect(i32 %39, %struct.sockaddr* %64, i32 4)
%67 = icmp eq i64 %66, 0
br i1 %67, label %75, label %68
68: ; preds = %65
%69 = load i64, i64* @errno
%70 = load i64, i64* @EINTR
%71 = icmp eq i64 %69, %70
br i1 %71, label %65, label %72
72: ; preds = %68
%73 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%74 = call i32 @dsm_close(i32 %39)
br label %75
75: ; preds = %65, %60, %72, %58, %50, %41, %16
%76 = phi i32 [ 0, %41 ], [ 0, %50 ], [ 0, %58 ], [ 0, %72 ], [ 0, %16 ], [ %39, %60 ], [ %39, %65 ]
ret i32 %76
}