#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*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
struct sockaddr {
  int /*<<< orphan*/ *sa_data;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
long recvfrom(int, int /*<<< orphan*/ *, unsigned long, int /*<<< orphan*/,
              struct sockaddr *, int /*<<< orphan*/ *);
int tm_udp_receive(int sock, uint8_t *buf, unsigned long buf_len,
                   uint32_t *ip) {
  struct sockaddr from;
  socklen_t from_len;
  signed long ret = recvfrom(sock, buf, buf_len, 0, &from, &from_len);
  memcpy(ip, &(from.sa_data[2]), sizeof(unsigned));
  return ret;
}


x86 assembly (clang, -O0):
<tm_udp_receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
lea    -0x28(%rbp),%r8
lea    -0x2c(%rbp),%r9
call   1040 <recvfrom@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x8,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_udp_receive>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
lea    0x8(%rsp),%r8
lea    0x14(%rsp),%r9
xor    %ecx,%ecx
call   1040 <recvfrom@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rsi
add    $0x8,%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32* }
define i32 @tm_udp_receive(i32 %0, i32* %1, i64 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca %struct.sockaddr
%10 = alloca i32
%11 = alloca i64
store i32 %0, i32* %5
store i32* %1, i32** %6
store i64 %2, i64* %7
store i32* %3, i32** %8
%12 = load i32, i32* %5
%13 = load i32*, i32** %6
%14 = load i64, i64* %7
%15 = call i64 @recvfrom(i32 %12, i32* %13, i64 %14, i32 0, %struct.sockaddr* %9, i32* %10)
store i64 %15, i64* %11
%16 = load i32*, i32** %8
%17 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %9, i32 0, i32 0
%18 = load i32*, i32** %17
%19 = getelementptr inbounds i32, i32* %18, i64 2
%20 = call i32 @memcpy(i32* %16, i32* %19, i32 4)
%21 = load i64, i64* %11
%22 = trunc i64 %21 to i32
ret i32 %22
}

LLVM IR (-O2):
%struct.sockaddr = type { i32* }
define i32 @tm_udp_receive(i32 %0, i32* %1, i64 %2, i32* %3) {
%5 = alloca %struct.sockaddr
%6 = alloca i32
%7 = bitcast %struct.sockaddr* %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = call i64 @recvfrom(i32 %0, i32* %1, i64 %2, i32 0, %struct.sockaddr* %5, i32* %6)
%10 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %5, i64 0, i32 0
%11 = load i32*, i32** %10
%12 = getelementptr inbounds i32, i32* %11, i64 2
%13 = call i32 @memcpy(i32* %3, i32* %12, i32 4)
%14 = trunc i64 %9 to i32
ret i32 %14
}