#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 char uint8_t;
typedef char uint16_t;
typedef int /*<<< orphan*/ tcphdr;
typedef int /*<<< orphan*/ svalue;
struct tcphdr {
  char th_sport;
  char th_dport;
  char th_seq;
  char th_ack;
  int th_off;
  int th_x2;
  char th_flags;
  char th_win;
  char th_urp;
};
struct TYPE_4__ {
  char s_addr;
};
struct TYPE_3__ {
  char s_addr;
};
struct ip {
  char ip_p;
  TYPE_2__ ip_dst;
  TYPE_1__ ip_src;
};
typedef int /*<<< orphan*/ cvalue;

/* Variables and functions */
int IP_MAXPACKET;
char checksum(char *, int);
char htons(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
uint16_t tcp4_checksum(struct ip iphdr, struct tcphdr tcphdr, uint8_t *payload,
                       int payloadlen) {
  uint16_t svalue;
  char buf[IP_MAXPACKET], cvalue;
  char *ptr;
  int i, chksumlen = 0;
  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);
  svalue = htons(sizeof(tcphdr) + payloadlen);
  memcpy(ptr, &svalue, sizeof(svalue));
  ptr += sizeof(svalue);
  chksumlen += sizeof(svalue);
  memcpy(ptr, &tcphdr.th_sport, sizeof(tcphdr.th_sport));
  ptr += sizeof(tcphdr.th_sport);
  chksumlen += sizeof(tcphdr.th_sport);
  memcpy(ptr, &tcphdr.th_dport, sizeof(tcphdr.th_dport));
  ptr += sizeof(tcphdr.th_dport);
  chksumlen += sizeof(tcphdr.th_dport);
  memcpy(ptr, &tcphdr.th_seq, sizeof(tcphdr.th_seq));
  ptr += sizeof(tcphdr.th_seq);
  chksumlen += sizeof(tcphdr.th_seq);
  memcpy(ptr, &tcphdr.th_ack, sizeof(tcphdr.th_ack));
  ptr += sizeof(tcphdr.th_ack);
  chksumlen += sizeof(tcphdr.th_ack);
  cvalue = (tcphdr.th_off << 4) + tcphdr.th_x2;
  memcpy(ptr, &cvalue, sizeof(cvalue));
  ptr += sizeof(cvalue);
  chksumlen += sizeof(cvalue);
  memcpy(ptr, &tcphdr.th_flags, sizeof(tcphdr.th_flags));
  ptr += sizeof(tcphdr.th_flags);
  chksumlen += sizeof(tcphdr.th_flags);
  memcpy(ptr, &tcphdr.th_win, sizeof(tcphdr.th_win));
  ptr += sizeof(tcphdr.th_win);
  chksumlen += sizeof(tcphdr.th_win);
  *ptr = 0;
  ptr++;
  *ptr = 0;
  ptr++;
  chksumlen += 2;
  memcpy(ptr, &tcphdr.th_urp, sizeof(tcphdr.th_urp));
  ptr += sizeof(tcphdr.th_urp);
  chksumlen += sizeof(tcphdr.th_urp);
  memcpy(ptr, payload, payloadlen);
  ptr += payloadlen;
  chksumlen += payloadlen;
  for (i = 0; i < payloadlen % 2; i++, ptr++) {
    *ptr = 0;
    ptr++;
    chksumlen++;
  }
  return checksum((uint16_t *)buf, chksumlen);
}


x86 assembly (clang, -O0):
<tcp4_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %di,%ax
mov    %ax,-0xc(%rbp)
shr    $0x10,%edi
mov    %dil,%al
mov    %al,-0xa(%rbp)
mov    -0xa(%rbp),%al
mov    %al,-0x6(%rbp)
mov    -0xc(%rbp),%ax
mov    %ax,-0x8(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x38(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x60(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x40(%rbp)
movl   $0x0,-0x58(%rbp)
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x8(%rbp),%rsi
add    $0x2,%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
movslq -0x58(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x8(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
movslq -0x58(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x58(%rbp)
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
movslq -0x58(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x58(%rbp)
movslq -0x2c(%rbp),%rax
add    $0x10,%rax
mov    %eax,%edi
call   1030 <htons@plt>
mov    %al,-0x2d(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x2d(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
movslq -0x58(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
movslq -0x58(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
movslq -0x58(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x20(%rbp),%rsi
add    $0x2,%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
movslq -0x58(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x20(%rbp),%rsi
add    $0x3,%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
movslq -0x58(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x58(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
add    -0x18(%rbp),%eax
mov    %al,-0x41(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
movslq -0x58(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x20(%rbp),%rsi
add    $0xc,%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
movslq -0x58(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x20(%rbp),%rsi
add    $0xd,%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
movslq -0x58(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x58(%rbp)
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x58(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x20(%rbp),%rsi
add    $0xe,%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
movslq -0x58(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
add    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x64(%rbp),%eax
cmp    %edx,%eax
jge    1497 <tcp4_checksum+0x367>
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    1445 <tcp4_checksum+0x315>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%esi
call   1040 <checksum@plt>
mov    -0x38(%rbp),%rcx
mov    %rcx,%rsp
movsbl %al,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcp4_checksum>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8d,%r15d
mov    %rcx,-0x50(%rbp)
mov    %rsp,-0x58(%rbp)
mov    %di,-0x30(%rbp)
shr    $0x10,%edi
mov    %dil,-0x2e(%rbp)
mov    %rsi,-0x40(%rbp)
mov    %rdx,-0x38(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %rbx,-0x48(%rbp)
add    $0xf,%r14
and    $0xfffffffffffffff0,%r14
sub    %r14,%rbx
mov    %rbx,%rsp
lea    -0x2e(%rbp),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1050 <memcpy@plt>
lea    0x1(%rbx),%rdi
lea    -0x2f(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
movb   $0x0,0x2(%rbx)
lea    0x3(%rbx),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
lea    0x4(%rbx),%r13
lea    0x10(%r15),%r12d
mov    %r12d,%edi
call   1030 <htons@plt>
mov    %al,-0x2a(%rbp)
lea    -0x2a(%rbp),%rsi
mov    %r13,%rdi
mov    $0x1,%edx
call   1050 <memcpy@plt>
lea    0x5(%rbx),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
lea    0x6(%rbx),%rdi
lea    -0x3f(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
lea    0x7(%rbx),%rdi
lea    -0x3e(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
lea    0x8(%rbx),%rdi
lea    -0x3d(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
lea    0x9(%rbx),%rdi
mov    -0x3c(%rbp),%eax
shl    $0x4,%eax
add    -0x38(%rbp),%eax
mov    %al,-0x29(%rbp)
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
lea    0xa(%rbx),%rdi
lea    -0x34(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
lea    0xb(%rbx),%rdi
lea    -0x33(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
neg    %r14
mov    -0x48(%rbp),%rax
movw   $0x0,0xc(%rax,%r14,1)
lea    0xe(%rbx),%rdi
lea    -0x32(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
lea    0xf(%rbx),%r13
mov    %r13,%rdi
mov    -0x50(%rbp),%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
mov    %r15d,%eax
and    $0x80000001,%eax
cmp    $0x1,%eax
jne    12b1 <tcp4_checksum+0x181>
mov    %r15d,%eax
movb   $0x0,0x0(%r13,%rax,1)
jmp    12b8 <tcp4_checksum+0x188>
add    $0xf,%r15d
mov    %r15d,%r12d
mov    %rbx,%rdi
mov    %r12d,%esi
call   1040 <checksum@plt>
mov    -0x58(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ip = type { i8, %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i8 }
%struct.TYPE_3__ = type { i8 }
%struct.tcphdr = type { i8, i8, i8, i8, i32, i32, i8, i8, i8 }
@IP_MAXPACKET = global i32 0
define signext i8 @tcp4_checksum(i24 %0, i64 %1, i64 %2, i8* %3, i32 %4) {
%6 = alloca %struct.ip
%7 = alloca i24
%8 = alloca %struct.tcphdr
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i8
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
store i24 %0, i24* %7
%18 = bitcast %struct.ip* %6 to i8*
%19 = bitcast i24* %7 to i8*
%20 = bitcast %struct.tcphdr* %8 to { i64, i64 }*
%21 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %20, i32 0, i32 0
store i64 %1, i64* %21
%22 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %20, i32 0, i32 1
store i64 %2, i64* %22
store i8* %3, i8** %9
store i32 %4, i32* %10
%23 = load i32, i32* @IP_MAXPACKET
%24 = zext i32 %23 to i64
%25 = call i8* @llvm.stacksave()
store i8* %25, i8** %12
%26 = alloca i8, i64 %24
store i64 %24, i64* %13
store i32 0, i32* %17
%27 = getelementptr inbounds i8, i8* %26, i64 0
store i8* %27, i8** %15
%28 = load i8*, i8** %15
%29 = getelementptr inbounds %struct.ip, %struct.ip* %6, i32 0, i32 2
%30 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %29, i32 0, i32 0
%31 = call i32 @memcpy(i8* %28, i8* %30, i32 1)
%32 = load i8*, i8** %15
%33 = getelementptr inbounds i8, i8* %32, i64 1
store i8* %33, i8** %15
%34 = load i32, i32* %17
%35 = sext i32 %34 to i64
%36 = add i64 %35, 1
%37 = trunc i64 %36 to i32
store i32 %37, i32* %17
%38 = load i8*, i8** %15
%39 = getelementptr inbounds %struct.ip, %struct.ip* %6, i32 0, i32 1
%40 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %39, i32 0, i32 0
%41 = call i32 @memcpy(i8* %38, i8* %40, i32 1)
%42 = load i8*, i8** %15
%43 = getelementptr inbounds i8, i8* %42, i64 1
store i8* %43, i8** %15
%44 = load i32, i32* %17
%45 = sext i32 %44 to i64
%46 = add i64 %45, 1
%47 = trunc i64 %46 to i32
store i32 %47, i32* %17
%48 = load i8*, i8** %15
store i8 0, i8* %48
%49 = load i8*, i8** %15
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %15
%51 = load i32, i32* %17
%52 = add nsw i32 %51, 1
store i32 %52, i32* %17
%53 = load i8*, i8** %15
%54 = getelementptr inbounds %struct.ip, %struct.ip* %6, i32 0, i32 0
%55 = call i32 @memcpy(i8* %53, i8* %54, i32 1)
%56 = load i8*, i8** %15
%57 = getelementptr inbounds i8, i8* %56, i64 1
store i8* %57, i8** %15
%58 = load i32, i32* %17
%59 = sext i32 %58 to i64
%60 = add i64 %59, 1
%61 = trunc i64 %60 to i32
store i32 %61, i32* %17
%62 = load i32, i32* %10
%63 = sext i32 %62 to i64
%64 = add i64 16, %63
%65 = trunc i64 %64 to i32
%66 = call signext i8 @htons(i32 %65)
store i8 %66, i8* %11
%67 = load i8*, i8** %15
%68 = call i32 @memcpy(i8* %67, i8* %11, i32 1)
%69 = load i8*, i8** %15
%70 = getelementptr inbounds i8, i8* %69, i64 1
store i8* %70, i8** %15
%71 = load i32, i32* %17
%72 = sext i32 %71 to i64
%73 = add i64 %72, 1
%74 = trunc i64 %73 to i32
store i32 %74, i32* %17
%75 = load i8*, i8** %15
%76 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 0
%77 = call i32 @memcpy(i8* %75, i8* %76, i32 1)
%78 = load i8*, i8** %15
%79 = getelementptr inbounds i8, i8* %78, i64 1
store i8* %79, i8** %15
%80 = load i32, i32* %17
%81 = sext i32 %80 to i64
%82 = add i64 %81, 1
%83 = trunc i64 %82 to i32
store i32 %83, i32* %17
%84 = load i8*, i8** %15
%85 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 1
%86 = call i32 @memcpy(i8* %84, i8* %85, i32 1)
%87 = load i8*, i8** %15
%88 = getelementptr inbounds i8, i8* %87, i64 1
store i8* %88, i8** %15
%89 = load i32, i32* %17
%90 = sext i32 %89 to i64
%91 = add i64 %90, 1
%92 = trunc i64 %91 to i32
store i32 %92, i32* %17
%93 = load i8*, i8** %15
%94 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 2
%95 = call i32 @memcpy(i8* %93, i8* %94, i32 1)
%96 = load i8*, i8** %15
%97 = getelementptr inbounds i8, i8* %96, i64 1
store i8* %97, i8** %15
%98 = load i32, i32* %17
%99 = sext i32 %98 to i64
%100 = add i64 %99, 1
%101 = trunc i64 %100 to i32
store i32 %101, i32* %17
%102 = load i8*, i8** %15
%103 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 3
%104 = call i32 @memcpy(i8* %102, i8* %103, i32 1)
%105 = load i8*, i8** %15
%106 = getelementptr inbounds i8, i8* %105, i64 1
store i8* %106, i8** %15
%107 = load i32, i32* %17
%108 = sext i32 %107 to i64
%109 = add i64 %108, 1
%110 = trunc i64 %109 to i32
store i32 %110, i32* %17
%111 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 4
%112 = load i32, i32* %111
%113 = shl i32 %112, 4
%114 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 5
%115 = load i32, i32* %114
%116 = add nsw i32 %113, %115
%117 = trunc i32 %116 to i8
store i8 %117, i8* %14
%118 = load i8*, i8** %15
%119 = call i32 @memcpy(i8* %118, i8* %14, i32 1)
%120 = load i8*, i8** %15
%121 = getelementptr inbounds i8, i8* %120, i64 1
store i8* %121, i8** %15
%122 = load i32, i32* %17
%123 = sext i32 %122 to i64
%124 = add i64 %123, 1
%125 = trunc i64 %124 to i32
store i32 %125, i32* %17
%126 = load i8*, i8** %15
%127 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 6
%128 = call i32 @memcpy(i8* %126, i8* %127, i32 1)
%129 = load i8*, i8** %15
%130 = getelementptr inbounds i8, i8* %129, i64 1
store i8* %130, i8** %15
%131 = load i32, i32* %17
%132 = sext i32 %131 to i64
%133 = add i64 %132, 1
%134 = trunc i64 %133 to i32
store i32 %134, i32* %17
%135 = load i8*, i8** %15
%136 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 7
%137 = call i32 @memcpy(i8* %135, i8* %136, i32 1)
%138 = load i8*, i8** %15
%139 = getelementptr inbounds i8, i8* %138, i64 1
store i8* %139, i8** %15
%140 = load i32, i32* %17
%141 = sext i32 %140 to i64
%142 = add i64 %141, 1
%143 = trunc i64 %142 to i32
store i32 %143, i32* %17
%144 = load i8*, i8** %15
store i8 0, i8* %144
%145 = load i8*, i8** %15
%146 = getelementptr inbounds i8, i8* %145, i32 1
store i8* %146, i8** %15
%147 = load i8*, i8** %15
store i8 0, i8* %147
%148 = load i8*, i8** %15
%149 = getelementptr inbounds i8, i8* %148, i32 1
store i8* %149, i8** %15
%150 = load i32, i32* %17
%151 = add nsw i32 %150, 2
store i32 %151, i32* %17
%152 = load i8*, i8** %15
%153 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 8
%154 = call i32 @memcpy(i8* %152, i8* %153, i32 1)
%155 = load i8*, i8** %15
%156 = getelementptr inbounds i8, i8* %155, i64 1
store i8* %156, i8** %15
%157 = load i32, i32* %17
%158 = sext i32 %157 to i64
%159 = add i64 %158, 1
%160 = trunc i64 %159 to i32
store i32 %160, i32* %17
%161 = load i8*, i8** %15
%162 = load i8*, i8** %9
%163 = load i32, i32* %10
%164 = call i32 @memcpy(i8* %161, i8* %162, i32 %163)
%165 = load i32, i32* %10
%166 = load i8*, i8** %15
%167 = sext i32 %165 to i64
%168 = getelementptr inbounds i8, i8* %166, i64 %167
store i8* %168, i8** %15
%169 = load i32, i32* %10
%170 = load i32, i32* %17
%171 = add nsw i32 %170, %169
store i32 %171, i32* %17
store i32 0, i32* %16
br label %172
172: ; preds = %183, %5
%173 = load i32, i32* %16
%174 = load i32, i32* %10
%175 = srem i32 %174, 2
%176 = icmp slt i32 %173, %175
br i1 %176, label %177, label %188
177: ; preds = %172
%178 = load i8*, i8** %15
store i8 0, i8* %178
%179 = load i8*, i8** %15
%180 = getelementptr inbounds i8, i8* %179, i32 1
store i8* %180, i8** %15
%181 = load i32, i32* %17
%182 = add nsw i32 %181, 1
store i32 %182, i32* %17
br label %183
183: ; preds = %177
%184 = load i32, i32* %16
%185 = add nsw i32 %184, 1
store i32 %185, i32* %16
%186 = load i8*, i8** %15
%187 = getelementptr inbounds i8, i8* %186, i32 1
store i8* %187, i8** %15
br label %172
188: ; preds = %172
%189 = load i32, i32* %17
%190 = call signext i8 @checksum(i8* %26, i32 %189)
%191 = load i8*, i8** %12
ret i8 %190
}

LLVM IR (-O2):
%struct.ip = type { i8, %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i8 }
%struct.TYPE_3__ = type { i8 }
%struct.tcphdr = type { i8, i8, i8, i8, i32, i32, i8, i8, i8 }
@IP_MAXPACKET = global i32 0
define signext i8 @tcp4_checksum(i24 %0, i64 %1, i64 %2, i8* %3, i32 %4) {
%6 = alloca %struct.ip
%7 = alloca { i64, i64 }
%8 = bitcast { i64, i64 }* %7 to %struct.tcphdr*
%9 = alloca i8
%10 = alloca i8
%11 = bitcast %struct.ip* %6 to i24*
store i24 %0, i24* %11
%12 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %7, i64 0, i32 0
store i64 %1, i64* %12
%13 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %7, i64 0, i32 1
store i64 %2, i64* %13
%14 = load i32, i32* @IP_MAXPACKET
%15 = zext i32 %14 to i64
%16 = tail call i8* @llvm.stacksave()
%17 = alloca i8, i64 %15
%18 = getelementptr inbounds %struct.ip, %struct.ip* %6, i64 0, i32 2, i32 0
%19 = call i32 @memcpy(i8* %17, i8* %18, i32 1)
%20 = getelementptr inbounds i8, i8* %17, i64 1
%21 = getelementptr inbounds %struct.ip, %struct.ip* %6, i64 0, i32 1, i32 0
%22 = call i32 @memcpy(i8* %20, i8* %21, i32 1)
%23 = getelementptr inbounds i8, i8* %17, i64 2
store i8 0, i8* %23
%24 = getelementptr inbounds i8, i8* %17, i64 3
%25 = getelementptr inbounds %struct.ip, %struct.ip* %6, i64 0, i32 0
%26 = call i32 @memcpy(i8* %24, i8* %25, i32 1)
%27 = getelementptr inbounds i8, i8* %17, i64 4
%28 = add i32 %4, 16
%29 = call signext i8 @htons(i32 %28)
store i8 %29, i8* %9
%30 = call i32 @memcpy(i8* %27, i8* %9, i32 1)
%31 = getelementptr inbounds i8, i8* %17, i64 5
%32 = bitcast { i64, i64 }* %7 to i8*
%33 = call i32 @memcpy(i8* %31, i8* %32, i32 1)
%34 = getelementptr inbounds i8, i8* %17, i64 6
%35 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i64 0, i32 1
%36 = call i32 @memcpy(i8* %34, i8* %35, i32 1)
%37 = getelementptr inbounds i8, i8* %17, i64 7
%38 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i64 0, i32 2
%39 = call i32 @memcpy(i8* %37, i8* %38, i32 1)
%40 = getelementptr inbounds i8, i8* %17, i64 8
%41 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i64 0, i32 3
%42 = call i32 @memcpy(i8* %40, i8* %41, i32 1)
%43 = getelementptr inbounds i8, i8* %17, i64 9
%44 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i64 0, i32 4
%45 = load i32, i32* %44
%46 = shl i32 %45, 4
%47 = bitcast i64* %13 to i32*
%48 = load i32, i32* %47
%49 = add nsw i32 %46, %48
%50 = trunc i32 %49 to i8
store i8 %50, i8* %10
%51 = call i32 @memcpy(i8* %43, i8* %10, i32 1)
%52 = getelementptr inbounds i8, i8* %17, i64 10
%53 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i64 0, i32 6
%54 = call i32 @memcpy(i8* %52, i8* %53, i32 1)
%55 = getelementptr inbounds i8, i8* %17, i64 11
%56 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i64 0, i32 7
%57 = call i32 @memcpy(i8* %55, i8* %56, i32 1)
%58 = getelementptr inbounds i8, i8* %17, i64 12
store i8 0, i8* %58
%59 = getelementptr inbounds i8, i8* %17, i64 13
store i8 0, i8* %59
%60 = getelementptr inbounds i8, i8* %17, i64 14
%61 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i64 0, i32 8
%62 = call i32 @memcpy(i8* %60, i8* %61, i32 1)
%63 = getelementptr inbounds i8, i8* %17, i64 15
%64 = call i32 @memcpy(i8* %63, i8* %3, i32 %4)
%65 = add nsw i32 %4, 15
%66 = and i32 %4, -2147483647
%67 = icmp eq i32 %66, 1
br i1 %67, label %68, label %71
68: ; preds = %5
%69 = zext i32 %4 to i64
%70 = getelementptr inbounds i8, i8* %63, i64 %69
store i8 0, i8* %70
br label %71
71: ; preds = %68, %5
%72 = phi i32 [ %65, %5 ], [ %28, %68 ]
%73 = call signext i8 @checksum(i8* %17, i32 %72)
ret i8 %73
}