#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 */
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ strlen(char const *);
char *strstr(char *, char const *);
int32_t get_xval(char *buff, const char *start, const char *end, char **p) {
  if (buff == NULL)
    return -1;
  char *p1, *p2;
  int32_t stlen = (int32_t)strlen(start);
  p1 = strstr(buff, start);
  if (p1 == NULL)
    return 0;
  p2 = strstr(p1 + stlen, end);
  if (p2 == NULL)
    return 0;
  *p = p1 + stlen;
  return (int32_t)(p2 - *p);
}


x86 assembly (clang, -O0):
<get_xval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114f <get_xval+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <get_xval+0xb5>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1183 <get_xval+0x63>
movl   $0x0,-0x4(%rbp)
jmp    11d5 <get_xval+0xb5>
mov    -0x30(%rbp),%rdi
movslq -0x3c(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11b2 <get_xval+0x92>
movl   $0x0,-0x4(%rbp)
jmp    11d5 <get_xval+0xb5>
mov    -0x30(%rbp),%rcx
movslq -0x3c(%rbp),%rax
add    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_xval>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     1178 <get_xval+0x58>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <strstr@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     117d <get_xval+0x5d>
mov    %rax,%rbx
movslq %r12d,%rax
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     117d <get_xval+0x5d>
mov    %rbx,(%r14)
sub    %ebx,%eax
mov    %eax,%ebp
jmp    117d <get_xval+0x5d>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_xval(i8* %0, i8* %1, i8* %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8** %3, i8*** %9
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 -1, i32* %5
br label %48
16: ; preds = %4
%17 = load i8*, i8** %7
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %12
%19 = load i8*, i8** %6
%20 = load i8*, i8** %7
%21 = call i8* @strstr(i8* %19, i8* %20)
store i8* %21, i8** %10
%22 = load i8*, i8** %10
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %16
store i32 0, i32* %5
br label %48
25: ; preds = %16
%26 = load i8*, i8** %10
%27 = load i32, i32* %12
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8*, i8** %8
%31 = call i8* @strstr(i8* %29, i8* %30)
store i8* %31, i8** %11
%32 = load i8*, i8** %11
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %35
34: ; preds = %25
store i32 0, i32* %5
br label %48
35: ; preds = %25
%36 = load i8*, i8** %10
%37 = load i32, i32* %12
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8**, i8*** %9
store i8* %39, i8** %40
%41 = load i8*, i8** %11
%42 = load i8**, i8*** %9
%43 = load i8*, i8** %42
%44 = ptrtoint i8* %41 to i64
%45 = ptrtoint i8* %43 to i64
%46 = sub i64 %44, %45
%47 = trunc i64 %46 to i32
store i32 %47, i32* %5
br label %48
48: ; preds = %35, %34, %24, %15
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
define i32 @get_xval(i8* %0, i8* %1, i8* nocapture %2, i8** nocapture writeonly %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %20, label %6
6: ; preds = %4
%7 = tail call i32 @strlen(i8* %1)
%8 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %20, label %10
10: ; preds = %6
%11 = sext i32 %7 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
%13 = tail call i8* @strstr(i8* %12, i8* dereferenceable(1) %2)
%14 = icmp eq i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %10
store i8* %12, i8** %3
%16 = ptrtoint i8* %13 to i64
%17 = ptrtoint i8* %12 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
br label %20
20: ; preds = %15, %6, %10, %4
%21 = phi i32 [ -1, %4 ], [ %19, %15 ], [ 0, %6 ], [ 0, %10 ]
ret i32 %21
}