#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 rm_so;
  int rm_eo;
};
typedef TYPE_1__ regmatch_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int REG_EXTENDED;
int REG_NEWLINE;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_result(char *);
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ regexec(int /*<<< orphan*/ *, char *, int, TYPE_1__ *,
                           int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, int);
int file_name(char *name) {
  char *patten = "(.*/)?(.*)\\.hq9fp";
  char *source;
  regex_t pt;
  if (regcomp(&pt, patten, REG_EXTENDED | REG_NEWLINE)) {
    perror("regex compile failed");
    exit(1);
  }
  regmatch_t patternMatch[3];
  if (!(regexec(&pt, name, 3, patternMatch, 0))) {
    int start, end, len;
    start = patternMatch[2].rm_so;
    end = patternMatch[2].rm_eo;
    len = end - start;
    source = (char *)malloc((len + 1) * sizeof(char));
    if (source == NULL) {
      perror("malloc");
      exit(1);
    }
    strncpy(source, name + start, len);
    print_result(source);
    free(source);
  }
  return (0);
}


x86 assembly (clang, -O0):
<file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe6d(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
mov    0x2e3d(%rip),%rax
or     (%rax),%edx
lea    -0x1c(%rbp),%rdi
call   1060 <regcomp@plt>
cmp    $0x0,%rax
je     11d6 <file_name+0x56>
lea    0xe4b(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rsi
lea    -0x40(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x3,%edx
xor    %r8d,%r8d
call   1080 <regexec@plt>
cmp    $0x0,%eax
jne    126e <file_name+0xee>
mov    -0x30(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
sub    -0x44(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1245 <file_name+0xc5>
lea    0xdf1(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x44(%rbp),%rax
add    %rax,%rsi
mov    -0x4c(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x18(%rbp),%rdi
call   1050 <print_result@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
mov    0x2e43(%rip),%rax
mov    0x2e4c(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe59(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1060 <regcomp@plt>
test   %rax,%rax
jne    1221 <file_name+0xa1>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rcx
mov    %r14,%rsi
mov    $0x3,%edx
xor    %r8d,%r8d
call   1080 <regexec@plt>
test   %eax,%eax
jne    1213 <file_name+0x93>
movslq 0x20(%rsp),%r12
mov    0x24(%rsp),%r15d
sub    %r12d,%r15d
lea    0x1(%r15),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     122a <file_name+0xaa>
mov    %rax,%rbx
add    %r12,%r14
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <strncpy@plt>
mov    %rbx,%rdi
call   1050 <print_result@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdea(%rip),%rdi
jmp    1231 <file_name+0xb1>
lea    0xdf6(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [18 x i8] c"(.*/)?(.*)\\.hq9fp\00"
@REG_EXTENDED = global i32 0
@REG_NEWLINE = global i32 0
@.str.1 = [21 x i8] c"regex compile failed\00"
@.str.2 = [7 x i8] c"malloc\00"
define i32 @file_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [3 x %struct.TYPE_3__]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %2
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %3
%10 = load i8*, i8** %3
%11 = load i32, i32* @REG_EXTENDED
%12 = load i32, i32* @REG_NEWLINE
%13 = or i32 %11, %12
%14 = call i64 @regcomp(i32* %5, i8* %10, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %1
%20 = load i8*, i8** %2
%21 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %6, i64 0, i64 0
%22 = call i32 @regexec(i32* %5, i8* %20, i32 3, %struct.TYPE_3__* %21, i32 0)
%23 = icmp ne i32 %22, 0
br i1 %23, label %58, label %24
24: ; preds = %19
%25 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %6, i64 0, i64 2
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %25, i32 0, i32 0
%27 = load i32, i32* %26
store i32 %27, i32* %7
%28 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %6, i64 0, i64 2
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %28, i32 0, i32 1
%30 = load i32, i32* %29
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = load i32, i32* %7
%33 = sub nsw i32 %31, %32
store i32 %33, i32* %9
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = mul i64 %36, 1
%38 = trunc i64 %37 to i32
%39 = call i64 @malloc(i32 %38)
%40 = inttoptr i64 %39 to i8*
store i8* %40, i8** %4
%41 = load i8*, i8** %4
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %46
43: ; preds = %24
%44 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %24
%47 = load i8*, i8** %4
%48 = load i8*, i8** %2
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i32, i32* %9
%53 = call i32 @strncpy(i8* %47, i8* %51, i32 %52)
%54 = load i8*, i8** %4
%55 = call i32 @print_result(i8* %54)
%56 = load i8*, i8** %4
%57 = call i32 @free(i8* %56)
br label %58
58: ; preds = %46, %19
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [18 x i8] c"(.*/)?(.*)\\.hq9fp\00"
@REG_EXTENDED = global i32 0
@REG_NEWLINE = global i32 0
@.str.1 = [21 x i8] c"regex compile failed\00"
@.str.2 = [7 x i8] c"malloc\00"
define i32 @file_name(i8* %0) {
%2 = alloca i32
%3 = alloca [3 x %struct.TYPE_3__]
%4 = bitcast i32* %2 to i8*
%5 = load i32, i32* @REG_EXTENDED
%6 = load i32, i32* @REG_NEWLINE
%7 = or i32 %6, %5
%8 = call i64 @regcomp(i32* %2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = bitcast [3 x %struct.TYPE_3__]* %3 to i8*
%15 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %3, i64 0, i64 0
%16 = call i32 @regexec(i32* %2, i8* %0, i32 3, %struct.TYPE_3__* %15, i32 0)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %37
18: ; preds = %13
%19 = getelementptr inbounds [3 x %struct.TYPE_3__], [3 x %struct.TYPE_3__]* %3, i64 0, i64 2, i32 0
%20 = load i32, i32* %19
%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 = sub nsw i32 %22, %20
%24 = add nsw i32 %23, 1
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
%27 = icmp eq i64 %25, 0
br i1 %27, label %28, label %31
28: ; preds = %18
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %18
%32 = sext i32 %20 to i64
%33 = getelementptr inbounds i8, i8* %0, i64 %32
%34 = call i32 @strncpy(i8* %26, i8* %33, i32 %23)
%35 = call i32 @print_result(i8* %26)
%36 = call i32 @free(i8* %26)
br label %37
37: ; preds = %31, %13
ret i32 0
}