#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int /*<<< orphan*/ rm_eo;
  int /*<<< orphan*/ rm_so;
};
typedef TYPE_1__ regmatch_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ REG_EXTENDED;
int REG_NOMATCH;
char *cs_substr(char const *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int regcomp(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char const *, int, TYPE_1__ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *pkg_name(const char *input) {
  (void)(0);
  const char *regex = "^(/.*/)?("
                      "[a-zA-Z][a-zA-Z0-9_-]*"
                      ")"
                      "-[0-9].*-[0-9]+-(any|i686|x86_64).pkg.tar.(gz|bz2|xz)$";
  char errbuf[BUFSIZ];
  int errcode;
  regex_t preg;
  errcode = regcomp(&preg, regex, REG_EXTENDED);
  if (errcode != 0) {
    regerror(errcode, &preg, errbuf, sizeof errbuf);
    fprintf(stderr,
            "Error: "
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/cassava/repo-keep/refs/heads/master/src/"
            "actions.c"
            " ("
            "390"
            "): "
            "regcomp: %s\n",
            errbuf);
    return NULL;
  }
  char *result = NULL;
  regmatch_t pmatch[3];
  errcode = regexec(&preg, input, 3, pmatch, 0);
  if (errcode == 0) {
    result = cs_substr(input, pmatch[2].rm_so, pmatch[2].rm_eo);
  } else if (errcode == REG_NOMATCH) {
    goto end;
  } else {
    regerror(errcode, &preg, errbuf, sizeof errbuf);
    fprintf(stderr,
            "Error: "
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/cassava/repo-keep/refs/heads/master/src/"
            "actions.c"
            " ("
            "403"
            "): "
            "regexec: %s\n",
            errbuf);
    goto end;
  }
end:
  regfree(&preg);
  return result;
}


x86 assembly (clang, -O0):
<pkg_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8d(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x70(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
mov    0x2e16(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rdi
call   1050 <regcomp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     120d <pkg_name+0xad>
mov    -0x68(%rbp),%rdx
mov    -0x70(%rbp),%rax
mov    -0x2c(%rbp),%edi
mov    %eax,%ecx
lea    -0x30(%rbp),%rsi
call   1070 <regerror@plt>
mov    -0x68(%rbp),%rdx
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    12bb <pkg_name+0x15b>
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x60(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x3,%edx
xor    %r8d,%r8d
call   1080 <regexec@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1253 <pkg_name+0xf3>
mov    -0x10(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    -0x50(%rbp),%edx
call   1040 <cs_substr@plt>
mov    %rax,-0x40(%rbp)
jmp    129e <pkg_name+0x13e>
mov    -0x2c(%rbp),%eax
mov    0x2d8b(%rip),%rcx
cmp    (%rcx),%eax
jne    126a <pkg_name+0x10a>
jmp    12a3 <pkg_name+0x143>
mov    -0x68(%rbp),%rdx
mov    -0x70(%rbp),%rax
mov    -0x2c(%rbp),%edi
mov    %eax,%ecx
lea    -0x30(%rbp),%rsi
call   1070 <regerror@plt>
mov    -0x68(%rbp),%rdx
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12a3 <pkg_name+0x143>
jmp    12a3 <pkg_name+0x143>
lea    -0x30(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pkg_name>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r15
mov    0x2e59(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
lea    0xe62(%rip),%rsi
lea    -0x1c(%rbp),%rdi
call   1050 <regcomp@plt>
test   %eax,%eax
je     11d8 <pkg_name+0x78>
lea    -0x1c(%rbp),%rsi
mov    %eax,%edi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1070 <regerror@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
xor    %ebx,%ebx
jmp    1246 <pkg_name+0xe6>
lea    -0x1c(%rbp),%rdi
lea    -0x40(%rbp),%rcx
mov    %r15,%rsi
mov    $0x3,%edx
xor    %r8d,%r8d
call   1080 <regexec@plt>
test   %eax,%eax
je     122c <pkg_name+0xcc>
mov    0x2ded(%rip),%rcx
cmp    (%rcx),%eax
je     1228 <pkg_name+0xc8>
lea    -0x1c(%rbp),%rsi
mov    %eax,%edi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1070 <regerror@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xede(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
xor    %ebx,%ebx
jmp    123d <pkg_name+0xdd>
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%esi
mov    %r15,%rdi
call   1040 <cs_substr@plt>
mov    %rax,%rbx
lea    -0x1c(%rbp),%rdi
call   1030 <regfree@plt>
mov    %rbx,%rax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [87 x i8] c"^(/.*/)?([a-zA-Z][a-zA-Z0-9_-]*)-[0-9].*-[0-9]+-(any|i686|x86_64).pkg.tar.(gz|bz2|xz)$\00"
@BUFSIZ = global i32 0
@REG_EXTENDED = global i32 0
@stderr = global i32 0
@.str.1 = [167 x i8] c"Error: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cassava/repo-keep/refs/heads/master/src/actions.c (390): regcomp: %s\0A\00"
@REG_NOMATCH = global i32 0
@.str.2 = [167 x i8] c"Error: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cassava/repo-keep/refs/heads/master/src/actions.c (403): regexec: %s\0A\00"
define i8* @pkg_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [3 x %struct.TYPE_3__]
store i8* %0, i8** %3
store i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0), i8** %4
%12 = load i32, i32* @BUFSIZ
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %5
%15 = alloca i8, i64 %13
store i64 %13, i64* %6
%16 = load i8*, i8** %4
%17 = load i32, i32* @REG_EXTENDED
%18 = call i32 @regcomp(i32* %8, i8* %16, i32 %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %1
%22 = load i32, i32* %7
%23 = trunc i64 %13 to i32
%24 = call i32 @regerror(i32 %22, i32* %8, i8* %15, i32 %23)
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i8* null, i8** %2
store i32 1, i32* %9
br label %57
27: ; preds = %1
store i8* null, i8** %10
%28 = load i8*, i8** %3
%29 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %11, i64 0, i64 0
%30 = call i32 @regexec(i32* %8, i8* %28, i32 3, %struct.TYPE_3__* %29, i32 0)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %27
%34 = load i8*, i8** %3
%35 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %11, i64 0, i64 2
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %35, i32 0, i32 1
%37 = load i32, i32* %36
%38 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %11, i64 0, i64 2
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i8* @cs_substr(i8* %34, i32 %37, i32 %40)
store i8* %41, i8** %10
br label %53
42: ; preds = %27
%43 = load i32, i32* %7
%44 = load i32, i32* @REG_NOMATCH
%45 = icmp eq i32 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %42
br label %54
47: ; preds = %42
%48 = load i32, i32* %7
%49 = trunc i64 %13 to i32
%50 = call i32 @regerror(i32 %48, i32* %8, i8* %15, i32 %49)
%51 = load i32, i32* @stderr
%52 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %54
53: ; preds = %33
br label %54
54: ; preds = %53, %47, %46
%55 = call i32 @regfree(i32* %8)
%56 = load i8*, i8** %10
store i8* %56, i8** %2
store i32 1, i32* %9
br label %57
57: ; preds = %54, %21
%58 = load i8*, i8** %5
%59 = load i8*, i8** %2
ret i8* %59
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [87 x i8] c"^(/.*/)?([a-zA-Z][a-zA-Z0-9_-]*)-[0-9].*-[0-9]+-(any|i686|x86_64).pkg.tar.(gz|bz2|xz)$\00"
@BUFSIZ = global i32 0
@REG_EXTENDED = global i32 0
@stderr = global i32 0
@.str.1 = [167 x i8] c"Error: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cassava/repo-keep/refs/heads/master/src/actions.c (390): regcomp: %s\0A\00"
@REG_NOMATCH = global i32 0
@.str.2 = [167 x i8] c"Error: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cassava/repo-keep/refs/heads/master/src/actions.c (403): regexec: %s\0A\00"
define i8* @pkg_name(i8* %0) {
%2 = alloca i32
%3 = alloca [3 x %struct.TYPE_3__]
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast i32* %2 to i8*
%8 = load i32, i32* @REG_EXTENDED
%9 = call i32 @regcomp(i32* %2, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %1
%12 = call i32 @regerror(i32 %9, i32* %2, i8* %6, i32 %4)
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %36
15: ; preds = %1
%16 = bitcast [3 x %struct.TYPE_3__]* %3 to i8*
%17 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %3, i64 0, i64 0
%18 = call i32 @regexec(i32* %2, i8* %0, i32 3, %struct.TYPE_3__* %17, i32 0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %3, i64 0, i64 2, i32 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %3, i64 0, i64 2, i32 0
%24 = load i32, i32* %23
%25 = call i8* @cs_substr(i8* %0, i32 %22, i32 %24)
br label %33
26: ; preds = %15
%27 = load i32, i32* @REG_NOMATCH
%28 = icmp eq i32 %18, %27
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = call i32 @regerror(i32 %18, i32* %2, i8* %6, i32 %4)
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %33
33: ; preds = %26, %20, %29
%34 = phi i8* [ %25, %20 ], [ null, %26 ], [ null, %29 ]
%35 = call i32 @regfree(i32* %2)
br label %36
36: ; preds = %33, %11
%37 = phi i8* [ null, %11 ], [ %34, %33 ]
ret i8* %37
}