#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 udphdr {
  int check;
  void *len;
  void *dest;
  void *source;
};
struct sockaddr_ll {
  int sll_ifindex;
  int sll_halen;
  unsigned char *sll_addr;
  int /*<<< orphan*/ sll_pkttype;
  int /*<<< orphan*/ sll_hatype;
  void *sll_protocol;
  int /*<<< orphan*/ sll_family;
};
struct sockaddr {
  int dummy;
};
struct iphdr {
  int version;
  int ihl;
  int tos;
  int ttl;
  int protocol;
  int check;
  int /*<<< orphan*/ daddr;
  int /*<<< orphan*/ saddr;
  void *frag_off;
  void *id;
  void *tot_len;
};
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
struct ethhdr {
  unsigned char *h_source;
  unsigned char *h_dest;
  int h_proto;
};
typedef int /*<<< orphan*/ socket_address;

/* Variables and functions */
int /*<<< orphan*/ ARPHRD_ETHER;
int const ETH_ALEN;
int ETH_FRAME_LEN;
int ETH_P_IP;
int /*<<< orphan*/ PACKET_OTHERHOST;
int /*<<< orphan*/ PF_PACKET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(void *);
void *htons(int const);
int in_cksum(unsigned short *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int const);
int /*<<< orphan*/ perror(char *);
int sendto(int const, void *, int const, int /*<<< orphan*/, struct sockaddr *,
           int);
int /*<<< orphan*/ stderr;
int udp_sum_calc(unsigned char *, unsigned char *, unsigned char *, int);
int send_custom_udp(const int socket, const int ifindex,
                    const unsigned char *sourcemac,
                    const unsigned char *destmac,
                    const struct in_addr *sourceip, const int sourceport,
                    const struct in_addr *destip, const int destport,
                    const unsigned char *data, const int datalen) {
  struct sockaddr_ll socket_address;
  void *buffer = (void *)malloc(ETH_FRAME_LEN);
  struct ethhdr *eh = (struct ethhdr *)buffer;
  struct iphdr *ip = (struct iphdr *)(buffer + 14);
  struct udphdr *udp = (struct udphdr *)(buffer + 14 + 20);
  unsigned char *rest =
      (unsigned char *)(buffer + 20 + 14 + sizeof(struct udphdr));
  if (((void *)rest - (void *)buffer) + datalen > ETH_FRAME_LEN) {
    fprintf(stderr, "packet size too large\n");
    free(buffer);
    return 0;
  }
  static unsigned int id = 1;
  int send_result = 0;
  if (buffer == NULL) {
    perror("malloc");
    exit(1);
  }
  memcpy(eh->h_source, sourcemac, ETH_ALEN);
  memcpy(eh->h_dest, destmac, ETH_ALEN);
  eh->h_proto = 8;
  socket_address.sll_family = PF_PACKET;
  socket_address.sll_protocol = htons(ETH_P_IP);
  socket_address.sll_ifindex = ifindex;
  socket_address.sll_hatype = ARPHRD_ETHER;
  socket_address.sll_pkttype = PACKET_OTHERHOST;
  socket_address.sll_halen = ETH_ALEN;
  memcpy(socket_address.sll_addr, eh->h_source, ETH_ALEN);
  socket_address.sll_addr[6] = 0x00;
  socket_address.sll_addr[7] = 0x00;
  ip->version = 4;
  ip->ihl = 5;
  ip->tos = 0x10;
  ip->tot_len = htons(datalen + 8 + 20);
  ip->id = htons(id++);
  ip->frag_off = htons(0x4000);
  ip->ttl = 64;
  ip->protocol = 17;
  ip->check = 0x0000;
  ip->saddr = sourceip->s_addr;
  ip->daddr = destip->s_addr;
  ip->check = in_cksum((unsigned short *)ip, sizeof(struct iphdr));
  udp->source = htons(sourceport);
  udp->dest = htons(destport);
  udp->len = htons(sizeof(struct udphdr) + datalen);
  udp->check = 0;
  memcpy(rest, data, datalen);
  udp->check =
      udp_sum_calc((unsigned char *)&(ip->saddr), (unsigned char *)&(ip->daddr),
                   (unsigned char *)udp, sizeof(struct udphdr) + datalen);
  udp->check = htons(udp->check);
  send_result =
      sendto(socket, buffer, datalen + 8 + 14 + 20, 0,
             (struct sockaddr *)&socket_address, sizeof(socket_address));
  free(buffer);
  return send_result - 8 - 14 - 20;
}


x86 assembly (clang, -O0):
<send_custom_udp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1090 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x60(%rbp),%rax
add    $0xe,%rax
mov    %rax,-0x70(%rbp)
mov    -0x60(%rbp),%rax
add    $0xe,%rax
add    $0x14,%rax
mov    %rax,-0x78(%rbp)
mov    -0x60(%rbp),%rax
add    $0x14,%rax
add    $0xe,%rax
add    $0x20,%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
mov    -0x60(%rbp),%rcx
sub    %rcx,%rax
movslq 0x28(%rbp),%rcx
add    %rcx,%rax
mov    0x2d86(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jle    1268 <send_custom_udp+0xc8>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    14e0 <send_custom_udp+0x340>
movl   $0x0,-0x84(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    1293 <send_custom_udp+0xf3>
lea    0xd93(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x68(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2d3b(%rip),%rax
mov    (%rax),%edx
call   1080 <memcpy@plt>
mov    -0x68(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2d21(%rip),%rax
mov    (%rax),%edx
call   1080 <memcpy@plt>
mov    -0x68(%rbp),%rax
movl   $0x8,0x10(%rax)
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
call   1050 <htons@plt>
mov    %rax,-0x40(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x2cdc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2ca8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2ccc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x68(%rbp),%rax
mov    (%rax),%rsi
mov    0x2cb5(%rip),%rax
mov    (%rax),%edx
call   1080 <memcpy@plt>
mov    -0x50(%rbp),%rax
movb   $0x0,0x6(%rax)
mov    -0x50(%rbp),%rax
movb   $0x0,0x7(%rax)
mov    -0x70(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x70(%rbp),%rax
movl   $0x5,0x4(%rax)
mov    -0x70(%rbp),%rax
movl   $0x10,0x8(%rax)
mov    0x28(%rbp),%edi
add    $0x8,%edi
add    $0x14,%edi
call   1050 <htons@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
mov    %rcx,0x30(%rax)
mov    0x2cef(%rip),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,0x2ce4(%rip)
call   1050 <htons@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    $0x4000,%edi
call   1050 <htons@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x70(%rbp),%rax
movl   $0x40,0xc(%rax)
mov    -0x70(%rbp),%rax
movl   $0x11,0x10(%rax)
mov    -0x70(%rbp),%rax
movl   $0x0,0x14(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
mov    -0x70(%rbp),%rax
mov    %ecx,0x1c(%rax)
mov    0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x70(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x70(%rbp),%rdi
mov    $0x38,%esi
call   1040 <in_cksum@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0x2c(%rbp),%edi
call   1050 <htons@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    0x18(%rbp),%edi
call   1050 <htons@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
mov    %rcx,0x10(%rax)
movslq 0x28(%rbp),%rax
add    $0x20,%rax
mov    %eax,%edi
call   1050 <htons@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x78(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x80(%rbp),%rdi
mov    0x20(%rbp),%rsi
mov    0x28(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x70(%rbp),%rdi
add    $0x1c,%rdi
mov    -0x70(%rbp),%rsi
add    $0x18,%rsi
mov    -0x78(%rbp),%rdx
movslq 0x28(%rbp),%rax
add    $0x20,%rax
mov    %eax,%ecx
call   10b0 <udp_sum_calc@plt>
mov    %eax,%ecx
mov    -0x78(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x78(%rbp),%rax
mov    (%rax),%edi
call   1050 <htons@plt>
mov    %eax,%ecx
mov    -0x78(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    0x28(%rbp),%edx
add    $0x8,%edx
add    $0xe,%edx
add    $0x14,%edx
lea    -0x58(%rbp),%r8
xor    %ecx,%ecx
mov    $0x28,%r9d
call   1060 <sendto@plt>
mov    %eax,-0x84(%rbp)
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x84(%rbp),%eax
sub    $0x8,%eax
sub    $0xe,%eax
sub    $0x14,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_custom_udp>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
movslq 0x48(%rsp),%rbx
mov    0x2e45(%rip),%r13
mov    0x0(%r13),%edi
call   1070 <malloc@plt>
mov    %rax,%r12
add    $0x42,%rbx
movslq 0x0(%r13),%rax
cmp    %rax,%rbx
jle    11cd <send_custom_udp+0x5d>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
test   %r12,%r12
jne    11e8 <send_custom_udp+0x78>
lea    0xe3e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    (%r12),%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1060 <memcpy@plt>
mov    0x8(%r12),%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1060 <memcpy@plt>
movl   $0x8,0x10(%r12)
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   1040 <htons@plt>
mov    (%r12),%rsi
xor    %edx,%edx
call   1060 <memcpy@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.sockaddr_ll = type { i32, i32, i8*, i32, i32, i8*, i32 }
%struct.ethhdr = type { i8*, i8*, i32 }
%struct.iphdr = type { i32, i32, i32, i32, i32, i32, i32, i32, i8*, i8*, i8* }
%struct.udphdr = type { i32, i8*, i8*, i8* }
%struct.sockaddr = type { i32 }
@ETH_FRAME_LEN = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"packet size too large\0A\00"
@send_custom_udp.id = internal global i32 1
@.str.1 = [7 x i8] c"malloc\00"
@ETH_ALEN = constant i32 0
@PF_PACKET = global i32 0
@ETH_P_IP = global i32 0
@ARPHRD_ETHER = global i32 0
@PACKET_OTHERHOST = global i32 0
define i32 @send_custom_udp(i32 %0, i32 %1, i8* %2, i8* %3, %struct.in_addr* %4, i32 %5, %struct.in_addr* %6, i32 %7, i8* %8, i32 %9) {
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca %struct.in_addr*
%17 = alloca i32
%18 = alloca %struct.in_addr*
%19 = alloca i32
%20 = alloca i8*
%21 = alloca i32
%22 = alloca %struct.sockaddr_ll
%23 = alloca i8*
%24 = alloca %struct.ethhdr*
%25 = alloca %struct.iphdr*
%26 = alloca %struct.udphdr*
%27 = alloca i8*
%28 = alloca i32
store i32 %0, i32* %12
store i32 %1, i32* %13
store i8* %2, i8** %14
store i8* %3, i8** %15
store %struct.in_addr* %4, %struct.in_addr** %16
store i32 %5, i32* %17
store %struct.in_addr* %6, %struct.in_addr** %18
store i32 %7, i32* %19
store i8* %8, i8** %20
store i32 %9, i32* %21
%29 = load i32, i32* @ETH_FRAME_LEN
%30 = call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %23
%32 = load i8*, i8** %23
%33 = bitcast i8* %32 to %struct.ethhdr*
store %struct.ethhdr* %33, %struct.ethhdr** %24
%34 = load i8*, i8** %23
%35 = getelementptr i8, i8* %34, i64 14
%36 = bitcast i8* %35 to %struct.iphdr*
store %struct.iphdr* %36, %struct.iphdr** %25
%37 = load i8*, i8** %23
%38 = getelementptr i8, i8* %37, i64 14
%39 = getelementptr i8, i8* %38, i64 20
%40 = bitcast i8* %39 to %struct.udphdr*
store %struct.udphdr* %40, %struct.udphdr** %26
%41 = load i8*, i8** %23
%42 = getelementptr i8, i8* %41, i64 20
%43 = getelementptr i8, i8* %42, i64 14
%44 = getelementptr i8, i8* %43, i64 32
store i8* %44, i8** %27
%45 = load i8*, i8** %27
%46 = load i8*, i8** %23
%47 = ptrtoint i8* %45 to i64
%48 = ptrtoint i8* %46 to i64
%49 = sub i64 %47, %48
%50 = load i32, i32* %21
%51 = sext i32 %50 to i64
%52 = add nsw i64 %49, %51
%53 = load i32, i32* @ETH_FRAME_LEN
%54 = sext i32 %53 to i64
%55 = icmp sgt i64 %52, %54
br i1 %55, label %56, label %61
56: ; preds = %10
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%59 = load i8*, i8** %23
%60 = call i32 @free(i8* %59)
store i32 0, i32* %11
br label %206
61: ; preds = %10
store i32 0, i32* %28
%62 = load i8*, i8** %23
%63 = icmp eq i8* %62, null
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %61
%68 = load %struct.ethhdr*, %struct.ethhdr** %24
%69 = getelementptr inbounds %struct.ethhdr, %struct.ethhdr* %68, i32 0, i32 0
%70 = load i8*, i8** %69
%71 = load i8*, i8** %14
%72 = load i32, i32* @ETH_ALEN
%73 = call i32 @memcpy(i8* %70, i8* %71, i32 %72)
%74 = load %struct.ethhdr*, %struct.ethhdr** %24
%75 = getelementptr inbounds %struct.ethhdr, %struct.ethhdr* %74, i32 0, i32 1
%76 = load i8*, i8** %75
%77 = load i8*, i8** %15
%78 = load i32, i32* @ETH_ALEN
%79 = call i32 @memcpy(i8* %76, i8* %77, i32 %78)
%80 = load %struct.ethhdr*, %struct.ethhdr** %24
%81 = getelementptr inbounds %struct.ethhdr, %struct.ethhdr* %80, i32 0, i32 2
store i32 8, i32* %81
%82 = load i32, i32* @PF_PACKET
%83 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %22, i32 0, i32 6
store i32 %82, i32* %83
%84 = load i32, i32* @ETH_P_IP
%85 = call i8* @htons(i32 %84)
%86 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %22, i32 0, i32 5
store i8* %85, i8** %86
%87 = load i32, i32* %13
%88 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %22, i32 0, i32 0
store i32 %87, i32* %88
%89 = load i32, i32* @ARPHRD_ETHER
%90 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %22, i32 0, i32 4
store i32 %89, i32* %90
%91 = load i32, i32* @PACKET_OTHERHOST
%92 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %22, i32 0, i32 3
store i32 %91, i32* %92
%93 = load i32, i32* @ETH_ALEN
%94 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %22, i32 0, i32 1
store i32 %93, i32* %94
%95 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %22, i32 0, i32 2
%96 = load i8*, i8** %95
%97 = load %struct.ethhdr*, %struct.ethhdr** %24
%98 = getelementptr inbounds %struct.ethhdr, %struct.ethhdr* %97, i32 0, i32 0
%99 = load i8*, i8** %98
%100 = load i32, i32* @ETH_ALEN
%101 = call i32 @memcpy(i8* %96, i8* %99, i32 %100)
%102 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %22, i32 0, i32 2
%103 = load i8*, i8** %102
%104 = getelementptr inbounds i8, i8* %103, i64 6
store i8 0, i8* %104
%105 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %22, i32 0, i32 2
%106 = load i8*, i8** %105
%107 = getelementptr inbounds i8, i8* %106, i64 7
store i8 0, i8* %107
%108 = load %struct.iphdr*, %struct.iphdr** %25
%109 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %108, i32 0, i32 0
store i32 4, i32* %109
%110 = load %struct.iphdr*, %struct.iphdr** %25
%111 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %110, i32 0, i32 1
store i32 5, i32* %111
%112 = load %struct.iphdr*, %struct.iphdr** %25
%113 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %112, i32 0, i32 2
store i32 16, i32* %113
%114 = load i32, i32* %21
%115 = add nsw i32 %114, 8
%116 = add nsw i32 %115, 20
%117 = call i8* @htons(i32 %116)
%118 = load %struct.iphdr*, %struct.iphdr** %25
%119 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %118, i32 0, i32 10
store i8* %117, i8** %119
%120 = load i32, i32* @send_custom_udp.id
%121 = add i32 %120, 1
store i32 %121, i32* @send_custom_udp.id
%122 = call i8* @htons(i32 %120)
%123 = load %struct.iphdr*, %struct.iphdr** %25
%124 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %123, i32 0, i32 9
store i8* %122, i8** %124
%125 = call i8* @htons(i32 16384)
%126 = load %struct.iphdr*, %struct.iphdr** %25
%127 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %126, i32 0, i32 8
store i8* %125, i8** %127
%128 = load %struct.iphdr*, %struct.iphdr** %25
%129 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %128, i32 0, i32 3
store i32 64, i32* %129
%130 = load %struct.iphdr*, %struct.iphdr** %25
%131 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %130, i32 0, i32 4
store i32 17, i32* %131
%132 = load %struct.iphdr*, %struct.iphdr** %25
%133 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %132, i32 0, i32 5
store i32 0, i32* %133
%134 = load %struct.in_addr*, %struct.in_addr** %16
%135 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %134, i32 0, i32 0
%136 = load i32, i32* %135
%137 = load %struct.iphdr*, %struct.iphdr** %25
%138 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %137, i32 0, i32 7
store i32 %136, i32* %138
%139 = load %struct.in_addr*, %struct.in_addr** %18
%140 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %139, i32 0, i32 0
%141 = load i32, i32* %140
%142 = load %struct.iphdr*, %struct.iphdr** %25
%143 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %142, i32 0, i32 6
store i32 %141, i32* %143
%144 = load %struct.iphdr*, %struct.iphdr** %25
%145 = bitcast %struct.iphdr* %144 to i16*
%146 = call i32 @in_cksum(i16* %145, i32 56)
%147 = load %struct.iphdr*, %struct.iphdr** %25
%148 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %147, i32 0, i32 5
store i32 %146, i32* %148
%149 = load i32, i32* %17
%150 = call i8* @htons(i32 %149)
%151 = load %struct.udphdr*, %struct.udphdr** %26
%152 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %151, i32 0, i32 3
store i8* %150, i8** %152
%153 = load i32, i32* %19
%154 = call i8* @htons(i32 %153)
%155 = load %struct.udphdr*, %struct.udphdr** %26
%156 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %155, i32 0, i32 2
store i8* %154, i8** %156
%157 = load i32, i32* %21
%158 = sext i32 %157 to i64
%159 = add i64 32, %158
%160 = trunc i64 %159 to i32
%161 = call i8* @htons(i32 %160)
%162 = load %struct.udphdr*, %struct.udphdr** %26
%163 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %162, i32 0, i32 1
store i8* %161, i8** %163
%164 = load %struct.udphdr*, %struct.udphdr** %26
%165 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %164, i32 0, i32 0
store i32 0, i32* %165
%166 = load i8*, i8** %27
%167 = load i8*, i8** %20
%168 = load i32, i32* %21
%169 = call i32 @memcpy(i8* %166, i8* %167, i32 %168)
%170 = load %struct.iphdr*, %struct.iphdr** %25
%171 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %170, i32 0, i32 7
%172 = bitcast i32* %171 to i8*
%173 = load %struct.iphdr*, %struct.iphdr** %25
%174 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %173, i32 0, i32 6
%175 = bitcast i32* %174 to i8*
%176 = load %struct.udphdr*, %struct.udphdr** %26
%177 = bitcast %struct.udphdr* %176 to i8*
%178 = load i32, i32* %21
%179 = sext i32 %178 to i64
%180 = add i64 32, %179
%181 = trunc i64 %180 to i32
%182 = call i32 @udp_sum_calc(i8* %172, i8* %175, i8* %177, i32 %181)
%183 = load %struct.udphdr*, %struct.udphdr** %26
%184 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %183, i32 0, i32 0
store i32 %182, i32* %184
%185 = load %struct.udphdr*, %struct.udphdr** %26
%186 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %185, i32 0, i32 0
%187 = load i32, i32* %186
%188 = call i8* @htons(i32 %187)
%189 = ptrtoint i8* %188 to i32
%190 = load %struct.udphdr*, %struct.udphdr** %26
%191 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %190, i32 0, i32 0
store i32 %189, i32* %191
%192 = load i32, i32* %12
%193 = load i8*, i8** %23
%194 = load i32, i32* %21
%195 = add nsw i32 %194, 8
%196 = add nsw i32 %195, 14
%197 = add nsw i32 %196, 20
%198 = bitcast %struct.sockaddr_ll* %22 to %struct.sockaddr*
%199 = call i32 @sendto(i32 %192, i8* %193, i32 %197, i32 0, %struct.sockaddr* %198, i32 40)
store i32 %199, i32* %28
%200 = load i8*, i8** %23
%201 = call i32 @free(i8* %200)
%202 = load i32, i32* %28
%203 = sub nsw i32 %202, 8
%204 = sub nsw i32 %203, 14
%205 = sub nsw i32 %204, 20
store i32 %205, i32* %11
br label %206
206: ; preds = %67, %56
%207 = load i32, i32* %11
ret i32 %207
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.ethhdr = type { i8*, i8*, i32 }
@ETH_FRAME_LEN = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"packet size too large\0A\00"
@.str.1 = [7 x i8] c"malloc\00"
@ETH_ALEN = constant i32 0
@PF_PACKET = global i32 0
@ETH_P_IP = global i32 0
@ARPHRD_ETHER = global i32 0
@PACKET_OTHERHOST = global i32 0
define i32 @send_custom_udp(i32 %0, i32 %1, i8* %2, i8* %3, %struct.in_addr* nocapture %4, i32 %5, %struct.in_addr* nocapture %6, i32 %7, i8* %8, i32 %9) {
%11 = load i32, i32* @ETH_FRAME_LEN
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = inttoptr i64 %12 to %struct.ethhdr*
%15 = getelementptr i8, i8* %13, i64 66
%16 = ptrtoint i8* %15 to i64
%17 = sext i32 %9 to i64
%18 = sub i64 %17, %12
%19 = add i64 %18, %16
%20 = load i32, i32* @ETH_FRAME_LEN
%21 = sext i32 %20 to i64
%22 = icmp sgt i64 %19, %21
br i1 %22, label %23, label %27
23: ; preds = %10
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%26 = tail call i32 @free(i8* %13)
ret i32 0
27: ; preds = %10
%28 = icmp eq i64 %12, 0
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %27
%33 = getelementptr inbounds %struct.ethhdr, %struct.ethhdr* %14, i64 0, i32 0
%34 = load i8*, i8** %33
%35 = tail call i32 @memcpy(i8* %34, i8* %2, i32 0)
%36 = getelementptr inbounds %struct.ethhdr, %struct.ethhdr* %14, i64 0, i32 1
%37 = load i8*, i8** %36
%38 = tail call i32 @memcpy(i8* %37, i8* %3, i32 0)
%39 = getelementptr inbounds %struct.ethhdr, %struct.ethhdr* %14, i64 0, i32 2
store i32 8, i32* %39
%40 = load i32, i32* @ETH_P_IP
%41 = tail call i8* @htons(i32 %40)
%42 = load i8*, i8** %33
%43 = tail call i32 @memcpy(i8* undef, i8* %42, i32 0)
unreachable
}