#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 atoi(char *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strrchr(char const *, char);
int parse_pathspec(char *xpath, const char *path) {
  int revision;
  char *split;
  if (!(split = strrchr(path, '@')))
    goto END;
  revision = atoi(split + 1);
  if (revision < 0 || revision > 20)
    goto END;
  memcpy(xpath, path, split - path);
  xpath[split - path] = '\0';
  return revision;
END:
  strcpy(xpath, path);
  return 0;
}


x86 assembly (clang, -O0):
<parse_pathspec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x40,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1171 <parse_pathspec+0x31>
jmp    11d2 <parse_pathspec+0x92>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1195 <parse_pathspec+0x55>
cmpl   $0x14,-0x1c(%rbp)
jle    119a <parse_pathspec+0x5a>
jmp    11d2 <parse_pathspec+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e6 <parse_pathspec+0xa6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_pathspec>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x40,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1170 <parse_pathspec+0x30>
mov    %rax,%rbx
lea    0x1(%rax),%rdi
call   1060 <atoi@plt>
cmp    $0x14,%eax
jbe    117f <parse_pathspec+0x3f>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
xor    %ebp,%ebp
jmp    1196 <parse_pathspec+0x56>
mov    %eax,%ebp
sub    %r15,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
movb   $0x0,(%r14,%rbx,1)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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