#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;
};
struct android_sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
struct sockaddr *alloca(int /*<<< orphan*/);
int bind(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/
darwin_convert_addr_to_native(struct android_sockaddr const *,
                              struct sockaddr *);
int /*<<< orphan*/ darwin_get_addr_size(struct android_sockaddr const *);
int darwin_my_bind(int sockfd, const struct android_sockaddr *addr,
                   socklen_t addrlen) {
  struct sockaddr *conv_addr = alloca(darwin_get_addr_size(addr));
  if (!darwin_convert_addr_to_native(addr, conv_addr))
    return -1;
  return bind(sockfd, conv_addr, addrlen);
}


x86 assembly (clang, -O0):
<darwin_my_bind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <darwin_get_addr_size@plt>
mov    %eax,%edi
call   1040 <alloca@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <darwin_convert_addr_to_native@plt>
cmp    $0x0,%eax
jne    1188 <darwin_my_bind+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <darwin_my_bind+0x5a>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <bind@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<darwin_my_bind>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %edi,%r15d
mov    %rsi,%rdi
call   1030 <darwin_get_addr_size@plt>
mov    %eax,%edi
call   1040 <alloca@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
call   1050 <darwin_convert_addr_to_native@plt>
test   %eax,%eax
je     1189 <darwin_my_bind+0x49>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <bind@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.android_sockaddr = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @darwin_my_bind(i32 %0, %struct.android_sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.android_sockaddr*
%7 = alloca i32
%8 = alloca %struct.sockaddr*
store i32 %0, i32* %5
store %struct.android_sockaddr* %1, %struct.android_sockaddr** %6
store i32 %2, i32* %7
%9 = load %struct.android_sockaddr*, %struct.android_sockaddr** %6
%10 = call i32 @darwin_get_addr_size(%struct.android_sockaddr* %9)
%11 = call %struct.sockaddr* @alloca(i32 %10)
store %struct.sockaddr* %11, %struct.sockaddr** %8
%12 = load %struct.android_sockaddr*, %struct.android_sockaddr** %6
%13 = load %struct.sockaddr*, %struct.sockaddr** %8
%14 = call i32 @darwin_convert_addr_to_native(%struct.android_sockaddr* %12, %struct.sockaddr* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %3
store i32 -1, i32* %4
br label %22
17: ; preds = %3
%18 = load i32, i32* %5
%19 = load %struct.sockaddr*, %struct.sockaddr** %8
%20 = load i32, i32* %7
%21 = call i32 @bind(i32 %18, %struct.sockaddr* %19, i32 %20)
store i32 %21, i32* %4
br label %22
22: ; preds = %17, %16
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
%struct.android_sockaddr = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @darwin_my_bind(i32 %0, %struct.android_sockaddr* %1, i32 %2) {
%4 = tail call i32 @darwin_get_addr_size(%struct.android_sockaddr* %1)
%5 = tail call %struct.sockaddr* @alloca(i32 %4)
%6 = tail call i32 @darwin_convert_addr_to_native(%struct.android_sockaddr* %1, %struct.sockaddr* %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 @bind(i32 %0, %struct.sockaddr* %5, i32 %2)
br label %10
10: ; preds = %3, %8
%11 = phi i32 [ %9, %8 ], [ -1, %3 ]
ret i32 %11
}