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) {
      v = pcap_nametollc(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     128f <lookup_proto+0x13f>
mov    -0x18(%rbp),%rax
lea    0xe85(%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    11ae <lookup_proto+0x5e>
mov    -0x8(%rbp),%rsi
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1050 <bpf_error@plt>
jmp    1296 <lookup_proto+0x146>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <pcap_nametoeproto@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11fa <lookup_proto+0xaa>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1070 <pcap_nametollc@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11f5 <lookup_proto+0xa5>
mov    -0x8(%rbp),%rsi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1050 <bpf_error@plt>
jmp    11fa <lookup_proto+0xaa>
jmp    1296 <lookup_proto+0x146>
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1224 <lookup_proto+0xd4>
movl   $0x82,-0x10(%rbp)
jmp    128a <lookup_proto+0x13a>
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1249 <lookup_proto+0xf9>
movl   $0x83,-0x10(%rbp)
jmp    1285 <lookup_proto+0x135>
mov    -0x8(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    126e <lookup_proto+0x11e>
movl   $0x81,-0x10(%rbp)
jmp    1280 <lookup_proto+0x130>
mov    -0x8(%rbp),%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1050 <bpf_error@plt>
jmp    1285 <lookup_proto+0x135>
jmp    128a <lookup_proto+0x13a>
jmp    1296 <lookup_proto+0x146>
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     1184 <lookup_proto+0x34>
mov    %rdi,%rbx
mov    %esi,%eax
lea    0xe99(%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     1186 <lookup_proto+0x36>
pop    %rbx
ret
lea    0xed7(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <bpf_error@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <pcap_nametoeproto@plt>
cmp    $0xffffffff,%eax
jne    1184 <lookup_proto+0x34>
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <pcap_nametollc@plt>
cmp    $0xffffffff,%eax
jne    1184 <lookup_proto+0x34>
lea    0xeb7(%rip),%rdi
jmp    118d <lookup_proto+0x3d>
lea    0xec7(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1207 <lookup_proto+0xb7>
lea    0xeb9(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     120e <lookup_proto+0xbe>
lea    0xeab(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1215 <lookup_proto+0xc5>
lea    0xe9d(%rip),%rdi
jmp    118d <lookup_proto+0x3d>
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 %52 [
i32 0, label %7
i32 2, label %7
i32 17, label %7
i32 1, label %16
i32 24, label %31
]
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 %53
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 %30
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = call i32 (i8*, ...) bitcast (i32 (...)* @pcap_nametollc to i32 (i8*, ...)*)(i8* %22)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i8*, i8** %3
%28 = 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* %27)
br label %29
29: ; preds = %26, %21
br label %30
30: ; preds = %29, %16
br label %53
31: ; preds = %2
%32 = load i8*, i8** %3
%33 = call i32 @strcmp(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 130, i32* %5
br label %51
36: ; preds = %31
%37 = load i8*, i8** %3
%38 = call i32 @strcmp(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %36
store i32 131, i32* %5
br label %50
41: ; preds = %36
%42 = load i8*, i8** %3
%43 = call i32 @strcmp(i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %41
store i32 129, i32* %5
br label %49
46: ; preds = %41
%47 = load i8*, i8** %3
%48 = 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* %47)
br label %49
49: ; preds = %46, %45
br label %50
50: ; preds = %49, %40
br label %51
51: ; preds = %50, %35
br label %53
52: ; preds = %2
store i32 -1, i32* %5
br label %53
53: ; preds = %52, %51, %30, %15
%54 = load i32, i32* %5
ret i32 %54
}

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 %24 [
i32 0, label %3
i32 2, label %3
i32 17, label %3
i32 1, label %6
i32 24, label %12
]
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 %21, label %24
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 %9, label %24
9: ; preds = %6
%10 = tail call i32 (i8*, ...) bitcast (i32 (...)* @pcap_nametollc to i32 (i8*, ...)*)(i8* %0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %21, label %24
12: ; preds = %2
%13 = 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))
%14 = icmp eq i32 %13, 0
br i1 %14, label %24, 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.3, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = 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))
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18, %9, %3
%22 = 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), %9 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), %18 ]
%23 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @bpf_error to i32 (i8*, i8*, ...)*)(i8* %22, i8* %0)
br label %24
24: ; preds = %21, %2, %18, %15, %12, %6, %9, %3
%25 = phi i32 [ %10, %9 ], [ %7, %6 ], [ %4, %3 ], [ 130, %12 ], [ 131, %15 ], [ 129, %18 ], [ -1, %2 ], [ -1, %21 ]
ret i32 %25
}