#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*/ add_to_string(char *, char *);
int /*<<< orphan*/ initialize_string(char *);
int /*<<< orphan*/ last_char_pos(int *, char *, int);
int /*<<< orphan*/ substr(char *, char *, int);
void base_path(char *variable, char *full_path) {
  int index;
  int needle = '/';
  last_char_pos(&index, full_path, needle);
  if (index == 0) {
    initialize_string(variable);
    add_to_string(variable, full_path);
  } else {
    substr(variable, full_path, index + 1);
  }
}


x86 assembly (clang, -O0):
<base_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2f,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    -0x14(%rbp),%rdi
call   1040 <last_char_pos@plt>
cmpl   $0x0,-0x14(%rbp)
jne    118c <base_path+0x4c>
mov    -0x8(%rbp),%rdi
call   1060 <initialize_string@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <add_to_string@plt>
jmp    119f <base_path+0x5f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
call   1030 <substr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base_path>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x4(%rsp),%rdi
mov    $0x2f,%edx
call   1040 <last_char_pos@plt>
mov    0x4(%rsp),%edx
test   %edx,%edx
je     1171 <base_path+0x31>
add    $0x1,%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <substr@plt>
jmp    1184 <base_path+0x44>
mov    %r14,%rdi
call   1060 <initialize_string@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <add_to_string@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @base_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 47, i32* %6
%7 = load i8*, i8** %4
%8 = load i32, i32* %6
%9 = call i32 @last_char_pos(i32* %5, i8* %7, i32 %8)
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @initialize_string(i8* %13)
%15 = load i8*, i8** %3
%16 = load i8*, i8** %4
%17 = call i32 @add_to_string(i8* %15, i8* %16)
br label %24
18: ; preds = %2
%19 = load i8*, i8** %3
%20 = load i8*, i8** %4
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
%23 = call i32 @substr(i8* %19, i8* %20, i32 %22)
br label %24
24: ; preds = %18, %12
ret void
}

LLVM IR (-O2):
define void @base_path(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @last_char_pos(i32* %3, i8* %1, i32 47)
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = call i32 @initialize_string(i8* %0)
%10 = call i32 @add_to_string(i8* %0, i8* %1)
br label %14
11: ; preds = %2
%12 = add nsw i32 %6, 1
%13 = call i32 @substr(i8* %0, i8* %1, i32 %12)
br label %14
14: ; preds = %11, %8
ret void
}