int lookup_proto(name, proto)
register const char *name;
register int proto;
{
  register int v;
  switch (proto) {
  case 0:
  case 2:
  case 17:
    v = pcap_nametoproto(name);
    if (v == -1)
      bpf_error("unknown ip proto '%s'", name);
    break;
  case 1:
    v = pcap_nametoeproto(name);
    if (v == -1)
      bpf_error("unknown ether proto '%s'", name);
    break;
  case 24:
    if (strcmp(name, "esis") == 0)
      v = 0x82;
    else if (strcmp(name, "isis") == 0)
      v = 0x83;
    else if (strcmp(name, "clnp") == 0)
      v = 0x81;
    else
      bpf_error("unknown osi proto '%s'", name);
    break;
  default:
    v = -1;
    break;
  }
  return v;
}


x86 assembly (clang, -O0):
<lookup_proto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x18,%rax
ja     1262 <lookup_proto+0x122>
mov    -0x18(%rbp),%rax
lea    0xe95(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1060 <pcap_nametoproto@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    119e <lookup_proto+0x5e>
mov    -0x8(%rbp),%rsi
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1050 <bpf_error@plt>
jmp    1269 <lookup_proto+0x129>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <pcap_nametoeproto@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11cd <lookup_proto+0x8d>
mov    -0x8(%rbp),%rsi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1050 <bpf_error@plt>
jmp    1269 <lookup_proto+0x129>
mov    -0x8(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11f7 <lookup_proto+0xb7>
movl   $0x82,-0x10(%rbp)
jmp    125d <lookup_proto+0x11d>
mov    -0x8(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    121c <lookup_proto+0xdc>
movl   $0x83,-0x10(%rbp)
jmp    1258 <lookup_proto+0x118>
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1241 <lookup_proto+0x101>
movl   $0x81,-0x10(%rbp)
jmp    1253 <lookup_proto+0x113>
mov    -0x8(%rbp),%rsi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <bpf_error@plt>
jmp    1258 <lookup_proto+0x118>
jmp    125d <lookup_proto+0x11d>
jmp    1269 <lookup_proto+0x129>
movl   $0xffffffff,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookup_proto>:
push   %rbx
mov    $0xffffffff,%eax
cmp    $0x18,%esi
ja     1174 <lookup_proto+0x34>
mov    %rdi,%rbx
mov    %esi,%eax
lea    0xea9(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
add    %rcx,%rdx
mov    $0xffffffff,%eax
jmp    *%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <pcap_nametoproto@plt>
cmp    $0xffffffff,%eax
je     1176 <lookup_proto+0x36>
pop    %rbx
ret
lea    0xee7(%rip),%rdi
jmp    11d7 <lookup_proto+0x97>
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <pcap_nametoeproto@plt>
cmp    $0xffffffff,%eax
jne    1174 <lookup_proto+0x34>
lea    0xee5(%rip),%rdi
jmp    11d7 <lookup_proto+0x97>
lea    0xef5(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11e8 <lookup_proto+0xa8>
lea    0xee7(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11ef <lookup_proto+0xaf>
lea    0xed9(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11f6 <lookup_proto+0xb6>
lea    0xecb(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <bpf_error@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
mov    $0x82,%eax
pop    %rbx
ret
mov    $0x83,%eax
pop    %rbx
ret
mov    $0x81,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"unknown ip proto '%s'\00"
@.str.1 = [25 x i8] c"unknown ether proto '%s'\00"
@.str.2 = [5 x i8] c"esis\00"
@.str.3 = [5 x i8] c"isis\00"
@.str.4 = [5 x i8] c"clnp\00"
@.str.5 = [23 x i8] c"unknown osi proto '%s'\00"
define i32 @lookup_proto(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
switch i32 %6, label %46 [
i32 0, label %7
i32 2, label %7
i32 17, label %7
i32 1, label %16
i32 24, label %25
]
7: ; preds = %2, %2, %2
%8 = load i8*, i8** %3
%9 = call i32 (i8*, ...) bitcast (i32 (...)* @pcap_nametoproto to i32 (i8*, ...)*)(i8* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i8*, i8** %3
%14 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @bpf_error to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %7
br label %47
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = call i32 (i8*, ...) bitcast (i32 (...)* @pcap_nametoeproto to i32 (i8*, ...)*)(i8* %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @bpf_error to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %16
br label %47
25: ; preds = %2
%26 = load i8*, i8** %3
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 130, i32* %5
br label %45
30: ; preds = %25
%31 = load i8*, i8** %3
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 131, i32* %5
br label %44
35: ; preds = %30
%36 = load i8*, i8** %3
%37 = call i32 @strcmp(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 129, i32* %5
br label %43
40: ; preds = %35
%41 = load i8*, i8** %3
%42 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @bpf_error to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %40, %39
br label %44
44: ; preds = %43, %34
br label %45
45: ; preds = %44, %29
br label %47
46: ; preds = %2
store i32 -1, i32* %5
br label %47
47: ; preds = %46, %45, %24, %15
%48 = load i32, i32* %5
ret i32 %48
}

LLVM IR (-O2):
@.str = [22 x i8] c"unknown ip proto '%s'\00"
@.str.1 = [25 x i8] c"unknown ether proto '%s'\00"
@.str.2 = [5 x i8] c"esis\00"
@.str.3 = [5 x i8] c"isis\00"
@.str.4 = [5 x i8] c"clnp\00"
@.str.5 = [23 x i8] c"unknown osi proto '%s'\00"
define i32 @lookup_proto(i8* %0, i32 %1) {
switch i32 %1, label %21 [
i32 0, label %3
i32 2, label %3
i32 17, label %3
i32 1, label %6
i32 24, label %9
]
3: ; preds = %2, %2, %2
%4 = tail call i32 (i8*, ...) bitcast (i32 (...)* @pcap_nametoproto to i32 (i8*, ...)*)(i8* %0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %18, label %21
6: ; preds = %2
%7 = tail call i32 (i8*, ...) bitcast (i32 (...)* @pcap_nametoeproto to i32 (i8*, ...)*)(i8* %0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %18, label %21
9: ; preds = %2
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15, %6, %3
%19 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), %6 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), %15 ]
%20 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @bpf_error to i32 (i8*, i8*, ...)*)(i8* %19, i8* %0)
br label %21
21: ; preds = %18, %2, %15, %12, %9, %6, %3
%22 = phi i32 [ %7, %6 ], [ %4, %3 ], [ 130, %9 ], [ 131, %12 ], [ 129, %15 ], [ -1, %2 ], [ -1, %18 ]
ret i32 %22
}