#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*/ die(char *, char const *, char const *);
int /*<<< orphan*/ streq(char const *, char *);
int strlen(char const *);
int /*<<< orphan*/ strneq(char const *, char const *, int);
char *xstrdup(char const *);
char *nodename_from_path(const char *ppath, const char *cpath) {
  int plen;
  plen = strlen(ppath);
  if (!strneq(ppath, cpath, plen))
    die("Path \"%s\" is not valid as a child of \"%s\"\n", cpath, ppath);
  if (!streq(ppath, "/"))
    plen++;
  return xstrdup(cpath + plen);
}


x86 assembly (clang, -O0):
<nodename_from_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <strneq@plt>
cmp    $0x0,%eax
jne    1199 <nodename_from_path+0x49>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe6c(%rip),%rdi
call   1070 <die@plt>
mov    -0x8(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1050 <streq@plt>
cmp    $0x0,%eax
jne    11bb <nodename_from_path+0x6b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
call   1040 <xstrdup@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nodename_from_path>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <strneq@plt>
test   %eax,%eax
jne    1184 <nodename_from_path+0x34>
lea    0xe87(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1070 <die@plt>
lea    0xea0(%rip),%rsi
mov    %rbx,%rdi
call   1050 <streq@plt>
cmp    $0x1,%eax
adc    $0x0,%ebp
movslq %ebp,%rax
add    %rax,%r14
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <xstrdup@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"Path \22%s\22 is not valid as a child of \22%s\22\0A\00"
@.str.1 = [2 x i8] c"/\00"
define i8* @nodename_from_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = load i8*, i8** %3
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = call i32 @strneq(i8* %8, i8* %9, i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load i8*, i8** %3
%16 = call i32 @die(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15)
br label %17
17: ; preds = %13, %2
%18 = load i8*, i8** %3
%19 = call i32 @streq(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %24
24: ; preds = %21, %17
%25 = load i8*, i8** %4
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = call i8* @xstrdup(i8* %28)
ret i8* %29
}

LLVM IR (-O2):
@.str = [43 x i8] c"Path \22%s\22 is not valid as a child of \22%s\22\0A\00"
@.str.1 = [2 x i8] c"/\00"
define i8* @nodename_from_path(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strneq(i8* %0, i8* %1, i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @die(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %0)
br label %8
8: ; preds = %6, %2
%9 = tail call i32 @streq(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
%11 = zext i1 %10 to i32
%12 = add nsw i32 %3, %11
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %1, i64 %13
%15 = tail call i8* @xstrdup(i8* %14)
ret i8* %15
}