#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 *filename_parameter(char *, int, char const *, int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *strrchr(char *, char);
char *ext_split(char *buffer, size_t buflen, const char *pattern, char c,
                int mode) {
  char Temp[260];
  char *str, *s1, *s2;
  size_t len;
  if (pattern == (char *)NULL)
    return ((char *)NULL);
  str = filename_parameter(Temp, 260, pattern, 0);
  s1 = str;
  s2 = str;
  if ((str = strrchr(str, c)) == (char *)NULL) {
    s1 = Temp;
    s2 = "";
  } else {
    *str = '\0';
    s2 = ++str;
  }
  switch (mode) {
  case 0:
    str = s1;
    break;
  case 1:
    str = s2;
    break;
  default:
    return ((char *)NULL);
  }
  len = ((buflen) < (strlen(str) + 1) ? (buflen) : (strlen(str) + 1)) - 1;
  (void)strncpy(buffer, str, len + 1);
  buffer[len] = '\0';
  return (buffer);
}


x86 assembly (clang, -O0):
<ext_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %cl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %al,-0x21(%rbp)
mov    %r8d,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1178 <ext_split+0x38>
movq   $0x0,-0x8(%rbp)
jmp    130f <ext_split+0x1cf>
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x104,%esi
xor    %ecx,%ecx
call   1060 <filename_parameter@plt>
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x138(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x138(%rbp),%rdi
movsbl -0x21(%rbp),%esi
call   1050 <strrchr@plt>
mov    %rax,-0x138(%rbp)
cmp    $0x0,%rax
jne    11f4 <ext_split+0xb4>
lea    -0x130(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    0xe18(%rip),%rax
mov    %rax,-0x148(%rbp)
jmp    1217 <ext_split+0xd7>
mov    -0x138(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
mov    %rax,-0x148(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x154(%rbp)
test   %eax,%eax
je     1241 <ext_split+0x101>
jmp    122d <ext_split+0xed>
mov    -0x154(%rbp),%eax
sub    $0x1,%eax
je     1254 <ext_split+0x114>
jmp    1267 <ext_split+0x127>
mov    -0x140(%rbp),%rax
mov    %rax,-0x138(%rbp)
jmp    1274 <ext_split+0x134>
mov    -0x148(%rbp),%rax
mov    %rax,-0x138(%rbp)
jmp    1274 <ext_split+0x134>
movq   $0x0,-0x8(%rbp)
jmp    130f <ext_split+0x1cf>
mov    -0x18(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x138(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x160(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jae    12b3 <ext_split+0x173>
mov    -0x18(%rbp),%rax
mov    %rax,-0x168(%rbp)
jmp    12cb <ext_split+0x18b>
mov    -0x138(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x168(%rbp)
mov    -0x168(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x150(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x138(%rbp),%rsi
mov    -0x150(%rbp),%rdx
add    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x150(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ext_split>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
test   %rdx,%rdx
je     11e7 <ext_split+0xa7>
mov    %r8d,%r12d
mov    %ecx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%r13
mov    %r13,%rdi
mov    $0x104,%esi
xor    %ecx,%ecx
call   1060 <filename_parameter@plt>
mov    %rax,%rbx
movsbl %bpl,%esi
mov    %rax,%rdi
call   1050 <strrchr@plt>
test   %rax,%rax
je     119c <ext_split+0x5c>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rbx,%r13
test   %r12d,%r12d
jne    11a8 <ext_split+0x68>
jmp    11b1 <ext_split+0x71>
lea    0xe5d(%rip),%rax
test   %r12d,%r12d
je     11b1 <ext_split+0x71>
cmp    $0x1,%r12d
jne    11e7 <ext_split+0xa7>
mov    %rax,%r13
mov    %r13,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
cmp    %r14,%rax
ja     11d1 <ext_split+0x91>
mov    %r13,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
movslq %eax,%r14
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1030 <strncpy@plt>
movb   $0x0,-0x1(%r14,%r15,1)
jmp    11ea <ext_split+0xaa>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @ext_split(i8* %0, i64 %1, i8* %2, i8 signext %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8
%11 = alloca i32
%12 = alloca [260 x i8]
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i64
store i8* %0, i8** %7
store i64 %1, i64* %8
store i8* %2, i8** %9
store i8 %3, i8* %10
store i32 %4, i32* %11
%17 = load i8*, i8** %9
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %5
store i8* null, i8** %6
br label %69
20: ; preds = %5
%21 = getelementptr inbounds [260 x i8], [260 x i8]* %12, i64 0, i64 0
%22 = load i8*, i8** %9
%23 = call i8* @filename_parameter(i8* %21, i32 260, i8* %22, i32 0)
store i8* %23, i8** %13
%24 = load i8*, i8** %13
store i8* %24, i8** %14
%25 = load i8*, i8** %13
store i8* %25, i8** %15
%26 = load i8*, i8** %13
%27 = load i8, i8* %10
%28 = call i8* @strrchr(i8* %26, i8 signext %27)
store i8* %28, i8** %13
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %32
30: ; preds = %20
%31 = getelementptr inbounds [260 x i8], [260 x i8]* %12, i64 0, i64 0
store i8* %31, i8** %14
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %15
br label %36
32: ; preds = %20
%33 = load i8*, i8** %13
store i8 0, i8* %33
%34 = load i8*, i8** %13
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %13
store i8* %35, i8** %15
br label %36
36: ; preds = %32, %30
%37 = load i32, i32* %11
switch i32 %37, label %42 [
i32 0, label %38
i32 1, label %40
]
38: ; preds = %36
%39 = load i8*, i8** %14
store i8* %39, i8** %13
br label %43
40: ; preds = %36
%41 = load i8*, i8** %15
store i8* %41, i8** %13
br label %43
42: ; preds = %36
store i8* null, i8** %6
br label %69
43: ; preds = %40, %38
%44 = load i64, i64* %8
%45 = load i8*, i8** %13
%46 = call i32 @strlen(i8* %45)
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = icmp ult i64 %44, %48
br i1 %49, label %50, label %52
50: ; preds = %43
%51 = load i64, i64* %8
br label %57
52: ; preds = %43
%53 = load i8*, i8** %13
%54 = call i32 @strlen(i8* %53)
%55 = add nsw i32 %54, 1
%56 = sext i32 %55 to i64
br label %57
57: ; preds = %52, %50
%58 = phi i64 [ %51, %50 ], [ %56, %52 ]
%59 = sub i64 %58, 1
store i64 %59, i64* %16
%60 = load i8*, i8** %7
%61 = load i8*, i8** %13
%62 = load i64, i64* %16
%63 = add i64 %62, 1
%64 = call i32 @strncpy(i8* %60, i8* %61, i64 %63)
%65 = load i8*, i8** %7
%66 = load i64, i64* %16
%67 = getelementptr inbounds i8, i8* %65, i64 %66
store i8 0, i8* %67
%68 = load i8*, i8** %7
store i8* %68, i8** %6
br label %69
69: ; preds = %57, %42, %19
%70 = load i8*, i8** %6
ret i8* %70
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @ext_split(i8* %0, i64 %1, i8* %2, i8 signext %3, i32 %4) {
%6 = alloca [260 x i8]
%7 = getelementptr inbounds [260 x i8], [260 x i8]* %6, i64 0, i64 0
%8 = icmp eq i8* %2, null
br i1 %8, label %34, label %9
9: ; preds = %5
%10 = call i8* @filename_parameter(i8* %7, i32 260, i8* %2, i32 0)
%11 = call i8* @strrchr(i8* dereferenceable(1) %10, i8 signext %3)
%12 = icmp eq i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %9
store i8 0, i8* %11
%14 = getelementptr inbounds i8, i8* %11, i64 1
br label %15
15: ; preds = %9, %13
%16 = phi i8* [ %10, %13 ], [ %7, %9 ]
%17 = phi i8* [ %14, %13 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %9 ]
switch i32 %4, label %34 [
i32 0, label %19
i32 1, label %18
]
18: ; preds = %15
br label %19
19: ; preds = %15, %18
%20 = phi i8* [ %17, %18 ], [ %16, %15 ]
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = icmp ugt i64 %23, %1
br i1 %24, label %29, label %25
25: ; preds = %19
%26 = call i32 @strlen(i8* %20)
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
br label %29
29: ; preds = %19, %25
%30 = phi i64 [ %28, %25 ], [ %1, %19 ]
%31 = add i64 %30, -1
%32 = call i32 @strncpy(i8* %0, i8* %20, i64 %30)
%33 = getelementptr inbounds i8, i8* %0, i64 %31
store i8 0, i8* %33
br label %34
34: ; preds = %15, %5, %29
%35 = phi i8* [ %0, %29 ], [ null, %5 ], [ null, %15 ]
ret i8* %35
}