#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 *base_name(char *);
char *dir_name(char const *);
int /*<<< orphan*/ free(char *);
char *parent_parent_base_name(const char *path) {
  char *dir;
  char *parent_dir;
  char *parent_base;
  dir = dir_name(path);
  if (!dir)
    return NULL;
  parent_dir = dir_name(dir);
  if (!parent_dir)
    return NULL;
  parent_base = base_name(parent_dir);
  free(parent_dir);
  free(dir);
  return parent_base;
}


x86 assembly (clang, -O0):
<parent_parent_base_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <dir_name@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1161 <parent_parent_base_name+0x31>
movq   $0x0,-0x8(%rbp)
jmp    11ad <parent_parent_base_name+0x7d>
mov    -0x18(%rbp),%rdi
call   1040 <dir_name@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1186 <parent_parent_base_name+0x56>
movq   $0x0,-0x8(%rbp)
jmp    11ad <parent_parent_base_name+0x7d>
mov    -0x20(%rbp),%rdi
call   1050 <base_name@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parent_parent_base_name>:
push   %r15
push   %r14
push   %rbx
call   1040 <dir_name@plt>
test   %rax,%rax
je     1172 <parent_parent_base_name+0x42>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <dir_name@plt>
test   %rax,%rax
je     1172 <parent_parent_base_name+0x42>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <base_name@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rax
jmp    1174 <parent_parent_base_name+0x44>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @parent_parent_base_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @dir_name(i8* %7)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store i8* null, i8** %2
br label %26
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = call i8* @dir_name(i8* %13)
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %12
store i8* null, i8** %2
br label %26
18: ; preds = %12
%19 = load i8*, i8** %5
%20 = call i8* @base_name(i8* %19)
store i8* %20, i8** %6
%21 = load i8*, i8** %5
%22 = call i32 @free(i8* %21)
%23 = load i8*, i8** %4
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %6
store i8* %25, i8** %2
br label %26
26: ; preds = %18, %17, %11
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
define i8* @parent_parent_base_name(i8* %0) {
%2 = tail call i8* @dir_name(i8* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = tail call i8* @dir_name(i8* %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = tail call i8* @base_name(i8* %5)
%9 = tail call i32 @free(i8* %5)
%10 = tail call i32 @free(i8* %2)
br label %11
11: ; preds = %4, %1, %7
%12 = phi i8* [ %8, %7 ], [ null, %1 ], [ null, %4 ]
ret i8* %12
}