int find_ip_ppp(char *buf) {
  unsigned char ppp_byte0;
  unsigned short ppp_proto_type;
  int offset = -1;
  memcpy(&ppp_byte0, buf, 1);
  switch (ppp_byte0) {
  case 0xff:
    memcpy(&ppp_proto_type, buf + 2, 2);
    ppp_proto_type = ntohs(ppp_proto_type);
    if (ppp_proto_type == 0x21)
      offset = 4;
    else
      offset = -1;
    break;
  case 0x21:
    offset = 1;
    break;
  case 0x00:
    memcpy(&ppp_proto_type, buf, 2);
    ppp_proto_type = ntohs(ppp_proto_type);
    if (ppp_proto_type == 0x21)
      offset = 2;
    else
      offset = -1;
    break;
  default:
    offset = -1;
    break;
  }
  return offset;
}


x86 assembly (clang, -O0):
<find_ip_ppp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     11b0 <find_ip_ppp+0xa0>
jmp    1140 <find_ip_ppp+0x30>
mov    -0x14(%rbp),%eax
sub    $0x21,%eax
je     11a4 <find_ip_ppp+0x94>
jmp    1151 <find_ip_ppp+0x41>
mov    -0x14(%rbp),%eax
sub    $0xff,%eax
jne    11ef <find_ip_ppp+0xdf>
jmp    1164 <find_ip_ppp+0x54>
mov    -0x8(%rbp),%rax
mov    0x2(%rax),%ax
mov    %ax,-0xc(%rbp)
movzwl -0xc(%rbp),%edi
mov    $0x0,%al
call   1030 <ntohs@plt>
mov    %ax,-0xc(%rbp)
movzwl -0xc(%rbp),%eax
cmp    $0x21,%eax
jne    1198 <find_ip_ppp+0x88>
movl   $0x4,-0x10(%rbp)
jmp    119f <find_ip_ppp+0x8f>
movl   $0xffffffff,-0x10(%rbp)
jmp    11f6 <find_ip_ppp+0xe6>
movl   $0x1,-0x10(%rbp)
jmp    11f6 <find_ip_ppp+0xe6>
mov    -0x8(%rbp),%rax
mov    (%rax),%ax
mov    %ax,-0xc(%rbp)
movzwl -0xc(%rbp),%edi
mov    $0x0,%al
call   1030 <ntohs@plt>
mov    %ax,-0xc(%rbp)
movzwl -0xc(%rbp),%eax
cmp    $0x21,%eax
jne    11e3 <find_ip_ppp+0xd3>
movl   $0x2,-0x10(%rbp)
jmp    11ea <find_ip_ppp+0xda>
movl   $0xffffffff,-0x10(%rbp)
jmp    11f6 <find_ip_ppp+0xe6>
movl   $0xffffffff,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_ip_ppp>:
push   %rax
mov    (%rdi),%al
cmp    $0x21,%al
je     113b <find_ip_ppp+0x2b>
test   %al,%al
je     1142 <find_ip_ppp+0x32>
cmp    $0xff,%al
jne    115d <find_ip_ppp+0x4d>
movzwl 0x2(%rdi),%edi
xor    %eax,%eax
call   1030 <ntohs@plt>
xor    %ecx,%ecx
cmp    $0x21,%ax
sete   %cl
lea    (%rcx,%rcx,4),%eax
add    $0xffffffff,%eax
pop    %rcx
ret
mov    $0x1,%eax
pop    %rcx
ret
movzwl (%rdi),%edi
xor    %eax,%eax
call   1030 <ntohs@plt>
xor    %ecx,%ecx
cmp    $0x21,%ax
sete   %cl
lea    (%rcx,%rcx,2),%eax
add    $0xffffffff,%eax
pop    %rcx
ret
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @find_ip_ppp(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i16
%5 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %5
%6 = load i8*, i8** %2
%7 = load i8, i8* %3
%8 = zext i8 %7 to i32
switch i32 %8, label %37 [
i32 255, label %9
i32 33, label %23
i32 0, label %24
]
9: ; preds = %1
%10 = bitcast i16* %4 to i8*
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 2
%13 = load i16, i16* %4
%14 = zext i16 %13 to i32
%15 = call i32 (i32, ...) bitcast (i32 (...)* @ntohs to i32 (i32, ...)*)(i32 %14)
%16 = trunc i32 %15 to i16
store i16 %16, i16* %4
%17 = load i16, i16* %4
%18 = zext i16 %17 to i32
%19 = icmp eq i32 %18, 33
br i1 %19, label %20, label %21
20: ; preds = %9
store i32 4, i32* %5
br label %22
21: ; preds = %9
store i32 -1, i32* %5
br label %22
22: ; preds = %21, %20
br label %38
23: ; preds = %1
store i32 1, i32* %5
br label %38
24: ; preds = %1
%25 = bitcast i16* %4 to i8*
%26 = load i8*, i8** %2
%27 = load i16, i16* %4
%28 = zext i16 %27 to i32
%29 = call i32 (i32, ...) bitcast (i32 (...)* @ntohs to i32 (i32, ...)*)(i32 %28)
%30 = trunc i32 %29 to i16
store i16 %30, i16* %4
%31 = load i16, i16* %4
%32 = zext i16 %31 to i32
%33 = icmp eq i32 %32, 33
br i1 %33, label %34, label %35
34: ; preds = %24
store i32 2, i32* %5
br label %36
35: ; preds = %24
store i32 -1, i32* %5
br label %36
36: ; preds = %35, %34
br label %38
37: ; preds = %1
store i32 -1, i32* %5
br label %38
38: ; preds = %37, %36, %23, %22
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
define i32 @find_ip_ppp(i8* nocapture %0) {
%2 = load i8, i8* %0
switch i8 %2, label %20 [
i8 -1, label %3
i8 33, label %21
i8 0, label %12
]
3: ; preds = %1
%4 = getelementptr inbounds i8, i8* %0, i64 2
%5 = bitcast i8* %4 to i16*
%6 = load i16, i16* %5
%7 = zext i16 %6 to i32
%8 = tail call i32 (i32, ...) bitcast (i32 (...)* @ntohs to i32 (i32, ...)*)(i32 %7)
%9 = and i32 %8, 65535
%10 = icmp eq i32 %9, 33
%11 = select i1 %10, i32 4, i32 -1
br label %21
12: ; preds = %1
%13 = bitcast i8* %0 to i16*
%14 = load i16, i16* %13
%15 = zext i16 %14 to i32
%16 = tail call i32 (i32, ...) bitcast (i32 (...)* @ntohs to i32 (i32, ...)*)(i32 %15)
%17 = and i32 %16, 65535
%18 = icmp eq i32 %17, 33
%19 = select i1 %18, i32 2, i32 -1
br label %21
20: ; preds = %1
br label %21
21: ; preds = %12, %1, %3, %20
%22 = phi i32 [ -1, %20 ], [ %11, %3 ], [ 1, %1 ], [ %19, %12 ]
ret i32 %22
}