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

/* Variables and functions */
int /*<<< orphan*/ darwin_convert_addr_from_native(struct sockaddr *,
                                                   struct android_sockaddr *,
                                                   int);
int recvfrom(int, void *, size_t, int, struct sockaddr *, int *);
ssize_t darwin_my_recvfrom(int sockfd, void *buf, size_t len, int flags,
                           struct android_sockaddr *addr, socklen_t *addrlen) {
  struct sockaddr_storage stor;
  socklen_t ret_size = sizeof(stor);
  int ret =
      recvfrom(sockfd, buf, len, flags, (struct sockaddr *)&stor, &ret_size);
  if (ret >= 0) {
    if (!darwin_convert_addr_from_native((struct sockaddr *)&stor, addr,
                                         *addrlen))
      return -1;
    *addrlen = ret_size - 1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<darwin_my_recvfrom>:
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    %r9,-0x30(%rbp)
movl   $0x4,-0x3c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    -0x38(%rbp),%r8
lea    -0x3c(%rbp),%r9
call   1040 <recvfrom@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jl     11a1 <darwin_my_recvfrom+0x81>
lea    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   1030 <darwin_convert_addr_from_native@plt>
cmp    $0x0,%eax
jne    1195 <darwin_my_recvfrom+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <darwin_my_recvfrom+0x87>
mov    -0x3c(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<darwin_my_recvfrom>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %r9,%rbx
mov    %r8,%r14
movl   $0x4,0x4(%rsp)
lea    0x8(%rsp),%r8
lea    0x4(%rsp),%r9
call   1040 <recvfrom@plt>
mov    %eax,%ebp
test   %eax,%eax
js     116e <darwin_my_recvfrom+0x4e>
mov    (%rbx),%edx
lea    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1030 <darwin_convert_addr_from_native@plt>
test   %eax,%eax
je     1169 <darwin_my_recvfrom+0x49>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
mov    %eax,(%rbx)
jmp    116e <darwin_my_recvfrom+0x4e>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.android_sockaddr = type { i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @darwin_my_recvfrom(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_storage
%15 = alloca i32
%16 = alloca i32
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
store i32 4, i32* %15
%17 = load i32, i32* %8
%18 = load i8*, i8** %9
%19 = load i64, i64* %10
%20 = load i32, i32* %11
%21 = bitcast %struct.sockaddr_storage* %14 to %struct.sockaddr*
%22 = call i32 @recvfrom(i32 %17, i8* %18, i64 %19, i32 %20, %struct.sockaddr* %21, i32* %15)
store i32 %22, i32* %16
%23 = load i32, i32* %16
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %37
25: ; preds = %6
%26 = bitcast %struct.sockaddr_storage* %14 to %struct.sockaddr*
%27 = load %struct.android_sockaddr*, %struct.android_sockaddr** %12
%28 = load i32*, i32** %13
%29 = load i32, i32* %28
%30 = call i32 @darwin_convert_addr_from_native(%struct.sockaddr* %26, %struct.android_sockaddr* %27, i32 %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %25
store i32 -1, i32* %7
br label %39
33: ; preds = %25
%34 = load i32, i32* %15
%35 = sub nsw i32 %34, 1
%36 = load i32*, i32** %13
store i32 %35, i32* %36
br label %37
37: ; preds = %33, %6
%38 = load i32, i32* %16
store i32 %38, i32* %7
br label %39
39: ; preds = %37, %32
%40 = load i32, i32* %7
ret i32 %40
}

LLVM IR (-O2):
%struct.android_sockaddr = type { i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @darwin_my_recvfrom(i32 %0, i8* %1, i64 %2, i32 %3, %struct.android_sockaddr* %4, i32* nocapture %5) {
%7 = alloca %struct.sockaddr_storage
%8 = alloca i32
%9 = bitcast %struct.sockaddr_storage* %7 to i8*
%10 = bitcast i32* %8 to i8*
store i32 4, i32* %8
%11 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%12 = call i32 @recvfrom(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr* %11, i32* %8)
%13 = icmp sgt i32 %12, -1
br i1 %13, label %14, label %21
14: ; preds = %6
%15 = load i32, i32* %5
%16 = call i32 @darwin_convert_addr_from_native(%struct.sockaddr* %11, %struct.android_sockaddr* %4, i32 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load i32, i32* %8
%20 = add nsw i32 %19, -1
store i32 %20, i32* %5
br label %21
21: ; preds = %6, %18, %14
%22 = phi i32 [ -1, %14 ], [ %12, %18 ], [ %12, %6 ]
ret i32 %22
}