#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 */

/* Variables and functions */
scalar_t__ ntohs(unsigned short);
unsigned int csum_tcpudp_nofold(unsigned long saddr, unsigned long daddr,
                                unsigned short len, unsigned short proto,
                                unsigned int sum) {
  unsigned long result;
  result = (saddr + daddr + sum + ((unsigned long)ntohs(len) << 16) +
            ((unsigned long)proto << 8));
  result = (result & 0xffffffff) + (result >> 32);
  result = (result & 0xffffffff) + (result >> 32);
  return result;
}


x86 assembly (clang, -O0):
<csum_tcpudp_nofold>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cx,%ax
mov    %dx,%cx
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %cx,-0x12(%rbp)
mov    %ax,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
movzwl -0x12(%rbp),%edi
call   1030 <ntohs@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
shl    $0x10,%rcx
add    %rcx,%rax
movzwl -0x14(%rbp),%ecx
shl    $0x8,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movabs $0xffffffff,%rax
and    -0x20(%rbp),%rax
mov    -0x20(%rbp),%rcx
shr    $0x20,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movabs $0xffffffff,%rax
and    -0x20(%rbp),%rax
mov    -0x20(%rbp),%rcx
shr    $0x20,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<csum_tcpudp_nofold>:
push   %rbp
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %r8d,%ebx
add    %rdi,%rbx
add    %rsi,%rbx
mov    %edx,%edi
call   1030 <ntohs@plt>
shl    $0x10,%rax
mov    %ebp,%ecx
shl    $0x8,%rcx
add    %rbx,%rcx
add    %rcx,%rax
mov    %eax,%ecx
shr    $0x20,%rax
add    %rcx,%rax
mov    %rax,%rcx
shr    $0x20,%rcx
add    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @csum_tcpudp_nofold(i64 %0, i64 %1, i16 zeroext %2, i16 zeroext %3, i32 %4) {
%6 = alloca i64
%7 = alloca i64
%8 = alloca i16
%9 = alloca i16
%10 = alloca i32
%11 = alloca i64
store i64 %0, i64* %6
store i64 %1, i64* %7
store i16 %2, i16* %8
store i16 %3, i16* %9
store i32 %4, i32* %10
%12 = load i64, i64* %6
%13 = load i64, i64* %7
%14 = add i64 %12, %13
%15 = load i32, i32* %10
%16 = zext i32 %15 to i64
%17 = add i64 %14, %16
%18 = load i16, i16* %8
%19 = call i64 @ntohs(i16 zeroext %18)
%20 = shl i64 %19, 16
%21 = add i64 %17, %20
%22 = load i16, i16* %9
%23 = zext i16 %22 to i64
%24 = shl i64 %23, 8
%25 = add i64 %21, %24
store i64 %25, i64* %11
%26 = load i64, i64* %11
%27 = and i64 %26, 4294967295
%28 = load i64, i64* %11
%29 = lshr i64 %28, 32
%30 = add i64 %27, %29
store i64 %30, i64* %11
%31 = load i64, i64* %11
%32 = and i64 %31, 4294967295
%33 = load i64, i64* %11
%34 = lshr i64 %33, 32
%35 = add i64 %32, %34
store i64 %35, i64* %11
%36 = load i64, i64* %11
%37 = trunc i64 %36 to i32
ret i32 %37
}

LLVM IR (-O2):
define i32 @csum_tcpudp_nofold(i64 %0, i64 %1, i16 zeroext %2, i16 zeroext %3, i32 %4) {
%6 = add i64 %1, %0
%7 = zext i32 %4 to i64
%8 = add i64 %6, %7
%9 = tail call i64 @ntohs(i16 zeroext %2)
%10 = shl i64 %9, 16
%11 = zext i16 %3 to i64
%12 = shl nuw nsw i64 %11, 8
%13 = add i64 %8, %12
%14 = add i64 %13, %10
%15 = and i64 %14, 4294967295
%16 = lshr i64 %14, 32
%17 = add nuw nsw i64 %15, %16
%18 = lshr i64 %17, 32
%19 = add nuw nsw i64 %18, %17
%20 = trunc i64 %19 to i32
ret i32 %20
}