#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 */
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;
};
typedef int /*<<< orphan*/ addrin;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int sendto(int, void *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int SendMsgByUdp(void *pMsg, int nSize, char *szAddr, int nPort) {
  int nSock;
  struct sockaddr_in addrin;
  assert((nSock = socket(AF_INET, SOCK_DGRAM, 0)) > 0);
  memset(&addrin, 0, sizeof(struct sockaddr));
  addrin.sin_family = AF_INET;
  addrin.sin_addr.s_addr = inet_addr(szAddr);
  addrin.sin_port = htons(nPort);
  assert(sendto(nSock, pMsg, nSize, 0, (struct sockaddr *)&addrin,
                sizeof(addrin)));
  close(nSock);
  return 0;
}


x86 assembly (clang, -O0):
<SendMsgByUdp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    -0x30(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %eax,%edi
call   1080 <assert@plt>
mov    -0x20(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SendMsgByUdp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    %esi,0x4(%rsp)
mov    %rdi,%r15
mov    0x2e56(%rip),%r14
mov    (%r14),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebp
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1080 <assert@plt>
lea    0x8(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    %rbx,%rdi
call   1070 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    %r12d,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    0x4(%rsp),%edx
xor    %ecx,%ecx
mov    %r13,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %eax,%edi
call   1080 <assert@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
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
@SOCK_DGRAM = global i32 0
define i32 @SendMsgByUdp(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %9
%14 = icmp sgt i32 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i32 @memset(%struct.sockaddr_in* %10, i32 0, i32 4)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %18, i32* %19
%20 = load i8*, i8** %7
%21 = call i32 @inet_addr(i8* %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load i32, i32* %8
%25 = call i32 @htons(i32 %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* %9
%28 = load i8*, i8** %5
%29 = load i32, i32* %6
%30 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%31 = call i32 @sendto(i32 %27, i8* %28, i32 %29, i32 0, %struct.sockaddr* %30, i32 12)
%32 = call i32 @assert(i32 %31)
%33 = load i32, i32* %9
%34 = call i32 @close(i32 %33)
ret i32 0
}

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
@SOCK_DGRAM = global i32 0
define i32 @SendMsgByUdp(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca %struct.sockaddr_in
%6 = bitcast %struct.sockaddr_in* %5 to i8*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp sgt i32 %9, 0
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 4)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @inet_addr(i8* %2)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %16, i32* %17
%18 = call i32 @htons(i32 %3)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%21 = call i32 @sendto(i32 %9, i8* %0, i32 %1, i32 0, %struct.sockaddr* %20, i32 12)
%22 = call i32 @assert(i32 %21)
%23 = call i32 @close(i32 %9)
ret i32 0
}