#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 iphdr {
  scalar_t__ check;
  int /*<<< orphan*/ tos;
};
typedef int /*<<< orphan*/ __u8;
typedef int __u64;

/* Variables and functions */
int /*<<< orphan*/ checksum(struct iphdr *, int, int /*<<< orphan*/);
scalar_t__ wrapsum(int /*<<< orphan*/);
void set_tos(void *pkt, void *end, __u64 offset, __u8 tos) {
  struct iphdr *ip = pkt + offset;
  ip->tos = tos;
  ip->check = 0;
  ip->check = wrapsum(checksum(ip, sizeof(*ip), 0));
}


x86 assembly (clang, -O0):
<set_tos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    $0x10,%esi
xor    %edx,%edx
call   1030 <checksum@plt>
mov    %eax,%edi
call   1040 <wrapsum@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_tos>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movslq %edx,%rbx
add    %rbx,%rdi
mov    %ecx,0x8(%r14,%rbx,1)
movq   $0x0,(%r14,%rbx,1)
mov    $0x10,%esi
xor    %edx,%edx
call   1030 <checksum@plt>
mov    %eax,%edi
call   1040 <wrapsum@plt>
mov    %rax,(%r14,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.iphdr = type { i64, i32 }
define void @set_tos(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.iphdr*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i8*, i8** %5
%11 = load i32, i32* %7
%12 = sext i32 %11 to i64
%13 = getelementptr i8, i8* %10, i64 %12
%14 = bitcast i8* %13 to %struct.iphdr*
store %struct.iphdr* %14, %struct.iphdr** %9
%15 = load i32, i32* %8
%16 = load %struct.iphdr*, %struct.iphdr** %9
%17 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %16, i32 0, i32 1
store i32 %15, i32* %17
%18 = load %struct.iphdr*, %struct.iphdr** %9
%19 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %18, i32 0, i32 0
store i64 0, i64* %19
%20 = load %struct.iphdr*, %struct.iphdr** %9
%21 = call i32 @checksum(%struct.iphdr* %20, i32 16, i32 0)
%22 = call i64 @wrapsum(i32 %21)
%23 = load %struct.iphdr*, %struct.iphdr** %9
%24 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %23, i32 0, i32 0
store i64 %22, i64* %24
ret void
}

LLVM IR (-O2):
%struct.iphdr = type { i64, i32 }
define void @set_tos(i8* %0, i8* nocapture readnone %1, i32 %2, i32 %3) {
%5 = sext i32 %2 to i64
%6 = getelementptr i8, i8* %0, i64 %5
%7 = bitcast i8* %6 to %struct.iphdr*
%8 = getelementptr inbounds i8, i8* %6, i64 8
%9 = bitcast i8* %8 to i32*
store i32 %3, i32* %9
%10 = bitcast i8* %6 to i64*
store i64 0, i64* %10
%11 = tail call i32 @checksum(%struct.iphdr* %7, i32 16, i32 0)
%12 = tail call i64 @wrapsum(i32 %11)
store i64 %12, i64* %10
ret void
}