#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 *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
void last_part(char *pathname, char *lastpart) {
  char *p = pathname;
  char *p2 = strchr(p, '/');
  if (p2 == NULL) {
    strcpy(lastpart, pathname);
    return;
  }
  while (p2 != NULL) {
    p = p2 + 1;
    p2 = strchr(p, '/');
  }
  strcpy(lastpart, p);
  return;
}


x86 assembly (clang, -O0):
<last_part>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1167 <last_part+0x47>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11a7 <last_part+0x87>
jmp    116c <last_part+0x4c>
cmpq   $0x0,-0x20(%rbp)
je     119a <last_part+0x7a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
jmp    116c <last_part+0x4c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<last_part>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     114b <last_part+0x2b>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
jmp    1130 <last_part+0x10>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
define void @last_part(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = call i8* @strchr(i8* %8, i8 signext 47)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load i8*, i8** %3
%15 = call i32 @strcpy(i8* %13, i8* %14)
br label %29
16: ; preds = %2
br label %17
17: ; preds = %20, %16
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %22, i8** %5
%23 = load i8*, i8** %5
%24 = call i8* @strchr(i8* %23, i8 signext 47)
store i8* %24, i8** %6
br label %17
25: ; preds = %17
%26 = load i8*, i8** %4
%27 = load i8*, i8** %5
%28 = call i32 @strcpy(i8* %26, i8* %27)
br label %29
29: ; preds = %25, %12
ret void
}

LLVM IR (-O2):
define void @last_part(i8* %0, i8* %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @strcpy(i8* %1, i8* %0)
br label %14
7: ; preds = %2, %7
%8 = phi i8* [ %10, %7 ], [ %3, %2 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = tail call i8* @strchr(i8* %9, i8 signext 47)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %7
12: ; preds = %7
%13 = tail call i32 @strcpy(i8* %1, i8* %9)
br label %14
14: ; preds = %12, %5
ret void
}