#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 uint32_t;

/* Variables and functions */
int htonl(int);
int /*<<< orphan*/ printf(char *, ...);
int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  uint32_t val;
  uint32_t mask;
  uint32_t hash;
  if (argc < 3) {
    printf("Use %s val mask\n", argv[0]);
    return (-1);
  }
  val = strtoul(argv[1], NULL, 0);
  mask = strtoul(argv[2], NULL, 0);
  hash = val & mask;
  printf("val:%x mask:%x = Hash is 0x%x/%d\n", val, mask, hash, hash);
  hash = htonl(val) & mask;
  printf("htonl(val):%x mask:%x = Hash is 0x%x/%d\n", htonl(val), mask, hash,
         hash);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1171 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f8 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <htonl@plt>
and    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <htonl@plt>
mov    %eax,%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     1155 <main+0x25>
mov    (%rbx),%rsi
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%r14d
jmp    11af <main+0x7f>
mov    0x8(%rbx),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %eax,%ebx
mov    %eax,%ecx
and    %ebp,%ecx
lea    0xe90(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
mov    %ecx,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%edi
call   1040 <htonl@plt>
mov    %eax,%ecx
and    %ebx,%ecx
lea    0xe92(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    %ecx,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Use %s val mask\0A\00"
@.str.1 = [34 x i8] c"val:%x mask:%x = Hash is 0x%x/%d\0A\00"
@.str.2 = [41 x i8] c"htonl(val):%x mask:%x = Hash is 0x%x/%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 -1, i32* %3
br label %43
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strtoul(i8* %19, i32* null, i32 0)
store i32 %20, i32* %6
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @strtoul(i8* %23, i32* null, i32 0)
store i32 %24, i32* %7
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = and i32 %25, %26
store i32 %27, i32* %8
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = load i32, i32* %8
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %28, i32 %29, i32 %30, i32 %31)
%33 = load i32, i32* %6
%34 = call i32 @htonl(i32 %33)
%35 = load i32, i32* %7
%36 = and i32 %34, %35
store i32 %36, i32* %8
%37 = load i32, i32* %6
%38 = call i32 @htonl(i32 %37)
%39 = load i32, i32* %7
%40 = load i32, i32* %8
%41 = load i32, i32* %8
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %38, i32 %39, i32 %40, i32 %41)
store i32 0, i32* %3
br label %43
43: ; preds = %16, %11
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [17 x i8] c"Use %s val mask\0A\00"
@.str.1 = [34 x i8] c"val:%x mask:%x = Hash is 0x%x/%d\0A\00"
@.str.2 = [41 x i8] c"htonl(val):%x mask:%x = Hash is 0x%x/%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %19
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strtoul(i8* nocapture %9, i32* null, i32 0)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @strtoul(i8* nocapture %12, i32* null, i32 0)
%14 = and i32 %13, %10
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %13, i32 %14, i32 %14)
%16 = tail call i32 @htonl(i32 %10)
%17 = and i32 %16, %13
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %13, i32 %17, i32 %17)
br label %19
19: ; preds = %7, %4
%20 = phi i32 [ -1, %4 ], [ 0, %7 ]
ret i32 %20
}