#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 */

/* Variables and functions */
int /*<<< orphan*/ NEXT_ARG();
scalar_t__ get_integer(int *, char *, int /*<<< orphan*/);
scalar_t__ matches(char *, char *);
scalar_t__ memcmp(char *, char *, scalar_t__);
scalar_t__ strlen(char *);
int parse_at(int *argc_p, char ***argv_p, int *off, int *offmask) {
  int argc = *argc_p;
  char **argv = *argv_p;
  char *p = *argv;
  if (argc <= 0)
    return -1;
  if (strlen(p) > strlen("nexthdr+") &&
      memcmp(p, "nexthdr+", strlen("nexthdr+")) == 0) {
    *offmask = -1;
    p += strlen("nexthdr+");
  } else if (matches(*argv, "nexthdr+") == 0) {
    NEXT_ARG();
    *offmask = -1;
    p = *argv;
  }
  if (get_integer(off, p, 0))
    return -1;
  argc--;
  argv++;
  *argc_p = argc;
  *argv_p = argv;
  return 0;
}


x86 assembly (clang, -O0):
<parse_at>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jg     119d <parse_at+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ad <parse_at+0x15d>
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x48(%rbp)
lea    0xe4f(%rip),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
cmp    %rcx,%rax
jle    121a <parse_at+0xca>
mov    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    0xe2b(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rdx
lea    0xe18(%rip),%rsi
call   1060 <memcmp@plt>
cmp    $0x0,%rax
jne    121a <parse_at+0xca>
mov    -0x28(%rbp),%rax
movl   $0xffffffff,(%rax)
lea    0xdf8(%rip),%rdi
call   1050 <strlen@plt>
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1258 <parse_at+0x108>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    0xdd8(%rip),%rsi
call   1040 <matches@plt>
cmp    $0x0,%rax
jne    1253 <parse_at+0x103>
mov    $0x0,%al
call   1070 <NEXT_ARG@plt>
mov    -0x28(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    1258 <parse_at+0x108>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
xor    %edx,%edx
call   1030 <get_integer@plt>
cmp    $0x0,%rax
je     127d <parse_at+0x12d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ad <parse_at+0x15d>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_at>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    (%rdi),%r12d
mov    $0xffffffff,%ebp
test   %r12d,%r12d
jle    1211 <parse_at+0xc1>
mov    %rdx,%r15
mov    %rdi,%r13
mov    %rcx,0x8(%rsp)
mov    %rsi,0x10(%rsp)
mov    (%rsi),%r14
mov    (%r14),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
cmp    $0x9,%rax
jl     11b2 <parse_at+0x62>
lea    0xe63(%rip),%rsi
mov    $0x8,%edx
mov    %rbx,%rdi
call   1060 <memcmp@plt>
test   %rax,%rax
je     11da <parse_at+0x8a>
mov    (%r14),%rdi
lea    0xe47(%rip),%rsi
call   1040 <matches@plt>
test   %rax,%rax
jne    11e9 <parse_at+0x99>
xor    %eax,%eax
call   1070 <NEXT_ARG@plt>
mov    0x8(%rsp),%rax
movl   $0xffffffff,(%rax)
mov    (%r14),%rbx
jmp    11e9 <parse_at+0x99>
mov    0x8(%rsp),%rax
movl   $0xffffffff,(%rax)
add    $0x8,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <get_integer@plt>
test   %rax,%rax
jne    1211 <parse_at+0xc1>
add    $0xffffffff,%r12d
add    $0x8,%r14
mov    %r12d,0x0(%r13)
mov    0x10(%rsp),%rax
mov    %r14,(%rax)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"nexthdr+\00"
define i32 @parse_at(i32* %0, i8*** %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8***
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i8**
%12 = alloca i8*
store i32* %0, i32** %6
store i8*** %1, i8**** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%13 = load i32*, i32** %6
%14 = load i32, i32* %13
store i32 %14, i32* %10
%15 = load i8***, i8**** %7
%16 = load i8**, i8*** %15
store i8** %16, i8*** %11
%17 = load i8**, i8*** %11
%18 = load i8*, i8** %17
store i8* %18, i8** %12
%19 = load i32, i32* %10
%20 = icmp sle i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %4
store i32 -1, i32* %5
br label %63
22: ; preds = %4
%23 = load i8*, i8** %12
%24 = call i64 @strlen(i8* %23)
%25 = call i64 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%26 = icmp sgt i64 %24, %25
br i1 %26, label %27, label %37
27: ; preds = %22
%28 = load i8*, i8** %12
%29 = call i64 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%30 = call i64 @memcmp(i8* %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i32*, i32** %9
store i32 -1, i32* %33
%34 = call i64 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%35 = load i8*, i8** %12
%36 = getelementptr inbounds i8, i8* %35, i64 %34
store i8* %36, i8** %12
br label %48
37: ; preds = %27, %22
%38 = load i8**, i8*** %11
%39 = load i8*, i8** %38
%40 = call i64 @matches(i8* %39, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = call i32 (...) @NEXT_ARG()
%44 = load i32*, i32** %9
store i32 -1, i32* %44
%45 = load i8**, i8*** %11
%46 = load i8*, i8** %45
store i8* %46, i8** %12
br label %47
47: ; preds = %42, %37
br label %48
48: ; preds = %47, %32
%49 = load i32*, i32** %8
%50 = load i8*, i8** %12
%51 = call i64 @get_integer(i32* %49, i8* %50, i32 0)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %48
store i32 -1, i32* %5
br label %63
54: ; preds = %48
%55 = load i32, i32* %10
%56 = add nsw i32 %55, -1
store i32 %56, i32* %10
%57 = load i8**, i8*** %11
%58 = getelementptr inbounds i8*, i8** %57, i32 1
store i8** %58, i8*** %11
%59 = load i32, i32* %10
%60 = load i32*, i32** %6
store i32 %59, i32* %60
%61 = load i8**, i8*** %11
%62 = load i8***, i8**** %7
store i8** %61, i8*** %62
store i32 0, i32* %5
br label %63
63: ; preds = %54, %53, %21
%64 = load i32, i32* %5
ret i32 %64
}

LLVM IR (-O2):
@.str = [9 x i8] c"nexthdr+\00"
define i32 @parse_at(i32* nocapture %0, i8*** nocapture %1, i32* %2, i32* nocapture writeonly %3) {
%5 = load i32, i32* %0
%6 = load i8**, i8*** %1
%7 = load i8*, i8** %6
%8 = icmp slt i32 %5, 1
br i1 %8, label %33, label %9
9: ; preds = %4
%10 = tail call i64 @strlen(i8* dereferenceable(1) %7)
%11 = icmp sgt i64 %10, 8
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = tail call i64 @memcmp(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 8)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = load i8*, i8** %6
br label %19
17: ; preds = %12
store i32 -1, i32* %3
%18 = getelementptr inbounds i8, i8* %7, i64 8
br label %26
19: ; preds = %15, %9
%20 = phi i8* [ %16, %15 ], [ %7, %9 ]
%21 = tail call i64 @matches(i8* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = tail call i32 (...) @NEXT_ARG()
store i32 -1, i32* %3
%25 = load i8*, i8** %6
br label %26
26: ; preds = %19, %23, %17
%27 = phi i8* [ %18, %17 ], [ %25, %23 ], [ %7, %19 ]
%28 = tail call i64 @get_integer(i32* %2, i8* %27, i32 0)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = add nsw i32 %5, -1
%32 = getelementptr inbounds i8*, i8** %6, i64 1
store i32 %31, i32* %0
store i8** %32, i8*** %1
br label %33
33: ; preds = %26, %4, %30
%34 = phi i32 [ 0, %30 ], [ -1, %4 ], [ -1, %26 ]
ret i32 %34
}