#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*/ strcpy(char *, char *);
int strlen(char *);
void get_path(char *full_file_name, char *result) {
  int last_slash = -1, i;
  for (i = 0; i < strlen(full_file_name); i++)
    if (full_file_name[i] == '/')
      last_slash = i;
  if (last_slash == -1)
    strcpy(result, "./");
  else {
    strcpy(result, full_file_name);
    result[last_slash + 1] = '\0';
  }
}


x86 assembly (clang, -O0):
<get_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    1188 <get_path+0x68>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1175 <get_path+0x55>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    117a <get_path+0x5a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113e <get_path+0x1e>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11a7 <get_path+0x87>
mov    -0x10(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11c5 <get_path+0xa5>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_path>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
test   %eax,%eax
jle    117f <get_path+0x5f>
mov    $0xffffffff,%ebp
xor    %ebx,%ebx
nopl   (%rax)
cmpb   $0x2f,(%r15,%rbx,1)
cmove  %ebx,%ebp
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1140 <get_path+0x20>
cmp    $0xffffffff,%ebp
je     117f <get_path+0x5f>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
movslq %ebp,%rax
movb   $0x0,0x1(%rax,%r14,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe7a(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"./\00"
define void @get_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 -1, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %23, %2
%8 = load i32, i32* %6
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %26
12: ; preds = %7
%13 = load i8*, i8** %3
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 47
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = load i32, i32* %6
store i32 %21, i32* %5
br label %22
22: ; preds = %20, %12
br label %23
23: ; preds = %22
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %7
26: ; preds = %7
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i8*, i8** %4
%31 = call i32 @strcpy(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %41
32: ; preds = %26
%33 = load i8*, i8** %4
%34 = load i8*, i8** %3
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = load i8*, i8** %4
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
store i8 0, i8* %40
br label %41
41: ; preds = %32, %29
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"./\00"
define void @get_path(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %19
5: ; preds = %2, %5
%6 = phi i64 [ %13, %5 ], [ 0, %2 ]
%7 = phi i32 [ %12, %5 ], [ -1, %2 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %6
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 47
%11 = trunc i64 %6 to i32
%12 = select i1 %10, i32 %11, i32 %7
%13 = add nuw nsw i64 %6, 1
%14 = tail call i32 @strlen(i8* %0)
%15 = sext i32 %14 to i64
%16 = icmp slt i64 %13, %15
br i1 %16, label %5, label %17
17: ; preds = %5
%18 = icmp eq i32 %12, -1
br i1 %18, label %19, label %21
19: ; preds = %2, %17
%20 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %26
21: ; preds = %17
%22 = tail call i32 @strcpy(i8* %1, i8* %0)
%23 = add nuw nsw i32 %12, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %1, i64 %24
store i8 0, i8* %25
br label %26
26: ; preds = %21, %19
ret void
}