#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 strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
void strip_directory(char *inbuf, char *outbuf, int maxlen) {
  char *strippt;
  int cpylen;
  strippt = strrchr(inbuf, '/');
  if (strippt == NULL) {
    cpylen = strlen(inbuf);
    strippt = inbuf;
  } else {
    strippt++;
    cpylen = strlen(strippt);
  }
  if (cpylen > maxlen - 1)
    cpylen = maxlen - 1;
  strncpy(outbuf, strippt, cpylen);
  outbuf[cpylen] = 0;
}


x86 assembly (clang, -O0):
<strip_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1179 <strip_directory+0x49>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1191 <strip_directory+0x61>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    11ab <strip_directory+0x7b>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_directory>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1164 <strip_directory+0x34>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%r12
jmp    116c <strip_directory+0x3c>
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    -0x1(%r15),%ebx
cmp    %r15d,%eax
cmovl  %eax,%ebx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @strip_directory(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i8* @strrchr(i8* %9, i8 signext 47)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %8
%16 = load i8*, i8** %4
store i8* %16, i8** %7
br label %22
17: ; preds = %3
%18 = load i8*, i8** %7
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %8
br label %22
22: ; preds = %17, %13
%23 = load i32, i32* %8
%24 = load i32, i32* %6
%25 = sub nsw i32 %24, 1
%26 = icmp sgt i32 %23, %25
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* %6
%29 = sub nsw i32 %28, 1
store i32 %29, i32* %8
br label %30
30: ; preds = %27, %22
%31 = load i8*, i8** %5
%32 = load i8*, i8** %7
%33 = load i32, i32* %8
%34 = call i32 @strncpy(i8* %31, i8* %32, i32 %33)
%35 = load i8*, i8** %5
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
ret void
}

LLVM IR (-O2):
define void @strip_directory(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %0)
br label %11
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %4, i64 1
%10 = tail call i32 @strlen(i8* %9)
br label %11
11: ; preds = %8, %6
%12 = phi i8* [ %0, %6 ], [ %9, %8 ]
%13 = phi i32 [ %7, %6 ], [ %10, %8 ]
%14 = icmp slt i32 %13, %2
%15 = add nsw i32 %2, -1
%16 = select i1 %14, i32 %13, i32 %15
%17 = tail call i32 @strncpy(i8* %1, i8* %12, i32 %16)
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 0, i8* %19
ret void
}