#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int uint8_t;
typedef int /*<<< orphan*/ tSocketAddr;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ htonl(int);
int /*<<< orphan*/ htons(int);
int sendto(int, int const *, unsigned long, int /*<<< orphan*/,
           struct sockaddr *, int);
int tm_udp_send(int sock, uint8_t ip0, uint8_t ip1, uint8_t ip2, uint8_t ip3,
                int port, const uint8_t *buf, unsigned long buf_len) {
  struct sockaddr_in tSocketAddr;
  tSocketAddr.sin_family = AF_INET;
  tSocketAddr.sin_addr.s_addr = htonl(ip0 << 24 | ip1 << 16 | ip2 << 8 | ip3);
  tSocketAddr.sin_port = htons(port);
  int sent = sendto(sock, buf, buf_len, 0, (struct sockaddr *)&tSocketAddr,
                    sizeof(tSocketAddr));
  return sent;
}


x86 assembly (clang, -O0):
<tm_udp_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    %r9d,-0x18(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
shl    $0x18,%edi
mov    -0xc(%rbp),%eax
shl    $0x10,%eax
or     %eax,%edi
mov    -0x10(%rbp),%eax
shl    $0x8,%eax
or     %eax,%edi
or     -0x14(%rbp),%edi
call   1040 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    0x10(%rbp),%rsi
mov    0x18(%rbp),%rdx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_udp_send>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%ebp
mov    %edi,%ebx
mov    0x40(%rsp),%r14
mov    0x48(%rsp),%r15
mov    0x2e98(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
shl    $0x18,%esi
shl    $0x10,%edx
or     %esi,%edx
shl    $0x8,%ecx
or     %r8d,%ecx
or     %edx,%ecx
mov    %ecx,%edi
call   1040 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    %ebp,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%r8
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
define i32 @tm_udp_send(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32* %6, i64 %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32*
%16 = alloca i64
%17 = alloca %struct.sockaddr_in
%18 = alloca i32
store i32 %0, i32* %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32* %6, i32** %15
store i64 %7, i64* %16
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* %10
%22 = shl i32 %21, 24
%23 = load i32, i32* %11
%24 = shl i32 %23, 16
%25 = or i32 %22, %24
%26 = load i32, i32* %12
%27 = shl i32 %26, 8
%28 = or i32 %25, %27
%29 = load i32, i32* %13
%30 = or i32 %28, %29
%31 = call i32 @htonl(i32 %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 1
%33 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %32, i32 0, i32 0
store i32 %31, i32* %33
%34 = load i32, i32* %14
%35 = call i32 @htons(i32 %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
store i32 %35, i32* %36
%37 = load i32, i32* %9
%38 = load i32*, i32** %15
%39 = load i64, i64* %16
%40 = bitcast %struct.sockaddr_in* %17 to %struct.sockaddr*
%41 = call i32 @sendto(i32 %37, i32* %38, i64 %39, i32 0, %struct.sockaddr* %40, i32 12)
store i32 %41, i32* %18
%42 = load i32, i32* %18
ret i32 %42
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
define i32 @tm_udp_send(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32* %6, i64 %7) {
%9 = alloca %struct.sockaddr_in
%10 = bitcast %struct.sockaddr_in* %9 to i8*
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 2
store i32 %11, i32* %12
%13 = shl i32 %1, 24
%14 = shl i32 %2, 16
%15 = or i32 %14, %13
%16 = shl i32 %3, 8
%17 = or i32 %15, %16
%18 = or i32 %17, %4
%19 = tail call i32 @htonl(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 1, i32 0
store i32 %19, i32* %20
%21 = tail call i32 @htons(i32 %5)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 0
store i32 %21, i32* %22
%23 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%24 = call i32 @sendto(i32 %0, i32* %6, i64 %7, i32 0, %struct.sockaddr* %23, i32 12)
ret i32 %24
}