#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint16_t;
struct udphdr {
  int /*<<< orphan*/ const len;
  int /*<<< orphan*/ const dest;
  int /*<<< orphan*/ const source;
};
struct TYPE_4__ {
  int /*<<< orphan*/ const s_addr;
};
struct TYPE_3__ {
  int /*<<< orphan*/ const s_addr;
};
struct ip {
  int /*<<< orphan*/ const ip_p;
  TYPE_2__ ip_dst;
  TYPE_1__ ip_src;
};

/* Variables and functions */
int IP_MAXPACKET;
int /*<<< orphan*/ ipHeaderChecksum(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/ const *, int);
uint16_t initUdp4Header(struct ip ipHdr, struct udphdr udpHdr,
                        const uint8_t *data, int dataLen) {
  char buf[IP_MAXPACKET];
  char *ptr;
  int chksumlen = 0;
  int i;
  ptr = &buf[0];
  memcpy(ptr, &ipHdr.ip_src.s_addr, sizeof(ipHdr.ip_src.s_addr));
  ptr += sizeof(ipHdr.ip_src.s_addr);
  chksumlen += sizeof(ipHdr.ip_src.s_addr);
  memcpy(ptr, &ipHdr.ip_dst.s_addr, sizeof(ipHdr.ip_dst.s_addr));
  ptr += sizeof(ipHdr.ip_dst.s_addr);
  chksumlen += sizeof(ipHdr.ip_dst.s_addr);
  *ptr = 0;
  ptr++;
  chksumlen += 1;
  memcpy(ptr, &ipHdr.ip_p, sizeof(ipHdr.ip_p));
  ptr += sizeof(ipHdr.ip_p);
  chksumlen += sizeof(ipHdr.ip_p);
  memcpy(ptr, &udpHdr.len, sizeof(udpHdr.len));
  ptr += sizeof(udpHdr.len);
  chksumlen += sizeof(udpHdr.len);
  memcpy(ptr, &udpHdr.source, sizeof(udpHdr.source));
  ptr += sizeof(udpHdr.source);
  chksumlen += sizeof(udpHdr.source);
  memcpy(ptr, &udpHdr.dest, sizeof(udpHdr.dest));
  ptr += sizeof(udpHdr.dest);
  chksumlen += sizeof(udpHdr.dest);
  memcpy(ptr, &udpHdr.len, sizeof(udpHdr.len));
  ptr += sizeof(udpHdr.len);
  chksumlen += sizeof(udpHdr.len);
  *ptr = 0;
  ptr++;
  *ptr = 0;
  ptr++;
  chksumlen += 2;
  memcpy(ptr, data, dataLen);
  ptr += dataLen;
  chksumlen += dataLen;
  for (i = 0; i < dataLen % 2; i++, ptr++) {
    *ptr = 0;
    ptr++;
    chksumlen++;
  }
  return (ipHeaderChecksum((uint16_t *)buf, chksumlen));
}


x86 assembly (clang, -O0):
<initUdp4Header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x20(%rbp)
mov    %esi,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    %rdx,-0x40(%rbp)
mov    %ecx,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    %r8,-0x48(%rbp)
mov    %r9d,-0x4c(%rbp)
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x58(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x78(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x60(%rbp)
movl   $0x0,-0x6c(%rbp)
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
lea    -0x10(%rbp),%rsi
add    $0x8,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x68(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x68(%rbp)
movslq -0x6c(%rbp),%rax
add    $0x4,%rax
mov    %eax,-0x6c(%rbp)
mov    -0x68(%rbp),%rdi
lea    -0x10(%rbp),%rsi
add    $0x4,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x68(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x68(%rbp)
movslq -0x6c(%rbp),%rax
add    $0x4,%rax
mov    %eax,-0x6c(%rbp)
mov    -0x68(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x68(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x68(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x68(%rbp)
movslq -0x6c(%rbp),%rax
add    $0x4,%rax
mov    %eax,-0x6c(%rbp)
mov    -0x68(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x68(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x68(%rbp)
movslq -0x6c(%rbp),%rax
add    $0x4,%rax
mov    %eax,-0x6c(%rbp)
mov    -0x68(%rbp),%rdi
lea    -0x30(%rbp),%rsi
add    $0x8,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x68(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x68(%rbp)
movslq -0x6c(%rbp),%rax
add    $0x4,%rax
mov    %eax,-0x6c(%rbp)
mov    -0x68(%rbp),%rdi
lea    -0x30(%rbp),%rsi
add    $0x4,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x68(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x68(%rbp)
movslq -0x6c(%rbp),%rax
add    $0x4,%rax
mov    %eax,-0x6c(%rbp)
mov    -0x68(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x68(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x68(%rbp)
movslq -0x6c(%rbp),%rax
add    $0x4,%rax
mov    %eax,-0x6c(%rbp)
mov    -0x68(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
mov    -0x6c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x4c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x4c(%rbp),%ecx
mov    -0x68(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x68(%rbp)
mov    -0x4c(%rbp),%eax
add    -0x6c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
movl   $0x0,-0x70(%rbp)
mov    -0x70(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x4c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x7c(%rbp),%eax
cmp    %edx,%eax
jge    1393 <initUdp4Header+0x273>
mov    -0x68(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
jmp    1341 <initUdp4Header+0x221>
mov    -0x78(%rbp),%rdi
mov    -0x6c(%rbp),%esi
call   1030 <ipHeaderChecksum@plt>
mov    -0x58(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initUdp4Header>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r14d
mov    %r8,-0x50(%rbp)
mov    %rdi,-0x48(%rbp)
lea    -0x40(%rbp),%rax
mov    %esi,-0x40(%rbp)
mov    %rdx,-0x38(%rbp)
mov    %ecx,-0x30(%rbp)
mov    0x2ea7(%rip),%rcx
mov    (%rcx),%r12d
mov    %rsp,%r15
add    $0xf,%r12
and    $0xfffffffffffffff0,%r12
mov    %r15,%rbx
sub    %r12,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    0x4(%rbx),%rdi
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
movb   $0x0,0x8(%rbx)
lea    0x9(%rbx),%rdi
lea    -0x48(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    0xd(%rbx),%rdi
lea    -0x38(%rbp),%r13
mov    %r13,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    0x11(%rbx),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    0x15(%rbx),%rdi
lea    -0x34(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    0x19(%rbx),%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
neg    %r12
movw   $0x0,0x1d(%r15,%r12,1)
lea    0x1f(%rbx),%r12
mov    %r12,%rdi
mov    -0x50(%rbp),%rsi
mov    %r14d,%edx
call   1040 <memcpy@plt>
mov    %r14d,%eax
and    $0x80000001,%eax
cmp    $0x1,%eax
jne    1223 <initUdp4Header+0x103>
mov    %r14d,%eax
movb   $0x0,(%r12,%rax,1)
add    $0x20,%r14d
jmp    1227 <initUdp4Header+0x107>
add    $0x1f,%r14d
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <ipHeaderChecksum@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ip = type { i32, %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32 }
%struct.TYPE_3__ = type { i32 }
%struct.udphdr = type { i32, i32, i32 }
@IP_MAXPACKET = global i32 0
define i32 @initUdp4Header(i64 %0, i32 %1, i64 %2, i32 %3, i32* %4, i32 %5) {
%7 = alloca %struct.ip
%8 = alloca { i64, i32 }
%9 = alloca %struct.udphdr
%10 = alloca { i64, i32 }
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
%18 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %8, i32 0, i32 0
store i64 %0, i64* %18
%19 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %8, i32 0, i32 1
store i32 %1, i32* %19
%20 = bitcast %struct.ip* %7 to i8*
%21 = bitcast { i64, i32 }* %8 to i8*
%22 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %10, i32 0, i32 0
store i64 %2, i64* %22
%23 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %10, i32 0, i32 1
store i32 %3, i32* %23
%24 = bitcast %struct.udphdr* %9 to i8*
%25 = bitcast { i64, i32 }* %10 to i8*
store i32* %4, i32** %11
store i32 %5, i32* %12
%26 = load i32, i32* @IP_MAXPACKET
%27 = zext i32 %26 to i64
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %13
%29 = alloca i8, i64 %27
store i64 %27, i64* %14
store i32 0, i32* %16
%30 = getelementptr inbounds i8, i8* %29, i64 0
store i8* %30, i8** %15
%31 = load i8*, i8** %15
%32 = getelementptr inbounds %struct.ip, %struct.ip* %7, i32 0, i32 2
%33 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %32, i32 0, i32 0
%34 = call i32 @memcpy(i8* %31, i32* %33, i32 4)
%35 = load i8*, i8** %15
%36 = getelementptr inbounds i8, i8* %35, i64 4
store i8* %36, i8** %15
%37 = load i32, i32* %16
%38 = sext i32 %37 to i64
%39 = add i64 %38, 4
%40 = trunc i64 %39 to i32
store i32 %40, i32* %16
%41 = load i8*, i8** %15
%42 = getelementptr inbounds %struct.ip, %struct.ip* %7, i32 0, i32 1
%43 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %42, i32 0, i32 0
%44 = call i32 @memcpy(i8* %41, i32* %43, i32 4)
%45 = load i8*, i8** %15
%46 = getelementptr inbounds i8, i8* %45, i64 4
store i8* %46, i8** %15
%47 = load i32, i32* %16
%48 = sext i32 %47 to i64
%49 = add i64 %48, 4
%50 = trunc i64 %49 to i32
store i32 %50, i32* %16
%51 = load i8*, i8** %15
store i8 0, i8* %51
%52 = load i8*, i8** %15
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %15
%54 = load i32, i32* %16
%55 = add nsw i32 %54, 1
store i32 %55, i32* %16
%56 = load i8*, i8** %15
%57 = getelementptr inbounds %struct.ip, %struct.ip* %7, i32 0, i32 0
%58 = call i32 @memcpy(i8* %56, i32* %57, i32 4)
%59 = load i8*, i8** %15
%60 = getelementptr inbounds i8, i8* %59, i64 4
store i8* %60, i8** %15
%61 = load i32, i32* %16
%62 = sext i32 %61 to i64
%63 = add i64 %62, 4
%64 = trunc i64 %63 to i32
store i32 %64, i32* %16
%65 = load i8*, i8** %15
%66 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %9, i32 0, i32 0
%67 = call i32 @memcpy(i8* %65, i32* %66, i32 4)
%68 = load i8*, i8** %15
%69 = getelementptr inbounds i8, i8* %68, i64 4
store i8* %69, i8** %15
%70 = load i32, i32* %16
%71 = sext i32 %70 to i64
%72 = add i64 %71, 4
%73 = trunc i64 %72 to i32
store i32 %73, i32* %16
%74 = load i8*, i8** %15
%75 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %9, i32 0, i32 2
%76 = call i32 @memcpy(i8* %74, i32* %75, i32 4)
%77 = load i8*, i8** %15
%78 = getelementptr inbounds i8, i8* %77, i64 4
store i8* %78, i8** %15
%79 = load i32, i32* %16
%80 = sext i32 %79 to i64
%81 = add i64 %80, 4
%82 = trunc i64 %81 to i32
store i32 %82, i32* %16
%83 = load i8*, i8** %15
%84 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %9, i32 0, i32 1
%85 = call i32 @memcpy(i8* %83, i32* %84, i32 4)
%86 = load i8*, i8** %15
%87 = getelementptr inbounds i8, i8* %86, i64 4
store i8* %87, i8** %15
%88 = load i32, i32* %16
%89 = sext i32 %88 to i64
%90 = add i64 %89, 4
%91 = trunc i64 %90 to i32
store i32 %91, i32* %16
%92 = load i8*, i8** %15
%93 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %9, i32 0, i32 0
%94 = call i32 @memcpy(i8* %92, i32* %93, i32 4)
%95 = load i8*, i8** %15
%96 = getelementptr inbounds i8, i8* %95, i64 4
store i8* %96, i8** %15
%97 = load i32, i32* %16
%98 = sext i32 %97 to i64
%99 = add i64 %98, 4
%100 = trunc i64 %99 to i32
store i32 %100, i32* %16
%101 = load i8*, i8** %15
store i8 0, i8* %101
%102 = load i8*, i8** %15
%103 = getelementptr inbounds i8, i8* %102, i32 1
store i8* %103, i8** %15
%104 = load i8*, i8** %15
store i8 0, i8* %104
%105 = load i8*, i8** %15
%106 = getelementptr inbounds i8, i8* %105, i32 1
store i8* %106, i8** %15
%107 = load i32, i32* %16
%108 = add nsw i32 %107, 2
store i32 %108, i32* %16
%109 = load i8*, i8** %15
%110 = load i32*, i32** %11
%111 = load i32, i32* %12
%112 = call i32 @memcpy(i8* %109, i32* %110, i32 %111)
%113 = load i32, i32* %12
%114 = load i8*, i8** %15
%115 = sext i32 %113 to i64
%116 = getelementptr inbounds i8, i8* %114, i64 %115
store i8* %116, i8** %15
%117 = load i32, i32* %12
%118 = load i32, i32* %16
%119 = add nsw i32 %118, %117
store i32 %119, i32* %16
store i32 0, i32* %17
br label %120
120: ; preds = %131, %6
%121 = load i32, i32* %17
%122 = load i32, i32* %12
%123 = srem i32 %122, 2
%124 = icmp slt i32 %121, %123
br i1 %124, label %125, label %136
125: ; preds = %120
%126 = load i8*, i8** %15
store i8 0, i8* %126
%127 = load i8*, i8** %15
%128 = getelementptr inbounds i8, i8* %127, i32 1
store i8* %128, i8** %15
%129 = load i32, i32* %16
%130 = add nsw i32 %129, 1
store i32 %130, i32* %16
br label %131
131: ; preds = %125
%132 = load i32, i32* %17
%133 = add nsw i32 %132, 1
store i32 %133, i32* %17
%134 = load i8*, i8** %15
%135 = getelementptr inbounds i8, i8* %134, i32 1
store i8* %135, i8** %15
br label %120
136: ; preds = %120
%137 = bitcast i8* %29 to i32*
%138 = load i32, i32* %16
%139 = call i32 @ipHeaderChecksum(i32* %137, i32 %138)
%140 = load i8*, i8** %13
ret i32 %139
}

LLVM IR (-O2):
%struct.ip = type { i32, %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32 }
%struct.TYPE_3__ = type { i32 }
%struct.udphdr = type { i32, i32, i32 }
@IP_MAXPACKET = global i32 0
define i32 @initUdp4Header(i64 %0, i32 %1, i64 %2, i32 %3, i32* %4, i32 %5) {
%7 = alloca %struct.ip
%8 = alloca %struct.udphdr
%9 = bitcast %struct.ip* %7 to i64*
store i64 %0, i64* %9
%10 = getelementptr inbounds %struct.ip, %struct.ip* %7, i64 0, i32 2, i32 0
store i32 %1, i32* %10
%11 = bitcast %struct.udphdr* %8 to i64*
store i64 %2, i64* %11
%12 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %8, i64 0, i32 2
store i32 %3, i32* %12
%13 = load i32, i32* @IP_MAXPACKET
%14 = zext i32 %13 to i64
%15 = alloca i8, i64 %14
%16 = call i32 @memcpy(i8* %15, i32* %10, i32 4)
%17 = getelementptr inbounds i8, i8* %15, i64 4
%18 = getelementptr inbounds %struct.ip, %struct.ip* %7, i64 0, i32 1, i32 0
%19 = call i32 @memcpy(i8* %17, i32* %18, i32 4)
%20 = getelementptr inbounds i8, i8* %15, i64 8
store i8 0, i8* %20
%21 = getelementptr inbounds i8, i8* %15, i64 9
%22 = getelementptr inbounds %struct.ip, %struct.ip* %7, i64 0, i32 0
%23 = call i32 @memcpy(i8* %21, i32* %22, i32 4)
%24 = getelementptr inbounds i8, i8* %15, i64 13
%25 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %8, i64 0, i32 0
%26 = call i32 @memcpy(i8* %24, i32* %25, i32 4)
%27 = getelementptr inbounds i8, i8* %15, i64 17
%28 = call i32 @memcpy(i8* %27, i32* %12, i32 4)
%29 = getelementptr inbounds i8, i8* %15, i64 21
%30 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %8, i64 0, i32 1
%31 = call i32 @memcpy(i8* %29, i32* %30, i32 4)
%32 = getelementptr inbounds i8, i8* %15, i64 25
%33 = call i32 @memcpy(i8* %32, i32* %25, i32 4)
%34 = getelementptr inbounds i8, i8* %15, i64 29
store i8 0, i8* %34
%35 = getelementptr inbounds i8, i8* %15, i64 30
store i8 0, i8* %35
%36 = getelementptr inbounds i8, i8* %15, i64 31
%37 = call i32 @memcpy(i8* %36, i32* %4, i32 %5)
%38 = add nsw i32 %5, 31
%39 = and i32 %5, -2147483647
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %45
41: ; preds = %6
%42 = zext i32 %5 to i64
%43 = getelementptr inbounds i8, i8* %36, i64 %42
store i8 0, i8* %43
%44 = add nuw i32 %5, 32
br label %45
45: ; preds = %41, %6
%46 = phi i32 [ %38, %6 ], [ %44, %41 ]
%47 = bitcast i8* %15 to i32*
%48 = call i32 @ipHeaderChecksum(i32* %47, i32 %46)
ret i32 %48
}