#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;
struct in_addr {
  int s_addr;
};

/* Variables and functions */
int ipAddressLevel(struct in_addr *addr, int offset) {
  uint32_t a = addr->s_addr;
  if ((a & 0xFF) == 10) {
    return 1 + offset;
  } else if (((a & 0xFF) == 172) && ((a >> 8 & 0xF0) == 16)) {
    return 1 + offset;
  } else if (((a & 0xFF) == 192) && ((a >> 8 & 0xFF) == 168)) {
    return 1 + offset;
  } else {
    return 3 + offset;
  }
}


x86 assembly (clang, -O0):
<ipAddressLevel>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
cmp    $0xa,%eax
jne    1133 <ipAddressLevel+0x33>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11a8 <ipAddressLevel+0xa8>
mov    -0x18(%rbp),%eax
and    $0xff,%eax
cmp    $0xac,%eax
jne    1168 <ipAddressLevel+0x68>
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xf0,%eax
cmp    $0x10,%eax
jne    1168 <ipAddressLevel+0x68>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11a8 <ipAddressLevel+0xa8>
mov    -0x18(%rbp),%eax
and    $0xff,%eax
cmp    $0xc0,%eax
jne    119f <ipAddressLevel+0x9f>
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
cmp    $0xa8,%eax
jne    119f <ipAddressLevel+0x9f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11a8 <ipAddressLevel+0xa8>
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipAddressLevel>:
mov    (%rdi),%ecx
mov    $0x1,%eax
cmp    $0xa,%cl
je     1139 <ipAddressLevel+0x39>
cmp    $0xc0,%cl
je     1126 <ipAddressLevel+0x26>
cmp    $0xac,%cl
jne    1134 <ipAddressLevel+0x34>
and    $0xf000,%ecx
cmp    $0x1000,%ecx
jne    1134 <ipAddressLevel+0x34>
jmp    1139 <ipAddressLevel+0x39>
and    $0xff00,%ecx
cmp    $0xa800,%ecx
je     1139 <ipAddressLevel+0x39>
mov    $0x3,%eax
add    %esi,%eax
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
define i32 @ipAddressLevel(%struct.in_addr* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.in_addr*
%5 = alloca i32
%6 = alloca i32
store %struct.in_addr* %0, %struct.in_addr** %4
store i32 %1, i32* %5
%7 = load %struct.in_addr*, %struct.in_addr** %4
%8 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
%9 = load i32, i32* %8
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = and i32 %10, 255
%12 = icmp eq i32 %11, 10
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* %5
%15 = add nsw i32 1, %14
store i32 %15, i32* %3
br label %43
16: ; preds = %2
%17 = load i32, i32* %6
%18 = and i32 %17, 255
%19 = icmp eq i32 %18, 172
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i32, i32* %6
%22 = ashr i32 %21, 8
%23 = and i32 %22, 240
%24 = icmp eq i32 %23, 16
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32, i32* %5
%27 = add nsw i32 1, %26
store i32 %27, i32* %3
br label %43
28: ; preds = %20, %16
%29 = load i32, i32* %6
%30 = and i32 %29, 255
%31 = icmp eq i32 %30, 192
br i1 %31, label %32, label %40
32: ; preds = %28
%33 = load i32, i32* %6
%34 = ashr i32 %33, 8
%35 = and i32 %34, 255
%36 = icmp eq i32 %35, 168
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i32, i32* %5
%39 = add nsw i32 1, %38
store i32 %39, i32* %3
br label %43
40: ; preds = %32, %28
%41 = load i32, i32* %5
%42 = add nsw i32 3, %41
store i32 %42, i32* %3
br label %43
43: ; preds = %40, %37, %25, %13
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
define i32 @ipAddressLevel(%struct.in_addr* nocapture %0, i32 %1) {
%3 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = trunc i32 %4 to i8
switch i8 %5, label %12 [
i8 10, label %13
i8 -84, label %6
i8 -64, label %9
]
6: ; preds = %2
%7 = and i32 %4, 61440
%8 = icmp eq i32 %7, 4096
br i1 %8, label %13, label %12
9: ; preds = %2
%10 = and i32 %4, 65280
%11 = icmp eq i32 %10, 43008
br i1 %11, label %13, label %12
12: ; preds = %6, %2, %9
br label %13
13: ; preds = %9, %6, %2, %12
%14 = phi i32 [ 3, %12 ], [ 1, %2 ], [ 1, %6 ], [ 1, %9 ]
%15 = add nsw i32 %14, %1
ret i32 %15
}