#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 convert_getnameinfo_flags(int);
int /*<<< orphan*/
darwin_convert_addr_to_native(struct android_sockaddr const *,
                              struct sockaddr *);
int /*<<< orphan*/ darwin_get_addr_size(struct android_sockaddr const *);
int getnameinfo(struct sockaddr *, int /*<<< orphan*/, char *,
                int /*<<< orphan*/, char *, int /*<<< orphan*/, int);
int darwin_my_getnameinfo(const struct android_sockaddr *__restrict sa,
                          socklen_t salen, char *__restrict host,
                          socklen_t hostlen, char *__restrict serv,
                          socklen_t servlen, int flags) {
  socklen_t conv_salen = darwin_get_addr_size(sa);
  struct sockaddr *conv_addr = alloca(conv_salen);
  if (!darwin_convert_addr_to_native(sa, conv_addr))
    return -1;
  int glibc_flags = convert_getnameinfo_flags(flags);
  return getnameinfo(conv_addr, conv_salen, host, hostlen, serv, servlen,
                     glibc_flags);
}


x86 assembly (clang, -O0):
<darwin_my_getnameinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <darwin_get_addr_size@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
call   1060 <alloca@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1070 <darwin_convert_addr_to_native@plt>
cmp    $0x0,%eax
jne    11ab <darwin_my_getnameinfo+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11da <darwin_my_getnameinfo+0x8a>
mov    0x10(%rbp),%edi
call   1040 <convert_getnameinfo_flags@plt>
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x30(%rbp),%r8
mov    -0x34(%rbp),%r9d
mov    -0x44(%rbp),%eax
mov    %eax,(%rsp)
call   1050 <getnameinfo@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<darwin_my_getnameinfo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,0x14(%rsp)
mov    %r8,%r15
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %rdi,%r14
call   1030 <darwin_get_addr_size@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <alloca@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1070 <darwin_convert_addr_to_native@plt>
test   %eax,%eax
je     11b5 <darwin_my_getnameinfo+0x65>
mov    0x50(%rsp),%edi
call   1040 <convert_getnameinfo_flags@plt>
mov    %eax,(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r13,%rdx
mov    %r12d,%ecx
mov    %r15,%r8
mov    0x14(%rsp),%r9d
call   1050 <getnameinfo@plt>
jmp    11ba <darwin_my_getnameinfo+0x6a>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.android_sockaddr = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @darwin_my_getnameinfo(%struct.android_sockaddr* noalias %0, i32 %1, i8* noalias %2, i32 %3, i8* noalias %4, i32 %5, i32 %6) {
%8 = alloca i32
%9 = alloca %struct.android_sockaddr*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca %struct.sockaddr*
%18 = alloca i32
store %struct.android_sockaddr* %0, %struct.android_sockaddr** %9
store i32 %1, i32* %10
store i8* %2, i8** %11
store i32 %3, i32* %12
store i8* %4, i8** %13
store i32 %5, i32* %14
store i32 %6, i32* %15
%19 = load %struct.android_sockaddr*, %struct.android_sockaddr** %9
%20 = call i32 @darwin_get_addr_size(%struct.android_sockaddr* %19)
store i32 %20, i32* %16
%21 = load i32, i32* %16
%22 = call %struct.sockaddr* @alloca(i32 %21)
store %struct.sockaddr* %22, %struct.sockaddr** %17
%23 = load %struct.android_sockaddr*, %struct.android_sockaddr** %9
%24 = load %struct.sockaddr*, %struct.sockaddr** %17
%25 = call i32 @darwin_convert_addr_to_native(%struct.android_sockaddr* %23, %struct.sockaddr* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %7
store i32 -1, i32* %8
br label %39
28: ; preds = %7
%29 = load i32, i32* %15
%30 = call i32 @convert_getnameinfo_flags(i32 %29)
store i32 %30, i32* %18
%31 = load %struct.sockaddr*, %struct.sockaddr** %17
%32 = load i32, i32* %16
%33 = load i8*, i8** %11
%34 = load i32, i32* %12
%35 = load i8*, i8** %13
%36 = load i32, i32* %14
%37 = load i32, i32* %18
%38 = call i32 @getnameinfo(%struct.sockaddr* %31, i32 %32, i8* %33, i32 %34, i8* %35, i32 %36, i32 %37)
store i32 %38, i32* %8
br label %39
39: ; preds = %28, %27
%40 = load i32, i32* %8
ret i32 %40
}

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