#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 ssize_t;
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
struct sockaddr *alloca(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 sendto(int, void const *, size_t, int, struct sockaddr *,
           int /*<<< orphan*/);
ssize_t darwin_my_sendto(int socket, const void *buffer, size_t length,
                         int flags, const struct android_sockaddr *dest_addr,
                         socklen_t dest_len) {
  struct sockaddr *conv_addr = alloca(darwin_get_addr_size(dest_addr));
  if (!darwin_convert_addr_to_native(dest_addr, conv_addr))
    return -1;
  return sendto(socket, buffer, length, flags, conv_addr, dest_len);
}


x86 assembly (clang, -O0):
<darwin_my_sendto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <darwin_get_addr_size@plt>
mov    %eax,%edi
call   1050 <alloca@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <darwin_convert_addr_to_native@plt>
cmp    $0x0,%eax
jne    1194 <darwin_my_sendto+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <darwin_my_sendto+0x72>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x38(%rbp),%r8
mov    -0x2c(%rbp),%r9d
call   1040 <sendto@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<darwin_my_sendto>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,0x4(%rsp)
mov    %r8,%r14
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%r13
mov    %edi,%ebx
mov    %r8,%rdi
call   1030 <darwin_get_addr_size@plt>
mov    %eax,%edi
call   1050 <alloca@plt>
mov    %rax,%rbp
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <darwin_convert_addr_to_native@plt>
test   %eax,%eax
je     11a5 <darwin_my_sendto+0x65>
mov    %ebx,%edi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15d,%ecx
mov    %rbp,%r8
mov    0x4(%rsp),%r9d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <sendto@plt>
mov    $0xffffffff,%eax
add    $0x8,%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_sendto(i32 %0, i8* %1, i64 %2, i32 %3, %struct.android_sockaddr* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca %struct.android_sockaddr*
%13 = alloca i32
%14 = alloca %struct.sockaddr*
store i32 %0, i32* %8
store i8* %1, i8** %9
store i64 %2, i64* %10
store i32 %3, i32* %11
store %struct.android_sockaddr* %4, %struct.android_sockaddr** %12
store i32 %5, i32* %13
%15 = load %struct.android_sockaddr*, %struct.android_sockaddr** %12
%16 = call i32 @darwin_get_addr_size(%struct.android_sockaddr* %15)
%17 = call %struct.sockaddr* @alloca(i32 %16)
store %struct.sockaddr* %17, %struct.sockaddr** %14
%18 = load %struct.android_sockaddr*, %struct.android_sockaddr** %12
%19 = load %struct.sockaddr*, %struct.sockaddr** %14
%20 = call i32 @darwin_convert_addr_to_native(%struct.android_sockaddr* %18, %struct.sockaddr* %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %6
store i32 -1, i32* %7
br label %31
23: ; preds = %6
%24 = load i32, i32* %8
%25 = load i8*, i8** %9
%26 = load i64, i64* %10
%27 = load i32, i32* %11
%28 = load %struct.sockaddr*, %struct.sockaddr** %14
%29 = load i32, i32* %13
%30 = call i32 @sendto(i32 %24, i8* %25, i64 %26, i32 %27, %struct.sockaddr* %28, i32 %29)
store i32 %30, i32* %7
br label %31
31: ; preds = %23, %22
%32 = load i32, i32* %7
ret i32 %32
}

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