#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 void *uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ uint16_t;
struct udphdr {
  void *len;
  scalar_t__ check;
  void *dest;
  void *source;
};
struct iphdr {
  int ihl;
  int version;
  int tos;
  int protocol;
  int saddr;
  int daddr;
  int /*<<< orphan*/ check;
  void *tot_len;
  void *ttl;
  void *id;
};
struct ether_header {
  void *ether_type;
  void **ether_dhost;
  void **ether_shost;
};

/* Variables and functions */
int ETH_P_IP;
int /*<<< orphan*/ csum(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *htons(int);
int /*<<< orphan*/ memset(void **, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
uint32_t packet_udp(uint8_t *_buf, uint32_t _len, uint8_t *_smac,
                    uint8_t *_dmac, uint32_t _sip, uint32_t _dip) {
  struct ether_header *eh = (struct ether_header *)_buf;
  struct iphdr *iph = (struct iphdr *)(_buf + sizeof(struct ether_header));
  struct udphdr *udph = (struct udphdr *)(_buf + sizeof(struct iphdr) +
                                          sizeof(struct ether_header));
  uint8_t ttl = 60;
  uint32_t ind = 0;
  if (_buf == NULL || _smac == NULL || _dmac == NULL) {
    fprintf(stderr,
            "error: packet_udp() buf or _smac or _dmac argument is NULL\n");
    exit(21);
  }
  if (_len < (sizeof(struct ether_header) + sizeof(struct iphdr) +
              sizeof(struct udphdr) + 4)) {
    fprintf(stderr, "error: packet_udp() argument len is too short\n");
    exit(21);
  }
  memset(_buf, 0, _len);
  eh->ether_shost[0] = _smac[0];
  eh->ether_shost[1] = _smac[1];
  eh->ether_shost[2] = _smac[2];
  eh->ether_shost[3] = _smac[3];
  eh->ether_shost[4] = _smac[4];
  eh->ether_shost[5] = _smac[5];
  eh->ether_dhost[0] = _dmac[0];
  eh->ether_dhost[1] = _dmac[1];
  eh->ether_dhost[2] = _dmac[2];
  eh->ether_dhost[3] = _dmac[3];
  eh->ether_dhost[4] = _dmac[4];
  eh->ether_dhost[5] = _dmac[5];
  eh->ether_type = htons(ETH_P_IP);
  ind += sizeof(struct ether_header);
  iph->ihl = 5;
  iph->version = 4;
  iph->tos = 16;
  iph->id = htons(54321);
  iph->ttl = ttl;
  iph->protocol = 17;
  iph->saddr = _sip;
  iph->daddr = _dip;
  ind += sizeof(struct iphdr);
  udph->source = htons(33423);
  udph->dest = htons(35342);
  udph->check = 0;
  ind += sizeof(struct udphdr);
  _buf[ind++] = 0xde;
  _buf[ind++] = 0xad;
  _buf[ind++] = 0xbe;
  _buf[ind++] = 0xef;
  udph->len = htons(ind - sizeof(struct ether_header) - sizeof(struct iphdr));
  iph->tot_len = htons(ind - sizeof(struct ether_header));
  iph->check = csum((uint16_t *)(_buf + sizeof(struct ether_header)),
                    (uint16_t)sizeof(struct iphdr));
  return ind;
}


x86 assembly (clang, -O0):
<packet_udp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc0,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1c0,%rax
add    $0xc0,%rax
mov    %rax,-0x40(%rbp)
mov    $0x3c,%eax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ca <packet_udp+0x7a>
cmpq   $0x0,-0x18(%rbp)
je     11ca <packet_udp+0x7a>
cmpq   $0x0,-0x20(%rbp)
jne    11e9 <packet_udp+0x99>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x15,%edi
call   1070 <exit@plt>
movslq -0xc(%rbp),%rax
cmp    $0x74,%rax
jae    1216 <packet_udp+0xc6>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x15,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rcx,0x10(%rax)
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rcx
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rcx,0x18(%rax)
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%rcx
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rcx,0x20(%rax)
mov    -0x18(%rbp),%rax
mov    0x28(%rax),%rcx
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rcx,0x28(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rcx,0x8(%rax)
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rcx,0x10(%rax)
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rcx
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rcx,0x18(%rax)
mov    -0x20(%rbp),%rax
mov    0x20(%rax),%rcx
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rcx,0x20(%rax)
mov    -0x20(%rbp),%rax
mov    0x28(%rax),%rcx
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rcx,0x28(%rax)
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
call   1040 <htons@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
movslq -0x4c(%rbp),%rax
add    $0x18,%rax
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
movl   $0x5,(%rax)
mov    -0x38(%rbp),%rax
movl   $0x4,0x4(%rax)
mov    -0x38(%rbp),%rax
movl   $0x10,0x8(%rax)
mov    $0xd431,%edi
call   1040 <htons@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x30(%rax)
mov    -0x48(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    -0x38(%rbp),%rax
movl   $0x11,0xc(%rax)
mov    -0x24(%rbp),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x28(%rbp),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,0x14(%rax)
movslq -0x4c(%rbp),%rax
add    $0x38,%rax
mov    %eax,-0x4c(%rbp)
mov    $0x828f,%edi
call   1040 <htons@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    $0x8a0e,%edi
call   1040 <htons@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x40(%rbp),%rax
movq   $0x0,0x8(%rax)
movslq -0x4c(%rbp),%rax
add    $0x20,%rax
mov    %eax,-0x4c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x4c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x4c(%rbp)
movslq %ecx,%rcx
mov    $0xde,%edx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    -0x4c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x4c(%rbp)
movslq %ecx,%rcx
mov    $0xad,%edx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    -0x4c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x4c(%rbp)
movslq %ecx,%rcx
mov    $0xbe,%edx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    -0x4c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x4c(%rbp)
movslq %ecx,%rcx
mov    $0xef,%edx
mov    %rdx,(%rax,%rcx,8)
movslq -0x4c(%rbp),%rax
sub    $0x18,%rax
sub    $0x38,%rax
mov    %eax,%edi
call   1040 <htons@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,(%rax)
movslq -0x4c(%rbp),%rax
sub    $0x18,%rax
mov    %eax,%edi
call   1040 <htons@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x8(%rbp),%rdi
add    $0xc0,%rdi
mov    $0x38,%esi
call   1030 <csum@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x4c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<packet_udp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     132e <packet_udp+0x1de>
mov    %rdx,%rbp
test   %rdx,%rdx
je     132e <packet_udp+0x1de>
mov    %rcx,%r13
test   %rcx,%rcx
je     132e <packet_udp+0x1de>
mov    %esi,%edx
cmp    $0x73,%esi
jbe    1340 <packet_udp+0x1f0>
mov    %r9d,%r15d
mov    %r8d,%r12d
mov    %rdi,%rbx
lea    0xc0(%rdi),%r14
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x0(%rbp),%rax
mov    0x10(%rbx),%rcx
mov    %rax,(%rcx)
mov    0x8(%rbp),%rax
mov    0x10(%rbx),%rcx
mov    %rax,0x8(%rcx)
mov    0x10(%rbp),%rax
mov    0x10(%rbx),%rcx
mov    %rax,0x10(%rcx)
mov    0x18(%rbp),%rax
mov    0x10(%rbx),%rcx
mov    %rax,0x18(%rcx)
mov    0x20(%rbp),%rax
mov    0x10(%rbx),%rcx
mov    %rax,0x20(%rcx)
mov    0x28(%rbp),%rax
mov    0x10(%rbx),%rcx
mov    %rax,0x28(%rcx)
mov    0x0(%r13),%rax
mov    0x8(%rbx),%rcx
mov    %rax,(%rcx)
mov    0x8(%r13),%rax
mov    0x8(%rbx),%rcx
mov    %rax,0x8(%rcx)
mov    0x10(%r13),%rax
mov    0x8(%rbx),%rcx
mov    %rax,0x10(%rcx)
mov    0x18(%r13),%rax
mov    0x8(%rbx),%rcx
mov    %rax,0x18(%rcx)
mov    0x20(%r13),%rax
mov    0x8(%rbx),%rcx
mov    %rax,0x20(%rcx)
mov    0x28(%r13),%rax
mov    0x8(%rbx),%rcx
mov    %rax,0x28(%rcx)
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   1040 <htons@plt>
mov    %rax,(%rbx)
movabs $0x400000005,%rax
mov    %rax,0xc0(%rbx)
movl   $0x10,0xc8(%rbx)
mov    $0xd431,%edi
call   1040 <htons@plt>
mov    %rax,0xf0(%rbx)
movq   $0x3c,0xe8(%rbx)
movl   $0x11,0xcc(%rbx)
mov    %r12d,0xd0(%rbx)
mov    %r15d,0xd4(%rbx)
mov    $0x828f,%edi
call   1040 <htons@plt>
mov    %rax,0x298(%rbx)
mov    $0x8a0e,%edi
call   1040 <htons@plt>
mov    %rax,0x290(%rbx)
movq   $0x0,0x288(%rbx)
movq   $0xde,0x380(%rbx)
movq   $0xad,0x388(%rbx)
movq   $0xbe,0x390(%rbx)
movq   $0xef,0x398(%rbx)
mov    $0x24,%edi
call   1040 <htons@plt>
mov    %rax,0x280(%rbx)
mov    $0x5c,%edi
call   1040 <htons@plt>
mov    %rax,0xe0(%rbx)
mov    %r14,%rdi
mov    $0x38,%esi
call   1030 <csum@plt>
mov    %eax,0xd8(%rbx)
mov    $0x74,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
lea    0xcc2(%rip),%rsi
jmp    1350 <packet_udp+0x200>
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
lea    0xcec(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x15,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
%struct.iphdr = type { i32, i32, i32, i32, i32, i32, i32, i8*, i8*, i8* }
@stderr = global i32 0
@.str = [60 x i8] c"error: packet_udp() buf or _smac or _dmac argument is NULL\0A\00"
@.str.1 = [47 x i8] c"error: packet_udp() argument len is too short\0A\00"
@ETH_P_IP = global i32 0
define i32 @packet_udp(i8** %0, i32 %1, i8** %2, i8** %3, i32 %4, i32 %5) {
%7 = getelementptr inbounds i8*, i8** %0, i64 24
%8 = bitcast i8** %7 to %struct.iphdr*
%9 = icmp eq i8** %0, null
%10 = icmp eq i8** %2, null
%11 = or i1 %9, %10
%12 = icmp eq i8** %3, null
%13 = or i1 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %6
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 21)
unreachable
18: ; preds = %6
%19 = icmp ult i32 %1, 116
br i1 %19, label %20, label %24
20: ; preds = %18
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @exit(i32 21)
unreachable
24: ; preds = %18
%25 = getelementptr inbounds i8*, i8** %0, i64 80
%26 = tail call i32 @memset(i8** %0, i32 0, i32 %1)
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8*, i8** %0, i64 2
%29 = bitcast i8** %28 to i8***
%30 = load i8**, i8*** %29
store i8* %27, i8** %30
%31 = getelementptr inbounds i8*, i8** %2, i64 1
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %29
%34 = getelementptr inbounds i8*, i8** %33, i64 1
store i8* %32, i8** %34
%35 = getelementptr inbounds i8*, i8** %2, i64 2
%36 = load i8*, i8** %35
%37 = load i8**, i8*** %29
%38 = getelementptr inbounds i8*, i8** %37, i64 2
store i8* %36, i8** %38
%39 = getelementptr inbounds i8*, i8** %2, i64 3
%40 = load i8*, i8** %39
%41 = load i8**, i8*** %29
%42 = getelementptr inbounds i8*, i8** %41, i64 3
store i8* %40, i8** %42
%43 = getelementptr inbounds i8*, i8** %2, i64 4
%44 = load i8*, i8** %43
%45 = load i8**, i8*** %29
%46 = getelementptr inbounds i8*, i8** %45, i64 4
store i8* %44, i8** %46
%47 = getelementptr inbounds i8*, i8** %2, i64 5
%48 = load i8*, i8** %47
%49 = load i8**, i8*** %29
%50 = getelementptr inbounds i8*, i8** %49, i64 5
store i8* %48, i8** %50
%51 = load i8*, i8** %3
%52 = getelementptr inbounds i8*, i8** %0, i64 1
%53 = bitcast i8** %52 to i8***
%54 = load i8**, i8*** %53
store i8* %51, i8** %54
%55 = getelementptr inbounds i8*, i8** %3, i64 1
%56 = load i8*, i8** %55
%57 = load i8**, i8*** %53
%58 = getelementptr inbounds i8*, i8** %57, i64 1
store i8* %56, i8** %58
%59 = getelementptr inbounds i8*, i8** %3, i64 2
%60 = load i8*, i8** %59
%61 = load i8**, i8*** %53
%62 = getelementptr inbounds i8*, i8** %61, i64 2
store i8* %60, i8** %62
%63 = getelementptr inbounds i8*, i8** %3, i64 3
%64 = load i8*, i8** %63
%65 = load i8**, i8*** %53
%66 = getelementptr inbounds i8*, i8** %65, i64 3
store i8* %64, i8** %66
%67 = getelementptr inbounds i8*, i8** %3, i64 4
%68 = load i8*, i8** %67
%69 = load i8**, i8*** %53
%70 = getelementptr inbounds i8*, i8** %69, i64 4
store i8* %68, i8** %70
%71 = getelementptr inbounds i8*, i8** %3, i64 5
%72 = load i8*, i8** %71
%73 = load i8**, i8*** %53
%74 = getelementptr inbounds i8*, i8** %73, i64 5
store i8* %72, i8** %74
%75 = load i32, i32* @ETH_P_IP
%76 = tail call i8* @htons(i32 %75)
store i8* %76, i8** %0
%77 = bitcast i8** %7 to i32*
store i32 5, i32* %77
%78 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %8, i64 0, i32 1
store i32 4, i32* %78
%79 = getelementptr inbounds i8*, i8** %0, i64 25
%80 = bitcast i8** %79 to i32*
store i32 16, i32* %80
%81 = tail call i8* @htons(i32 54321)
%82 = getelementptr inbounds i8*, i8** %0, i64 30
store i8* %81, i8** %82
%83 = getelementptr inbounds i8*, i8** %0, i64 29
store i8* inttoptr (i64 60 to i8*), i8** %83
%84 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %8, i64 0, i32 3
store i32 17, i32* %84
%85 = getelementptr inbounds i8*, i8** %0, i64 26
%86 = bitcast i8** %85 to i32*
store i32 %4, i32* %86
%87 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %8, i64 0, i32 5
store i32 %5, i32* %87
%88 = tail call i8* @htons(i32 33423)
%89 = getelementptr inbounds i8*, i8** %0, i64 83
store i8* %88, i8** %89
%90 = tail call i8* @htons(i32 35342)
%91 = getelementptr inbounds i8*, i8** %0, i64 82
store i8* %90, i8** %91
%92 = getelementptr inbounds i8*, i8** %0, i64 81
%93 = bitcast i8** %92 to i64*
store i64 0, i64* %93
%94 = getelementptr inbounds i8*, i8** %0, i64 112
store i8* inttoptr (i64 222 to i8*), i8** %94
%95 = getelementptr inbounds i8*, i8** %0, i64 113
store i8* inttoptr (i64 173 to i8*), i8** %95
%96 = getelementptr inbounds i8*, i8** %0, i64 114
store i8* inttoptr (i64 190 to i8*), i8** %96
%97 = getelementptr inbounds i8*, i8** %0, i64 115
store i8* inttoptr (i64 239 to i8*), i8** %97
%98 = tail call i8* @htons(i32 36)
store i8* %98, i8** %25
%99 = tail call i8* @htons(i32 92)
%100 = getelementptr inbounds i8*, i8** %0, i64 28
store i8* %99, i8** %100
%101 = tail call i32 @csum(i32* %77, i32 56)
%102 = getelementptr inbounds i8*, i8** %0, i64 27
%103 = bitcast i8** %102 to i32*
store i32 %101, i32* %103
ret i32 116
}