#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 */
char *basefile(char *);
char *strdup(char *);
int strlen(char *);
char *basefile_pattern(char *path, char *pattern) {
  char *base = NULL;
  int i;
  for (i = 0; i < strlen(pattern); i++) {
    if (pattern[i] == '/' && pattern[i + 1] == '*') {
      base = strdup(path + i + 1);
      break;
    }
  }
  if (!base) {
    base = basefile(path);
  }
  return base;
}


x86 assembly (clang, -O0):
<basefile_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11ca <basefile_pattern+0x9a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11b7 <basefile_pattern+0x87>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2a,%eax
jne    11b7 <basefile_pattern+0x87>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    11ca <basefile_pattern+0x9a>
jmp    11bc <basefile_pattern+0x8c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114f <basefile_pattern+0x1f>
cmpq   $0x0,-0x18(%rbp)
jne    11e2 <basefile_pattern+0xb2>
mov    -0x8(%rbp),%rdi
call   1040 <basefile@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basefile_pattern>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    118a <basefile_pattern+0x5a>
xor    %ebx,%ebx
jmp    1163 <basefile_pattern+0x33>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    118a <basefile_pattern+0x5a>
cmpb   $0x2f,(%r15,%rbx,1)
jne    1150 <basefile_pattern+0x20>
cmpb   $0x2a,0x1(%r15,%rbx,1)
jne    1150 <basefile_pattern+0x20>
lea    (%r14,%rbx,1),%rdi
add    $0x1,%rdi
call   1050 <strdup@plt>
test   %rax,%rax
je     118a <basefile_pattern+0x5a>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <basefile@plt>

LLVM IR (-O0):
define i8* @basefile_pattern(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %5
store i32 0, i32* %6
br label %7
7: ; preds = %37, %2
%8 = load i32, i32* %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %40
12: ; preds = %7
%13 = load i8*, i8** %4
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 47
br i1 %19, label %20, label %36
20: ; preds = %12
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 42
br i1 %28, label %29, label %36
29: ; preds = %20
%30 = load i8*, i8** %3
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = call i8* @strdup(i8* %34)
store i8* %35, i8** %5
br label %40
36: ; preds = %20, %12
br label %37
37: ; preds = %36
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %7
40: ; preds = %29, %7
%41 = load i8*, i8** %5
%42 = icmp ne i8* %41, null
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = load i8*, i8** %3
%45 = call i8* @basefile(i8* %44)
store i8* %45, i8** %5
br label %46
46: ; preds = %43, %40
%47 = load i8*, i8** %5
ret i8* %47
}

LLVM IR (-O2):
define i8* @basefile_pattern(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %25
5: ; preds = %2, %15
%6 = phi i64 [ %10, %15 ], [ 0, %2 ]
%7 = getelementptr inbounds i8, i8* %1, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 47
%10 = add nuw nsw i64 %6, 1
br i1 %9, label %11, label %15
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %1, i64 %10
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 42
br i1 %14, label %19, label %15
15: ; preds = %5, %11
%16 = tail call i32 @strlen(i8* %1)
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %10, %17
br i1 %18, label %5, label %25
19: ; preds = %11
%20 = and i64 %6, 4294967295
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = tail call i8* @strdup(i8* %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %15, %2, %19
%26 = tail call i8* @basefile(i8* %0)
br label %27
27: ; preds = %25, %19
%28 = phi i8* [ %23, %19 ], [ %26, %25 ]
ret i8* %28
}