#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 */
scalar_t__ calloc(unsigned int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(char *, char *);
unsigned int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, unsigned int);
char *strrchr(char *, char);
void split_path_file(char *input, char **path, char **file) {
  char *sptr = NULL, stmp[200];
  unsigned int len, pathlen = 0, filelen = 0;
  len = strlen(input);
  sptr = strrchr(input, '/');
  if (sptr == NULL) {
    getcwd(stmp, 200);
    if (stmp == NULL) {
      printf("\nCurrent directory name is too long.\n");
      printf("Exiting\n\n");
      exit(1);
    }
    pathlen = strlen(stmp);
    *path = (char *)calloc(pathlen + 1, sizeof(char));
    *file = (char *)calloc(len + 1, sizeof(char));
    strcpy(*path, stmp);
    strncpy(*file, input, len);
  } else {
    pathlen = sptr - input;
    filelen = len - pathlen - 1;
    *path = (char *)calloc(pathlen + 1, sizeof(char));
    *file = (char *)calloc(filelen + 1, sizeof(char));
    strncpy(*path, input, pathlen);
    strncpy(*file, sptr + 1, filelen);
  }
}


x86 assembly (clang, -O0):
<split_path_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0xf8(%rbp)
movl   $0x0,-0xfc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xf4(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    124a <split_path_file+0xea>
lea    -0xf0(%rbp),%rdi
mov    $0xc8,%esi
call   1070 <getcwd@plt>
lea    -0xf0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xf8(%rbp)
mov    -0xf8(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0xf4(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0xf0(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xf4(%rbp),%edx
call   1030 <strncpy@plt>
jmp    12da <split_path_file+0x17a>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0xf8(%rbp)
mov    -0xf4(%rbp),%eax
sub    -0xf8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xfc(%rbp)
mov    -0xf8(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0xfc(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xf8(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0xfc(%rbp),%edx
call   1030 <strncpy@plt>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_path_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1050 <strlen@plt>
mov    %eax,%r13d
mov    %r12,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     11f8 <split_path_file+0x98>
mov    %rax,%rbx
mov    %ebx,%ebp
sub    %r12d,%ebp
sub    %ebp,%r13d
lea    -0x1(%r13),%eax
mov    %eax,0xc(%rsp)
lea    0x1(%rbp),%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,(%r15)
mov    %r13d,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,(%r14)
mov    (%r15),%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    (%r14),%rdi
add    $0x1,%rbx
mov    %rbx,%rsi
mov    0xc(%rsp),%edx
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strncpy@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc8,%esi
call   1070 <getcwd@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,(%r15)
mov    %r13d,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,(%r14)
mov    (%r15),%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    (%r14),%rdi
mov    %r12,%rsi
mov    %r13d,%edx
call   1030 <strncpy@plt>
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @split_path_file(i8* %0, i8** nocapture %1, i8** nocapture %2) {
%4 = alloca [200 x i8]
%5 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %22
9: ; preds = %3
%10 = call i32 @getcwd(i8* %5, i32 200)
%11 = call i32 @strlen(i8* %5)
%12 = add i32 %11, 1
%13 = call i64 @calloc(i32 %12, i32 1)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %1
%15 = add i32 %6, 1
%16 = call i64 @calloc(i32 %15, i32 1)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %2
%18 = load i8*, i8** %1
%19 = call i32 @strcpy(i8* %18, i8* %5)
%20 = load i8*, i8** %2
%21 = call i32 @strncpy(i8* %20, i8* %0, i32 %6)
br label %39
22: ; preds = %3
%23 = ptrtoint i8* %7 to i64
%24 = ptrtoint i8* %0 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
%27 = sub i32 %6, %26
%28 = add i32 %27, -1
%29 = add i32 %26, 1
%30 = tail call i64 @calloc(i32 %29, i32 1)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %1
%32 = tail call i64 @calloc(i32 %27, i32 1)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %2
%34 = load i8*, i8** %1
%35 = tail call i32 @strncpy(i8* %34, i8* %0, i32 %26)
%36 = load i8*, i8** %2
%37 = getelementptr inbounds i8, i8* %7, i64 1
%38 = tail call i32 @strncpy(i8* %36, i8* %37, i32 %28)
br label %39
39: ; preds = %22, %9
ret void
}