#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 */
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ uint16_t;
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
size_t recvfrom(int, char *, size_t, int /*<<< orphan*/, struct sockaddr *,
                int *);
int /*<<< orphan*/ u16_ub(char *, int /*<<< orphan*/ *);
size_t sck_recv4(int s, char *b, size_t l, char ip[4], uint16_t *p) {
  struct sockaddr_in si;
  socklen_t len = sizeof si;
  size_t r;
  if ((r = recvfrom(s, b, l, 0, (struct sockaddr *)&si, &len)) < 0)
    return -1;
  if (ip)
    *(uint32_t *)ip = *(uint32_t *)&si.sin_addr;
  if (p)
    u16_ub((char *)&si.sin_port, p);
  return r;
}


x86 assembly (clang, -O0):
<sck_recv4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x8,-0x3c(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x38(%rbp),%r8
xor    %ecx,%ecx
lea    -0x3c(%rbp),%r9
call   1040 <recvfrom@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jae    1177 <sck_recv4+0x57>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11ab <sck_recv4+0x8b>
cmpq   $0x0,-0x28(%rbp)
je     118b <sck_recv4+0x6b>
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x30(%rbp)
je     11a3 <sck_recv4+0x83>
lea    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <u16_ub@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sck_recv4>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r14
mov    %rcx,%rbx
movl   $0x8,0x4(%rsp)
lea    0x8(%rsp),%r8
lea    0x4(%rsp),%r9
xor    %ecx,%ecx
call   1040 <recvfrom@plt>
mov    %rax,%r15
test   %rbx,%rbx
je     1156 <sck_recv4+0x36>
mov    0xc(%rsp),%eax
mov    %eax,(%rbx)
test   %r14,%r14
je     1168 <sck_recv4+0x48>
lea    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1030 <u16_ub@plt>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
define i64 @sck_recv4(i32 %0, i8* %1, i64 %2, i8* %3, i32* %4) {
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
%14 = alloca i64
store i32 %0, i32* %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i8* %3, i8** %10
store i32* %4, i32** %11
store i32 8, i32* %13
%15 = load i32, i32* %7
%16 = load i8*, i8** %8
%17 = load i64, i64* %9
%18 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%19 = call i64 @recvfrom(i32 %15, i8* %16, i64 %17, i32 0, %struct.sockaddr* %18, i32* %13)
store i64 %19, i64* %14
%20 = icmp ult i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %5
store i64 -1, i64* %6
br label %40
22: ; preds = %5
%23 = load i8*, i8** %10
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%27 = load i32, i32* %26
%28 = load i8*, i8** %10
%29 = bitcast i8* %28 to i32*
store i32 %27, i32* %29
br label %30
30: ; preds = %25, %22
%31 = load i32*, i32** %11
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%35 = bitcast i32* %34 to i8*
%36 = load i32*, i32** %11
%37 = call i32 @u16_ub(i8* %35, i32* %36)
br label %38
38: ; preds = %33, %30
%39 = load i64, i64* %14
store i64 %39, i64* %6
br label %40
40: ; preds = %38, %21
%41 = load i64, i64* %6
ret i64 %41
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
define i64 @sck_recv4(i32 %0, i8* %1, i64 %2, i8* writeonly %3, i32* %4) {
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = bitcast %struct.sockaddr_in* %6 to i8*
%9 = bitcast i32* %7 to i8*
store i32 8, i32* %7
%10 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%11 = call i64 @recvfrom(i32 %0, i8* %1, i64 %2, i32 0, %struct.sockaddr* %10, i32* %7)
%12 = icmp eq i8* %3, null
br i1 %12, label %17, label %13
13: ; preds = %5
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
%15 = load i32, i32* %14
%16 = bitcast i8* %3 to i32*
store i32 %15, i32* %16
br label %17
17: ; preds = %13, %5
%18 = icmp eq i32* %4, null
br i1 %18, label %21, label %19
19: ; preds = %17
%20 = call i32 @u16_ub(i8* %8, i32* %4)
br label %21
21: ; preds = %17, %19
ret i64 %11
}