#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*/ free(char *);
char *getcwd(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ isalpha(char);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *strrchr(char *, char);
char *get_pkgversion() {
  int i;
  char *cwd = getcwd(NULL, 0);
  char *v = strrchr(cwd, '-');
  char *version = malloc(sizeof(char) * 512);
  memset(version, 0, 512);
  if (v) {
    v++;
    for (i = 0; i < 512; ++i) {
      if (isalpha(v[i]) && (v[i - 1] == '.'))
        break;
      else
        version[i] = v[i];
    }
  } else {
    version = "";
  }
  free(cwd);
  return version;
}


x86 assembly (clang, -O0):
<get_pkgversion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1060 <getcwd@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2d,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
cmpq   $0x0,-0x18(%rbp)
je     123a <get_pkgversion+0xda>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x200,-0x4(%rbp)
jge    1235 <get_pkgversion+0xd5>
mov    -0x18(%rbp),%rax
movslq -0x4(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1080 <isalpha@plt>
cmp    $0x0,%rax
je     120c <get_pkgversion+0xac>
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    120c <get_pkgversion+0xac>
jmp    1235 <get_pkgversion+0xd5>
mov    -0x18(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1227 <get_pkgversion+0xc7>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <get_pkgversion+0x65>
jmp    1245 <get_pkgversion+0xe5>
lea    0xdbf(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pkgversion>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
xor    %esi,%esi
call   1060 <getcwd@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x2d,%esi
call   1040 <strrchr@plt>
mov    %rax,%r12
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
test   %r12,%r12
je     11e0 <get_pkgversion+0x80>
xor    %ebx,%ebx
jmp    11c7 <get_pkgversion+0x67>
nopl   0x0(%rax)
movzbl 0x1(%r12,%rbx,1),%eax
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    $0x200,%rbx
je     11e7 <get_pkgversion+0x87>
movsbl 0x1(%r12,%rbx,1),%edi
call   1080 <isalpha@plt>
test   %rax,%rax
je     11b0 <get_pkgversion+0x50>
cmpb   $0x2e,(%r12,%rbx,1)
jne    11b0 <get_pkgversion+0x50>
jmp    11e7 <get_pkgversion+0x87>
lea    0xe19(%rip),%r15
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @get_pkgversion() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i8* @getcwd(i32* null, i32 0)
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @strrchr(i8* %6, i8 signext 45)
store i8* %7, i8** %3
%8 = call i8* @malloc(i32 512)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @memset(i8* %9, i32 0, i32 512)
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %52
13: ; preds = %0
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %3
store i32 0, i32* %1
br label %16
16: ; preds = %48, %13
%17 = load i32, i32* %1
%18 = icmp slt i32 %17, 512
br i1 %18, label %19, label %51
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = load i32, i32* %1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = call i64 @isalpha(i8 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %19
%28 = load i8*, i8** %3
%29 = load i32, i32* %1
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 46
br i1 %35, label %36, label %37
36: ; preds = %27
br label %51
37: ; preds = %27, %19
%38 = load i8*, i8** %3
%39 = load i32, i32* %1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = load i8*, i8** %4
%44 = load i32, i32* %1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 %42, i8* %46
br label %47
47: ; preds = %37
br label %48
48: ; preds = %47
%49 = load i32, i32* %1
%50 = add nsw i32 %49, 1
store i32 %50, i32* %1
br label %16
51: ; preds = %36, %16
br label %53
52: ; preds = %0
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %4
br label %53
53: ; preds = %52, %51
%54 = load i8*, i8** %2
%55 = call i32 @free(i8* %54)
%56 = load i8*, i8** %4
ret i8* %56
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @get_pkgversion() {
%1 = tail call i8* @getcwd(i32* null, i32 0)
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 45)
%3 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%4 = tail call i32 @memset(i8* %3, i32 0, i32 512)
%5 = icmp eq i8* %2, null
br i1 %5, label %23, label %6
6: ; preds = %0
%7 = getelementptr inbounds i8, i8* %2, i64 1
br label %8
8: ; preds = %6, %18
%9 = phi i64 [ 0, %6 ], [ %21, %18 ]
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8, i8* %10
%12 = tail call i64 @isalpha(i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %8
%15 = getelementptr inbounds i8, i8* %2, i64 %9
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 46
br i1 %17, label %23, label %18
18: ; preds = %14, %8
%19 = load i8, i8* %10
%20 = getelementptr inbounds i8, i8* %3, i64 %9
store i8 %19, i8* %20
%21 = add nuw nsw i64 %9, 1
%22 = icmp eq i64 %21, 512
br i1 %22, label %23, label %8
23: ; preds = %18, %14, %0
%24 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %0 ], [ %3, %14 ], [ %3, %18 ]
%25 = tail call i32 @free(i8* %1)
ret i8* %24
}