#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 size_t uint8_t;

/* Variables and functions */
char *strdash(char *);
char *strdig(char *);
size_t strlen(char *);
char *strstr(char *, char *);
char *getpos(char *str) {
  char *pos = NULL;
  size_t len;
  len = strlen(str);
  for (uint8_t i = 0; i < len && pos == NULL; i++) {
    switch (str[i]) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      pos = strdig(str);
      break;
    case '-':
    case '_':
      pos = strdash(str);
      break;
    default:
      break;
    }
  }
  if (pos == NULL) {
    pos = strstr(str, "git");
    pos--;
  }
  return pos;
}


x86 assembly (clang, -O0):
<getpos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x21(%rbp)
jae    1187 <getpos+0x47>
cmpq   $0x0,-0x10(%rbp)
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1197 <getpos+0x57>
jmp    1218 <getpos+0xd8>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x28(%rbp)
sub    $0x2d,%eax
je     11eb <getpos+0xab>
jmp    11b4 <getpos+0x74>
mov    -0x28(%rbp),%eax
add    $0xffffffd0,%eax
sub    $0xa,%eax
jb     11d9 <getpos+0x99>
jmp    11c8 <getpos+0x88>
mov    -0x28(%rbp),%eax
sub    $0x5f,%eax
je     11eb <getpos+0xab>
jmp    11fd <getpos+0xbd>
mov    -0x8(%rbp),%rdi
call   1030 <strdig@plt>
mov    %rax,-0x10(%rbp)
jmp    1202 <getpos+0xc2>
mov    -0x8(%rbp),%rdi
call   1050 <strdash@plt>
mov    %rax,-0x10(%rbp)
jmp    1202 <getpos+0xc2>
jmp    1202 <getpos+0xc2>
jmp    1207 <getpos+0xc7>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1169 <getpos+0x29>
cmpq   $0x0,-0x10(%rbp)
jne    1243 <getpos+0x103>
mov    -0x8(%rbp),%rdi
lea    0xdd2(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpos>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1040 <strlen@plt>
test   %rax,%rax
je     11ad <getpos+0x6d>
mov    %rax,%r14
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
movsbl -0x1(%r15,%rbx,1),%eax
lea    -0x30(%rax),%ecx
cmp    $0xa,%ecx
jae    1190 <getpos+0x50>
mov    %r15,%rdi
call   1030 <strdig@plt>
cmp    %r14,%rbx
jae    11a8 <getpos+0x68>
add    $0x1,%rbx
test   %rax,%rax
je     1160 <getpos+0x20>
jmp    11a8 <getpos+0x68>
cs nopw 0x0(%rax,%rax,1)
cmp    $0x2d,%eax
je     119a <getpos+0x5a>
cmp    $0x5f,%eax
jne    11a4 <getpos+0x64>
mov    %r15,%rdi
call   1050 <strdash@plt>
jmp    1176 <getpos+0x36>
xor    %eax,%eax
jmp    1176 <getpos+0x36>
test   %rax,%rax
jne    11c0 <getpos+0x80>
lea    0xe4c(%rip),%rsi
mov    %r15,%rdi
call   1060 <strstr@plt>
add    $0xffffffffffffffff,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"git\00"
define i8* @getpos(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %3
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %4
store i64 0, i64* %5
br label %8
8: ; preds = %31, %1
%9 = load i64, i64* %5
%10 = load i64, i64* %4
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = icmp eq i8* %13, null
br label %15
15: ; preds = %12, %8
%16 = phi i1 [ false, %8 ], [ %14, %12 ]
br i1 %16, label %17, label %34
17: ; preds = %15
%18 = load i8*, i8** %2
%19 = load i64, i64* %5
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
switch i32 %22, label %29 [
i32 48, label %23
i32 49, label %23
i32 50, label %23
i32 51, label %23
i32 52, label %23
i32 53, label %23
i32 54, label %23
i32 55, label %23
i32 56, label %23
i32 57, label %23
i32 45, label %26
i32 95, label %26
]
23: ; preds = %17, %17, %17, %17, %17, %17, %17, %17, %17, %17
%24 = load i8*, i8** %2
%25 = call i8* @strdig(i8* %24)
store i8* %25, i8** %3
br label %30
26: ; preds = %17, %17
%27 = load i8*, i8** %2
%28 = call i8* @strdash(i8* %27)
store i8* %28, i8** %3
br label %30
29: ; preds = %17
br label %30
30: ; preds = %29, %26, %23
br label %31
31: ; preds = %30
%32 = load i64, i64* %5
%33 = add i64 %32, 1
store i64 %33, i64* %5
br label %8
34: ; preds = %15
%35 = load i8*, i8** %3
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i8*, i8** %2
%39 = call i8* @strstr(i8* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %39, i8** %3
%40 = load i8*, i8** %3
%41 = getelementptr inbounds i8, i8* %40, i32 -1
store i8* %41, i8** %3
br label %42
42: ; preds = %37, %34
%43 = load i8*, i8** %3
ret i8* %43
}

LLVM IR (-O2):
@.str = [4 x i8] c"git\00"
define i8* @getpos(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %20, label %5
4: ; preds = %14
br i1 %18, label %20, label %23
5: ; preds = %1, %14
%6 = phi i64 [ %16, %14 ], [ 0, %1 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
switch i32 %9, label %14 [
i32 48, label %10
i32 49, label %10
i32 50, label %10
i32 51, label %10
i32 52, label %10
i32 53, label %10
i32 54, label %10
i32 55, label %10
i32 56, label %10
i32 57, label %10
i32 45, label %12
i32 95, label %12
]
10: ; preds = %5, %5, %5, %5, %5, %5, %5, %5, %5, %5
%11 = tail call i8* @strdig(i8* %0)
br label %14
12: ; preds = %5, %5
%13 = tail call i8* @strdash(i8* %0)
br label %14
14: ; preds = %10, %12, %5
%15 = phi i8* [ null, %5 ], [ %13, %12 ], [ %11, %10 ]
%16 = add nuw i64 %6, 1
%17 = icmp ult i64 %16, %2
%18 = icmp eq i8* %15, null
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %5, label %4
20: ; preds = %1, %4
%21 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%22 = getelementptr inbounds i8, i8* %21, i64 -1
br label %23
23: ; preds = %20, %4
%24 = phi i8* [ %22, %20 ], [ %15, %4 ]
ret i8* %24
}