#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*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ stderr;
int strlen(char const *);
int path_extract(const char *full_path, char **base_file_name,
                 char **extension) {
  int allocation_size, full_path_length, base_file_name_length,
      extension_length, index, period_position = -1, slash_position = -1;
  if (full_path == NULL)
    return 1;
  full_path_length = strlen(full_path);
  index = full_path_length;
  while (index > 0) {
    if (full_path[index] == '/') {
      index = full_path_length;
      break;
    }
    if (full_path[index] == '.')
      break;
    index--;
  }
  if ((extension_length = full_path_length - index) > 0)
    period_position = index;
  if (period_position == -1) {
    if (extension != NULL)
      *extension = NULL;
    period_position = index;
  } else {
    if (extension != NULL) {
      allocation_size = extension_length + 1;
      if ((*extension = (char *)malloc(allocation_size)) == NULL) {
        fprintf(stderr, "BCA: malloc(%d) failed\n", allocation_size);
        return 1;
      }
      memcpy(*extension, full_path + period_position, extension_length);
      (*extension)[extension_length] = 0;
    }
  }
  index = period_position;
  while (index > 0) {
    if (full_path[index] == '/') {
      slash_position = index;
      break;
    }
    index--;
  }
  base_file_name_length = period_position - (slash_position + 1);
  if (base_file_name != NULL) {
    allocation_size = base_file_name_length + 1;
    if ((*base_file_name = (char *)malloc(allocation_size)) == NULL) {
      fprintf(stderr, "BCA: malloc(%d) failed\n", allocation_size);
      return 1;
    }
    memcpy(*base_file_name, full_path + slash_position + 1,
           base_file_name_length);
    (*base_file_name)[base_file_name_length] = 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<path_extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0xffffffff,-0x38(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1179 <path_extract+0x39>
movl   $0x1,-0x4(%rbp)
jmp    1370 <path_extract+0x230>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jle    11dd <path_extract+0x9d>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11b5 <path_extract+0x75>
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    11dd <path_extract+0x9d>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11cf <path_extract+0x8f>
jmp    11dd <path_extract+0x9d>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    118b <path_extract+0x4b>
mov    -0x28(%rbp),%eax
sub    -0x34(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jle    11f5 <path_extract+0xb5>
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    1220 <path_extract+0xe0>
cmpq   $0x0,-0x20(%rbp)
je     1215 <path_extract+0xd5>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    129f <path_extract+0x15f>
cmpq   $0x0,-0x20(%rbp)
je     129a <path_extract+0x15a>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <malloc@plt>
mov    -0x20(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    1271 <path_extract+0x131>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xda0(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1370 <path_extract+0x230>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x38(%rbp),%rax
add    %rax,%rsi
mov    -0x30(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    129f <path_extract+0x15f>
mov    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jle    12dd <path_extract+0x19d>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    12cf <path_extract+0x18f>
mov    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    12dd <path_extract+0x19d>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    12a5 <path_extract+0x165>
mov    -0x38(%rbp),%eax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
sub    %ecx,%eax
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1369 <path_extract+0x229>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <malloc@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    133c <path_extract+0x1fc>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xcd5(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1370 <path_extract+0x230>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x3c(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
mov    -0x2c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_extract>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%r15d
test   %rdi,%rdi
je     129f <path_extract+0x15f>
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r13d
test   %eax,%eax
jle    119d <path_extract+0x5d>
mov    %r13d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx,%rbp,1),%eax
cmp    $0x2e,%al
je     11a0 <path_extract+0x60>
cmp    $0x2f,%al
je     119d <path_extract+0x5d>
lea    -0x1(%rbp),%rax
cmp    $0x1,%rbp
mov    %rax,%rbp
jg     1180 <path_extract+0x40>
xor    %ebp,%ebp
jmp    11a0 <path_extract+0x60>
mov    %r13d,%ebp
cmp    $0xffffffff,%ebp
je     11ea <path_extract+0xaa>
sub    %ebp,%r13d
test   %r13d,%r13d
jle    11ea <path_extract+0xaa>
test   %r12,%r12
je     11f7 <path_extract+0xb7>
lea    0x1(%r13),%edi
mov    %edi,0x4(%rsp)
call   1060 <malloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     1286 <path_extract+0x146>
movslq %ebp,%rsi
add    %rbx,%rsi
mov    %rax,%rdi
mov    %r13d,%edx
call   1050 <memcpy@plt>
mov    (%r12),%rax
mov    %r13d,%ecx
movb   $0x0,(%rax,%rcx,1)
jmp    11f7 <path_extract+0xb7>
test   %r12,%r12
je     11f7 <path_extract+0xb7>
movq   $0x0,(%r12)
mov    $0xffffffff,%r13d
test   %ebp,%ebp
jle    1222 <path_extract+0xe2>
mov    %ebp,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%ecx
cmpb   $0x2f,(%rbx,%rcx,1)
je     1229 <path_extract+0xe9>
lea    -0x1(%rax),%ecx
cmp    $0x1,%eax
mov    %ecx,%eax
jg     1210 <path_extract+0xd0>
test   %r14,%r14
jne    1231 <path_extract+0xf1>
jmp    126c <path_extract+0x12c>
mov    %eax,%r13d
test   %r14,%r14
je     126c <path_extract+0x12c>
mov    %ebp,%r12d
sub    %r13d,%r12d
mov    %r12d,%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1271 <path_extract+0x131>
movslq %r13d,%rcx
not    %r13d
add    %r13d,%ebp
lea    (%rbx,%rcx,1),%rsi
add    $0x1,%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1050 <memcpy@plt>
mov    (%r14),%rax
movslq %ebp,%rcx
movb   $0x0,(%rax,%rcx,1)
xor    %r15d,%r15d
jmp    129f <path_extract+0x15f>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xd7f(%rip),%rsi
mov    %r12d,%edx
jmp    129a <path_extract+0x15a>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
mov    0x4(%rsp),%edx
call   1040 <fprintf@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"BCA: malloc(%d) failed\0A\00"
define i32 @path_extract(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 -1, i32* %13
store i32 -1, i32* %14
%15 = load i8*, i8** %5
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 1, i32* %4
br label %147
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %9
%21 = load i32, i32* %9
store i32 %21, i32* %12
br label %22
22: ; preds = %44, %18
%23 = load i32, i32* %12
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %47
25: ; preds = %22
%26 = load i8*, i8** %5
%27 = load i32, i32* %12
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 47
br i1 %32, label %33, label %35
33: ; preds = %25
%34 = load i32, i32* %9
store i32 %34, i32* %12
br label %47
35: ; preds = %25
%36 = load i8*, i8** %5
%37 = load i32, i32* %12
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 46
br i1 %42, label %43, label %44
43: ; preds = %35
br label %47
44: ; preds = %35
%45 = load i32, i32* %12
%46 = add nsw i32 %45, -1
store i32 %46, i32* %12
br label %22
47: ; preds = %43, %33, %22
%48 = load i32, i32* %9
%49 = load i32, i32* %12
%50 = sub nsw i32 %48, %49
store i32 %50, i32* %11
%51 = icmp sgt i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = load i32, i32* %12
store i32 %53, i32* %13
br label %54
54: ; preds = %52, %47
%55 = load i32, i32* %13
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %64
57: ; preds = %54
%58 = load i8**, i8*** %7
%59 = icmp ne i8** %58, null
br i1 %59, label %60, label %62
60: ; preds = %57
%61 = load i8**, i8*** %7
store i8* null, i8** %61
br label %62
62: ; preds = %60, %57
%63 = load i32, i32* %12
store i32 %63, i32* %13
br label %94
64: ; preds = %54
%65 = load i8**, i8*** %7
%66 = icmp ne i8** %65, null
br i1 %66, label %67, label %93
67: ; preds = %64
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 1
store i32 %69, i32* %8
%70 = load i32, i32* %8
%71 = call i64 @malloc(i32 %70)
%72 = inttoptr i64 %71 to i8*
%73 = load i8**, i8*** %7
store i8* %72, i8** %73
%74 = icmp eq i8* %72, null
br i1 %74, label %75, label %79
75: ; preds = %67
%76 = load i32, i32* @stderr
%77 = load i32, i32* %8
%78 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %77)
store i32 1, i32* %4
br label %147
79: ; preds = %67
%80 = load i8**, i8*** %7
%81 = load i8*, i8** %80
%82 = load i8*, i8** %5
%83 = load i32, i32* %13
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %82, i64 %84
%86 = load i32, i32* %11
%87 = call i32 @memcpy(i8* %81, i8* %85, i32 %86)
%88 = load i8**, i8*** %7
%89 = load i8*, i8** %88
%90 = load i32, i32* %11
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i8, i8* %89, i64 %91
store i8 0, i8* %92
br label %93
93: ; preds = %79, %64
br label %94
94: ; preds = %93, %62
%95 = load i32, i32* %13
store i32 %95, i32* %12
br label %96
96: ; preds = %109, %94
%97 = load i32, i32* %12
%98 = icmp sgt i32 %97, 0
br i1 %98, label %99, label %112
99: ; preds = %96
%100 = load i8*, i8** %5
%101 = load i32, i32* %12
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i8, i8* %100, i64 %102
%104 = load i8, i8* %103
%105 = sext i8 %104 to i32
%106 = icmp eq i32 %105, 47
br i1 %106, label %107, label %109
107: ; preds = %99
%108 = load i32, i32* %12
store i32 %108, i32* %14
br label %112
109: ; preds = %99
%110 = load i32, i32* %12
%111 = add nsw i32 %110, -1
store i32 %111, i32* %12
br label %96
112: ; preds = %107, %96
%113 = load i32, i32* %13
%114 = load i32, i32* %14
%115 = add nsw i32 %114, 1
%116 = sub nsw i32 %113, %115
store i32 %116, i32* %10
%117 = load i8**, i8*** %6
%118 = icmp ne i8** %117, null
br i1 %118, label %119, label %146
119: ; preds = %112
%120 = load i32, i32* %10
%121 = add nsw i32 %120, 1
store i32 %121, i32* %8
%122 = load i32, i32* %8
%123 = call i64 @malloc(i32 %122)
%124 = inttoptr i64 %123 to i8*
%125 = load i8**, i8*** %6
store i8* %124, i8** %125
%126 = icmp eq i8* %124, null
br i1 %126, label %127, label %131
127: ; preds = %119
%128 = load i32, i32* @stderr
%129 = load i32, i32* %8
%130 = call i32 @fprintf(i32 %128, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %129)
store i32 1, i32* %4
br label %147
131: ; preds = %119
%132 = load i8**, i8*** %6
%133 = load i8*, i8** %132
%134 = load i8*, i8** %5
%135 = load i32, i32* %14
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds i8, i8* %134, i64 %136
%138 = getelementptr inbounds i8, i8* %137, i64 1
%139 = load i32, i32* %10
%140 = call i32 @memcpy(i8* %133, i8* %138, i32 %139)
%141 = load i8**, i8*** %6
%142 = load i8*, i8** %141
%143 = load i32, i32* %10
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds i8, i8* %142, i64 %144
store i8 0, i8* %145
br label %146
146: ; preds = %131, %112
store i32 0, i32* %4
br label %147
147: ; preds = %146, %127, %75, %17
%148 = load i32, i32* %4
ret i32 %148
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"BCA: malloc(%d) failed\0A\00"
define i32 @path_extract(i8* %0, i8** %1, i8** %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %76, label %5
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %19
8: ; preds = %5
%9 = zext i32 %6 to i64
br label %10
10: ; preds = %8, %14
%11 = phi i64 [ %9, %8 ], [ %15, %14 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
switch i8 %13, label %14 [
i8 47, label %19
i8 46, label %17
]
14: ; preds = %10
%15 = add nsw i64 %11, -1
%16 = icmp sgt i64 %11, 1
br i1 %16, label %10, label %19
17: ; preds = %10
%18 = trunc i64 %11 to i32
br label %19
19: ; preds = %14, %10, %5, %17
%20 = phi i32 [ %18, %17 ], [ %6, %5 ], [ 0, %14 ], [ %6, %10 ]
%21 = sub nsw i32 %6, %20
%22 = icmp slt i32 %21, 1
%23 = icmp eq i32 %20, -1
%24 = or i1 %23, %22
%25 = icmp eq i8** %2, null
br i1 %24, label %26, label %28
26: ; preds = %19
br i1 %25, label %44, label %27
27: ; preds = %26
store i8* null, i8** %2
br label %44
28: ; preds = %19
br i1 %25, label %44, label %29
29: ; preds = %28
%30 = add nuw nsw i32 %21, 1
%31 = tail call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %2
%33 = icmp eq i64 %31, 0
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %30)
br label %76
37: ; preds = %29
%38 = sext i32 %20 to i64
%39 = getelementptr inbounds i8, i8* %0, i64 %38
%40 = tail call i32 @memcpy(i8* %32, i8* %39, i32 %21)
%41 = load i8*, i8** %2
%42 = zext i32 %21 to i64
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8 0, i8* %43
br label %44
44: ; preds = %26, %27, %28, %37
%45 = icmp sgt i32 %20, 0
br i1 %45, label %46, label %55
46: ; preds = %44, %52
%47 = phi i32 [ %53, %52 ], [ %20, %44 ]
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %0, i64 %48
%50 = load i8, i8* %49
%51 = icmp eq i8 %50, 47
br i1 %51, label %55, label %52
52: ; preds = %46
%53 = add nsw i32 %47, -1
%54 = icmp sgt i32 %47, 1
br i1 %54, label %46, label %55
55: ; preds = %52, %46, %44
%56 = phi i32 [ -1, %44 ], [ %47, %46 ], [ -1, %52 ]
%57 = xor i32 %56, -1
%58 = add i32 %20, %57
%59 = icmp eq i8** %1, null
br i1 %59, label %76, label %60
60: ; preds = %55
%61 = sub i32 %20, %56
%62 = tail call i64 @malloc(i32 %61)
%63 = inttoptr i64 %62 to i8*
store i8* %63, i8** %1
%64 = icmp eq i64 %62, 0
br i1 %64, label %65, label %68
65: ; preds = %60
%66 = load i32, i32* @stderr
%67 = tail call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %61)
br label %76
68: ; preds = %60
%69 = sext i32 %56 to i64
%70 = getelementptr inbounds i8, i8* %0, i64 %69
%71 = getelementptr inbounds i8, i8* %70, i64 1
%72 = tail call i32 @memcpy(i8* %63, i8* %71, i32 %58)
%73 = load i8*, i8** %1
%74 = sext i32 %58 to i64
%75 = getelementptr inbounds i8, i8* %73, i64 %74
store i8 0, i8* %75
br label %76
76: ; preds = %55, %68, %3, %65, %34
%77 = phi i32 [ 1, %65 ], [ 1, %34 ], [ 1, %3 ], [ 0, %68 ], [ 0, %55 ]
ret i32 %77
}