#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 int u_int32_t;
struct iphdr {
  int /*<<< orphan*/ check;
  int /*<<< orphan*/ ttl;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int ntohs(int /*<<< orphan*/);
void DecreaseTtlAndUpdateHeaderChecksum(unsigned char *ipPacket) {
  struct iphdr *iph;
  u_int32_t sum;
  assert(ipPacket != NULL);
  iph = (struct iphdr *)ipPacket;
  iph->ttl--;
  sum = ntohs(iph->check) + 0x100;
  iph->check = htons(sum + (sum >> 16));
}


x86 assembly (clang, -O0):
<DecreaseTtlAndUpdateHeaderChecksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <ntohs@plt>
add    $0x100,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%eax
sar    $0x10,%eax
add    %eax,%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DecreaseTtlAndUpdateHeaderChecksum>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
addl   $0xffffffff,0x4(%rbx)
mov    (%rbx),%edi
call   1050 <ntohs@plt>
lea    0x100(%rax),%ecx
sar    $0x10,%ecx
lea    (%rcx,%rax,1),%edi
add    $0x100,%edi
call   1030 <htons@plt>
mov    %eax,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
%struct.iphdr = type { i32, i32 }
define void @DecreaseTtlAndUpdateHeaderChecksum(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.iphdr*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i8*, i8** %2
%10 = bitcast i8* %9 to %struct.iphdr*
store %struct.iphdr* %10, %struct.iphdr** %3
%11 = load %struct.iphdr*, %struct.iphdr** %3
%12 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %11, i32 0, i32 1
%13 = load i32, i32* %12
%14 = add nsw i32 %13, -1
store i32 %14, i32* %12
%15 = load %struct.iphdr*, %struct.iphdr** %3
%16 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @ntohs(i32 %17)
%19 = add nsw i32 %18, 256
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = load i32, i32* %4
%22 = ashr i32 %21, 16
%23 = add nsw i32 %20, %22
%24 = call i32 @htons(i32 %23)
%25 = load %struct.iphdr*, %struct.iphdr** %3
%26 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %25, i32 0, i32 0
store i32 %24, i32* %26
ret void
}

LLVM IR (-O2):
define void @DecreaseTtlAndUpdateHeaderChecksum(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = getelementptr inbounds i8, i8* %0, i64 4
%6 = bitcast i8* %5 to i32*
%7 = load i32, i32* %6
%8 = add nsw i32 %7, -1
store i32 %8, i32* %6
%9 = bitcast i8* %0 to i32*
%10 = load i32, i32* %9
%11 = tail call i32 @ntohs(i32 %10)
%12 = add nsw i32 %11, 256
%13 = ashr i32 %12, 16
%14 = add nsw i32 %13, %12
%15 = tail call i32 @htons(i32 %14)
store i32 %15, i32* %9
ret void
}