#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 */
unsigned int ntohl(unsigned int);
unsigned int haproxy_server_hash(const char *addr, int len) {
  unsigned int h, l;
  l = h = 0;
  while ((l + sizeof(int)) <= len) {
    h ^= ntohl(*(unsigned int *)(&addr[l]));
    l += sizeof(int);
  }
  return h %= 4;
}


x86 assembly (clang, -O0):
<haproxy_server_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x4,%rax
movslq -0xc(%rbp),%rcx
cmp    %rcx,%rax
ja     1165 <haproxy_server_hash+0x55>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,1),%edi
call   1030 <ntohl@plt>
xor    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x4,%rax
mov    %eax,-0x14(%rbp)
jmp    112d <haproxy_server_hash+0x1d>
mov    -0x10(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0x10(%rbp)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<haproxy_server_hash>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
cmp    $0x4,%esi
jb     1149 <haproxy_server_hash+0x39>
mov    %rdi,%r14
movslq %esi,%r15
xor    %eax,%eax
mov    $0x4,%ebx
xor    %ebp,%ebp
nopl   (%rax)
mov    (%r14,%rax,1),%edi
call   1030 <ntohl@plt>
xor    %eax,%ebp
mov    %ebx,%eax
lea    0x4(%rax),%rbx
cmp    %r15,%rbx
jbe    1130 <haproxy_server_hash+0x20>
and    $0x3,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @haproxy_server_hash(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %14, %2
%8 = load i32, i32* %6
%9 = zext i32 %8 to i64
%10 = add i64 %9, 4
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = icmp ule i64 %10, %12
br i1 %13, label %14, label %28
14: ; preds = %7
%15 = load i8*, i8** %3
%16 = load i32, i32* %6
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = bitcast i8* %18 to i32*
%20 = load i32, i32* %19
%21 = call i32 @ntohl(i32 %20)
%22 = load i32, i32* %5
%23 = xor i32 %22, %21
store i32 %23, i32* %5
%24 = load i32, i32* %6
%25 = zext i32 %24 to i64
%26 = add i64 %25, 4
%27 = trunc i64 %26 to i32
store i32 %27, i32* %6
br label %7
28: ; preds = %7
%29 = load i32, i32* %5
%30 = urem i32 %29, 4
store i32 %30, i32* %5
ret i32 %30
}

LLVM IR (-O2):
define i32 @haproxy_server_hash(i8* nocapture %0, i32 %1) {
%3 = sext i32 %1 to i64
%4 = icmp ult i32 %1, 4
br i1 %4, label %19, label %5
5: ; preds = %2, %5
%6 = phi i64 [ %15, %5 ], [ 4, %2 ]
%7 = phi i64 [ %14, %5 ], [ 0, %2 ]
%8 = phi i32 [ %13, %5 ], [ 0, %2 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = bitcast i8* %9 to i32*
%11 = load i32, i32* %10
%12 = tail call i32 @ntohl(i32 %11)
%13 = xor i32 %12, %8
%14 = and i64 %6, 4294967295
%15 = add nuw nsw i64 %14, 4
%16 = icmp ugt i64 %15, %3
br i1 %16, label %17, label %5
17: ; preds = %5
%18 = and i32 %13, 3
br label %19
19: ; preds = %17, %2
%20 = phi i32 [ 0, %2 ], [ %18, %17 ]
ret i32 %20
}