#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 *options,
                       int opt_len) {
  uint16_t svalue;
  char buf[IP_MAXPACKET], cvalue;
  char *ptr;
  int 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) + opt_len);
  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, options, opt_len);
  ptr += opt_len;
  chksumlen += opt_len;
  return checksum((uint16_t *)buf, chksumlen);
}


x86 assembly (clang, -O0):
<tcp4_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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,-0x54(%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 -0x54(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x54(%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 -0x54(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%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 -0x54(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x54(%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 -0x54(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x54(%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 -0x54(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x54(%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 -0x54(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x54(%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 -0x54(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x54(%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 -0x54(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x54(%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 -0x54(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x54(%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 -0x54(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x54(%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 -0x54(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x54(%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    -0x54(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x54(%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 -0x54(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x60(%rbp),%rdi
mov    -0x2c(%rbp),%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
add    -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%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    $0x28,%rsp
mov    %r8d,%r15d
mov    %rcx,-0x50(%rbp)
mov    %rsp,-0x48(%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,%r13
add    $0xf,%r14
and    $0xfffffffffffffff0,%r14
mov    %r13,%rbx
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),%r12
lea    0x10(%r15),%edi
call   1030 <htons@plt>
mov    %al,-0x2a(%rbp)
lea    -0x2a(%rbp),%rsi
mov    %r12,%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
movw   $0x0,0xc(%r13,%r14,1)
lea    0xe(%rbx),%rdi
lea    -0x32(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
lea    0xf(%rbx),%rdi
mov    -0x50(%rbp),%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
add    $0xf,%r15d
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <checksum@plt>
mov    -0x48(%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
store i24 %0, i24* %7
%17 = bitcast %struct.ip* %6 to i8*
%18 = bitcast i24* %7 to i8*
%19 = bitcast %struct.tcphdr* %8 to { i64, i64 }*
%20 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %19, i32 0, i32 0
store i64 %1, i64* %20
%21 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %19, i32 0, i32 1
store i64 %2, i64* %21
store i8* %3, i8** %9
store i32 %4, i32* %10
%22 = load i32, i32* @IP_MAXPACKET
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %12
%25 = alloca i8, i64 %23
store i64 %23, i64* %13
store i32 0, i32* %16
%26 = getelementptr inbounds i8, i8* %25, i64 0
store i8* %26, i8** %15
%27 = load i8*, i8** %15
%28 = getelementptr inbounds %struct.ip, %struct.ip* %6, i32 0, i32 2
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %28, i32 0, i32 0
%30 = call i32 @memcpy(i8* %27, i8* %29, i32 1)
%31 = load i8*, i8** %15
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8* %32, i8** %15
%33 = load i32, i32* %16
%34 = sext i32 %33 to i64
%35 = add i64 %34, 1
%36 = trunc i64 %35 to i32
store i32 %36, i32* %16
%37 = load i8*, i8** %15
%38 = getelementptr inbounds %struct.ip, %struct.ip* %6, i32 0, i32 1
%39 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %38, i32 0, i32 0
%40 = call i32 @memcpy(i8* %37, i8* %39, i32 1)
%41 = load i8*, i8** %15
%42 = getelementptr inbounds i8, i8* %41, i64 1
store i8* %42, i8** %15
%43 = load i32, i32* %16
%44 = sext i32 %43 to i64
%45 = add i64 %44, 1
%46 = trunc i64 %45 to i32
store i32 %46, i32* %16
%47 = load i8*, i8** %15
store i8 0, i8* %47
%48 = load i8*, i8** %15
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %15
%50 = load i32, i32* %16
%51 = add nsw i32 %50, 1
store i32 %51, i32* %16
%52 = load i8*, i8** %15
%53 = getelementptr inbounds %struct.ip, %struct.ip* %6, i32 0, i32 0
%54 = call i32 @memcpy(i8* %52, i8* %53, i32 1)
%55 = load i8*, i8** %15
%56 = getelementptr inbounds i8, i8* %55, i64 1
store i8* %56, i8** %15
%57 = load i32, i32* %16
%58 = sext i32 %57 to i64
%59 = add i64 %58, 1
%60 = trunc i64 %59 to i32
store i32 %60, i32* %16
%61 = load i32, i32* %10
%62 = sext i32 %61 to i64
%63 = add i64 16, %62
%64 = trunc i64 %63 to i32
%65 = call signext i8 @htons(i32 %64)
store i8 %65, i8* %11
%66 = load i8*, i8** %15
%67 = call i32 @memcpy(i8* %66, i8* %11, i32 1)
%68 = load i8*, i8** %15
%69 = getelementptr inbounds i8, i8* %68, i64 1
store i8* %69, i8** %15
%70 = load i32, i32* %16
%71 = sext i32 %70 to i64
%72 = add i64 %71, 1
%73 = trunc i64 %72 to i32
store i32 %73, i32* %16
%74 = load i8*, i8** %15
%75 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 0
%76 = call i32 @memcpy(i8* %74, i8* %75, i32 1)
%77 = load i8*, i8** %15
%78 = getelementptr inbounds i8, i8* %77, i64 1
store i8* %78, i8** %15
%79 = load i32, i32* %16
%80 = sext i32 %79 to i64
%81 = add i64 %80, 1
%82 = trunc i64 %81 to i32
store i32 %82, i32* %16
%83 = load i8*, i8** %15
%84 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 1
%85 = call i32 @memcpy(i8* %83, i8* %84, i32 1)
%86 = load i8*, i8** %15
%87 = getelementptr inbounds i8, i8* %86, i64 1
store i8* %87, i8** %15
%88 = load i32, i32* %16
%89 = sext i32 %88 to i64
%90 = add i64 %89, 1
%91 = trunc i64 %90 to i32
store i32 %91, i32* %16
%92 = load i8*, i8** %15
%93 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 2
%94 = call i32 @memcpy(i8* %92, i8* %93, i32 1)
%95 = load i8*, i8** %15
%96 = getelementptr inbounds i8, i8* %95, i64 1
store i8* %96, i8** %15
%97 = load i32, i32* %16
%98 = sext i32 %97 to i64
%99 = add i64 %98, 1
%100 = trunc i64 %99 to i32
store i32 %100, i32* %16
%101 = load i8*, i8** %15
%102 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 3
%103 = call i32 @memcpy(i8* %101, i8* %102, i32 1)
%104 = load i8*, i8** %15
%105 = getelementptr inbounds i8, i8* %104, i64 1
store i8* %105, i8** %15
%106 = load i32, i32* %16
%107 = sext i32 %106 to i64
%108 = add i64 %107, 1
%109 = trunc i64 %108 to i32
store i32 %109, i32* %16
%110 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 4
%111 = load i32, i32* %110
%112 = shl i32 %111, 4
%113 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 5
%114 = load i32, i32* %113
%115 = add nsw i32 %112, %114
%116 = trunc i32 %115 to i8
store i8 %116, i8* %14
%117 = load i8*, i8** %15
%118 = call i32 @memcpy(i8* %117, i8* %14, i32 1)
%119 = load i8*, i8** %15
%120 = getelementptr inbounds i8, i8* %119, i64 1
store i8* %120, i8** %15
%121 = load i32, i32* %16
%122 = sext i32 %121 to i64
%123 = add i64 %122, 1
%124 = trunc i64 %123 to i32
store i32 %124, i32* %16
%125 = load i8*, i8** %15
%126 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 6
%127 = call i32 @memcpy(i8* %125, i8* %126, i32 1)
%128 = load i8*, i8** %15
%129 = getelementptr inbounds i8, i8* %128, i64 1
store i8* %129, i8** %15
%130 = load i32, i32* %16
%131 = sext i32 %130 to i64
%132 = add i64 %131, 1
%133 = trunc i64 %132 to i32
store i32 %133, i32* %16
%134 = load i8*, i8** %15
%135 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 7
%136 = call i32 @memcpy(i8* %134, i8* %135, i32 1)
%137 = load i8*, i8** %15
%138 = getelementptr inbounds i8, i8* %137, i64 1
store i8* %138, i8** %15
%139 = load i32, i32* %16
%140 = sext i32 %139 to i64
%141 = add i64 %140, 1
%142 = trunc i64 %141 to i32
store i32 %142, i32* %16
%143 = load i8*, i8** %15
store i8 0, i8* %143
%144 = load i8*, i8** %15
%145 = getelementptr inbounds i8, i8* %144, i32 1
store i8* %145, i8** %15
%146 = load i8*, i8** %15
store i8 0, i8* %146
%147 = load i8*, i8** %15
%148 = getelementptr inbounds i8, i8* %147, i32 1
store i8* %148, i8** %15
%149 = load i32, i32* %16
%150 = add nsw i32 %149, 2
store i32 %150, i32* %16
%151 = load i8*, i8** %15
%152 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 8
%153 = call i32 @memcpy(i8* %151, i8* %152, i32 1)
%154 = load i8*, i8** %15
%155 = getelementptr inbounds i8, i8* %154, i64 1
store i8* %155, i8** %15
%156 = load i32, i32* %16
%157 = sext i32 %156 to i64
%158 = add i64 %157, 1
%159 = trunc i64 %158 to i32
store i32 %159, i32* %16
%160 = load i8*, i8** %15
%161 = load i8*, i8** %9
%162 = load i32, i32* %10
%163 = call i32 @memcpy(i8* %160, i8* %161, i32 %162)
%164 = load i32, i32* %10
%165 = load i8*, i8** %15
%166 = sext i32 %164 to i64
%167 = getelementptr inbounds i8, i8* %165, i64 %166
store i8* %167, i8** %15
%168 = load i32, i32* %10
%169 = load i32, i32* %16
%170 = add nsw i32 %169, %168
store i32 %170, i32* %16
%171 = load i32, i32* %16
%172 = call signext i8 @checksum(i8* %25, i32 %171)
%173 = load i8*, i8** %12
ret i8 %172
}

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 = call signext i8 @checksum(i8* %17, i32 %65)
ret i8 %66
}