#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 sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ saddr;

/* Variables and functions */
int BMI_sockio_init_sock(struct sockaddr *, char const *, int);
int /*<<< orphan*/ EINTR;
scalar_t__ bind(int, struct sockaddr *, int);
int bmi_errno_to_pvfs(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int BMI_sockio_bind_sock_specific(int sockd, const char *name, int service) {
  struct sockaddr saddr;
  int ret;
  if ((ret = BMI_sockio_init_sock(&saddr, name, service)) != 0)
    return (ret);
bind_sock_restart:
  if (bind(sockd, &saddr, sizeof(saddr)) < 0) {
    if (errno == EINTR)
      goto bind_sock_restart;
    return (bmi_errno_to_pvfs(-errno));
  }
  return (sockd);
}


x86 assembly (clang, -O0):
<BMI_sockio_bind_sock_specific>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x18(%rbp),%rdi
call   1030 <BMI_sockio_init_sock@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1169 <BMI_sockio_bind_sock_specific+0x39>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <BMI_sockio_bind_sock_specific+0x94>
jmp    116e <BMI_sockio_bind_sock_specific+0x3e>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1050 <bind@plt>
cmp    $0x0,%rax
jge    11be <BMI_sockio_bind_sock_specific+0x8e>
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
mov    0x2e3f(%rip),%rcx
cmp    (%rcx),%eax
jne    11a6 <BMI_sockio_bind_sock_specific+0x76>
jmp    116e <BMI_sockio_bind_sock_specific+0x3e>
xor    %edi,%edi
mov    0x2e31(%rip),%rax
sub    (%rax),%edi
call   1040 <bmi_errno_to_pvfs@plt>
mov    %eax,-0x4(%rbp)
jmp    11c4 <BMI_sockio_bind_sock_specific+0x94>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BMI_sockio_bind_sock_specific>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %rsp,%rdi
call   1030 <BMI_sockio_init_sock@plt>
test   %eax,%eax
jne    1188 <BMI_sockio_bind_sock_specific+0x58>
mov    %rsp,%r14
mov    0x2e90(%rip),%r15
mov    0x2e81(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1050 <bind@plt>
test   %rax,%rax
jns    1186 <BMI_sockio_bind_sock_specific+0x56>
mov    (%r15),%edi
cmp    (%r12),%edi
je     1160 <BMI_sockio_bind_sock_specific+0x30>
neg    %edi
call   1040 <bmi_errno_to_pvfs@plt>
jmp    1188 <BMI_sockio_bind_sock_specific+0x58>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@errno = global i32 0
@EINTR = global i32 0
define i32 @BMI_sockio_bind_sock_specific(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.sockaddr
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = call i32 @BMI_sockio_init_sock(%struct.sockaddr* %8, i8* %10, i32 %11)
store i32 %12, i32* %9
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = load i32, i32* %9
store i32 %15, i32* %4
br label %32
16: ; preds = %3
br label %17
17: ; preds = %25, %16
%18 = load i32, i32* %5
%19 = call i64 @bind(i32 %18, %struct.sockaddr* %8, i32 4)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %17
%22 = load i32, i32* @errno
%23 = load i32, i32* @EINTR
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21
br label %17
26: ; preds = %21
%27 = load i32, i32* @errno
%28 = sub nsw i32 0, %27
%29 = call i32 @bmi_errno_to_pvfs(i32 %28)
store i32 %29, i32* %4
br label %32
30: ; preds = %17
%31 = load i32, i32* %5
store i32 %31, i32* %4
br label %32
32: ; preds = %30, %26, %14
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@errno = global i32 0
@EINTR = global i32 0
define i32 @BMI_sockio_bind_sock_specific(i32 %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr
%5 = bitcast %struct.sockaddr* %4 to i8*
%6 = call i32 @BMI_sockio_init_sock(%struct.sockaddr* %4, i8* %1, i32 %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %3, %11
%9 = call i64 @bind(i32 %0, %struct.sockaddr* %4, i32 4)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load i32, i32* @errno
%13 = load i32, i32* @EINTR
%14 = icmp eq i32 %12, %13
br i1 %14, label %8, label %15
15: ; preds = %11
%16 = sub nsw i32 0, %12
%17 = call i32 @bmi_errno_to_pvfs(i32 %16)
br label %18
18: ; preds = %8, %3, %15
%19 = phi i32 [ %17, %15 ], [ %6, %3 ], [ %0, %8 ]
ret i32 %19
}