#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 EINTR;
scalar_t__ bind(int, struct sockaddr *, int);
int 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 (-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     1159 <BMI_sockio_bind_sock_specific+0x39>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11af <BMI_sockio_bind_sock_specific+0x8f>
jmp    115e <BMI_sockio_bind_sock_specific+0x3e>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1040 <bind@plt>
cmp    $0x0,%rax
jge    11a9 <BMI_sockio_bind_sock_specific+0x89>
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    0x2e4f(%rip),%rcx
cmp    (%rcx),%eax
jne    1196 <BMI_sockio_bind_sock_specific+0x76>
jmp    115e <BMI_sockio_bind_sock_specific+0x3e>
xor    %eax,%eax
mov    0x2e41(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11af <BMI_sockio_bind_sock_specific+0x8f>
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    1173 <BMI_sockio_bind_sock_specific+0x53>
mov    %rsp,%r14
mov    0x2ea0(%rip),%r15
mov    0x2e91(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <bind@plt>
test   %rax,%rax
jns    1171 <BMI_sockio_bind_sock_specific+0x51>
mov    (%r15),%eax
cmp    (%r12),%eax
je     1150 <BMI_sockio_bind_sock_specific+0x30>
neg    %eax
jmp    1173 <BMI_sockio_bind_sock_specific+0x53>
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 %31
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 %29
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
store i32 %28, i32* %4
br label %31
29: ; preds = %17
%30 = load i32, i32* %5
store i32 %30, i32* %4
br label %31
31: ; preds = %29, %26, %14
%32 = load i32, i32* %4
ret i32 %32
}

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 %17
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 %17
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
br label %17
17: ; preds = %8, %3, %15
%18 = phi i32 [ %16, %15 ], [ %6, %3 ], [ %0, %8 ]
ret i32 %18
}