int lookup_proto(name, proto)
register const char *name;
register int proto;
{
  register int v;
  switch (proto) {
  case 0:
  case 2:
    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;
  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    %eax,-0x14(%rbp)
test   %eax,%eax
je     1174 <lookup_proto+0x44>
jmp    1152 <lookup_proto+0x22>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     11a3 <lookup_proto+0x73>
jmp    1163 <lookup_proto+0x33>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
jne    11d2 <lookup_proto+0xa2>
jmp    1174 <lookup_proto+0x44>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1050 <pcap_nametoproto@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    119e <lookup_proto+0x6e>
mov    -0x8(%rbp),%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <bpf_error@plt>
jmp    11d9 <lookup_proto+0xa9>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <pcap_nametoeproto@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11cd <lookup_proto+0x9d>
mov    -0x8(%rbp),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <bpf_error@plt>
jmp    11d9 <lookup_proto+0xa9>
movl   $0xffffffff,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookup_proto>:
push   %rbx
mov    %rdi,%rbx
mov    $0xffffffff,%eax
cmp    $0x2,%esi
je     1147 <lookup_proto+0x17>
cmp    $0x1,%esi
je     1158 <lookup_proto+0x28>
test   %esi,%esi
jne    1156 <lookup_proto+0x26>
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <pcap_nametoproto@plt>
cmp    $0xffffffff,%eax
je     1170 <lookup_proto+0x40>
pop    %rbx
ret
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <pcap_nametoeproto@plt>
cmp    $0xffffffff,%eax
jne    1156 <lookup_proto+0x26>
lea    0xea8(%rip),%rdi
jmp    1177 <lookup_proto+0x47>
lea    0xe89(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <bpf_error@plt>
mov    $0xffffffff,%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"
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 %25 [
i32 0, label %7
i32 2, label %7
i32 1, label %16
]
7: ; preds = %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 %26
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 %26
25: ; preds = %2
store i32 -1, i32* %5
br label %26
26: ; preds = %25, %24, %15
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
@.str = [22 x i8] c"unknown ip proto '%s'\00"
@.str.1 = [25 x i8] c"unknown ether proto '%s'\00"
define i32 @lookup_proto(i8* %0, i32 %1) {
switch i32 %1, label %12 [
i32 0, label %3
i32 2, label %3
i32 1, label %6
]
3: ; preds = %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 %9, label %12
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 %12
9: ; preds = %6, %3
%10 = 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 ]
%11 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @bpf_error to i32 (i8*, i8*, ...)*)(i8* %10, i8* %0)
br label %12
12: ; preds = %9, %2, %6, %3
%13 = phi i32 [ %7, %6 ], [ %4, %3 ], [ -1, %2 ], [ -1, %9 ]
ret i32 %13
}