#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 */
typedef int /*<<< orphan*/ filepath;
typedef int /*<<< orphan*/ filename;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
char *getfile(char *path) {
  static char filename[1024];
  char *tmp1, *tmp2, filepath[1024];
  if (path == NULL)
    return NULL;
  memset(filepath, 0, sizeof(filepath));
  strcpy(filepath, path);
  tmp2 = tmp1 = strtok(filepath, "/");
  while ((tmp1 = strtok(NULL, "/"))) {
    tmp2 = tmp1;
  }
  memset(filename, 0, sizeof(filename));
  if (tmp2) {
    strcpy(filename, tmp2);
    tmp1 = filename;
    while (*tmp1 && *tmp1++ != ' ')
      ;
    *(tmp1) = '\0';
  } else
    return NULL;
  return filename;
}


x86 assembly (clang, -O0):
<getfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1157 <getfile+0x27>
movq   $0x0,-0x8(%rbp)
jmp    126b <getfile+0x13b>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe60(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11c0 <getfile+0x90>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1195 <getfile+0x65>
lea    0x2e89(%rip),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
cmpq   $0x0,-0x20(%rbp)
je     1253 <getfile+0x123>
mov    -0x20(%rbp),%rsi
lea    0x2e67(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2e5b(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x421(%rbp)
je     122f <getfile+0xff>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x421(%rbp)
mov    -0x421(%rbp),%al
test   $0x1,%al
jne    1242 <getfile+0x112>
jmp    1247 <getfile+0x117>
jmp    11f9 <getfile+0xc9>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1260 <getfile+0x130>
movq   $0x0,-0x8(%rbp)
jmp    126b <getfile+0x13b>
lea    0x2de9(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfile>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
test   %rdi,%rdi
je     11dd <getfile+0xad>
mov    %rdi,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe94(%rip),%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strtok@plt>
nopw   0x0(%rax,%rax,1)
mov    %rax,%rbx
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
jne    1180 <getfile+0x50>
lea    0x2eb7(%rip),%r14
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
test   %rbx,%rbx
je     11e0 <getfile+0xb0>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
nopl   0x0(%rax,%rax,1)
movzbl (%r14),%eax
test   %al,%al
je     11d0 <getfile+0xa0>
add    $0x1,%r14
cmp    $0x20,%al
jne    11c0 <getfile+0x90>
movb   $0x0,(%r14)
lea    0x2e75(%rip),%r15
jmp    11e0 <getfile+0xb0>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@getfile.filename = internal global [1024 x i8] zeroinitializer
@.str = [2 x i8] c"/\00"
define i8* @getfile(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1024 x i8]
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* null, i8** %2
br label %48
10: ; preds = %1
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 1024)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%17 = call i8* @strtok(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %4
store i8* %17, i8** %5
br label %18
18: ; preds = %21, %10
%19 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %4
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = load i8*, i8** %4
store i8* %22, i8** %5
br label %18
23: ; preds = %18
%24 = call i32 @memset(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @getfile.filename, i64 0, i64 0), i32 0, i32 1024)
%25 = load i8*, i8** %5
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %46
27: ; preds = %23
%28 = load i8*, i8** %5
%29 = call i32 @strcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @getfile.filename, i64 0, i64 0), i8* %28)
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @getfile.filename, i64 0, i64 0), i8** %4
br label %30
30: ; preds = %43, %27
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %30
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %4
%38 = load i8, i8* %36
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 32
br label %41
41: ; preds = %35, %30
%42 = phi i1 [ false, %30 ], [ %40, %35 ]
br i1 %42, label %43, label %44
43: ; preds = %41
br label %30
44: ; preds = %41
%45 = load i8*, i8** %4
store i8 0, i8* %45
br label %47
46: ; preds = %23
store i8* null, i8** %2
br label %48
47: ; preds = %44
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @getfile.filename, i64 0, i64 0), i8** %2
br label %48
48: ; preds = %47, %46, %9
%49 = load i8*, i8** %2
ret i8* %49
}

LLVM IR (-O2):
@getfile.filename = internal global [1024 x i8] zeroinitializer
@.str = [2 x i8] c"/\00"
define i8* @getfile(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %27, label %5
5: ; preds = %1
%6 = call i32 @memset(i8* %3, i32 0, i32 1024)
%7 = call i32 @strcpy(i8* %3, i8* %0)
%8 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %9, %5
%10 = phi i8* [ %8, %5 ], [ %11, %9 ]
%11 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %9
13: ; preds = %9
%14 = call i32 @memset(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @getfile.filename, i64 0, i64 0), i32 0, i32 1024)
%15 = icmp eq i8* %10, null
br i1 %15, label %27, label %16
16: ; preds = %13
%17 = call i32 @strcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @getfile.filename, i64 0, i64 0), i8* %10)
br label %18
18: ; preds = %22, %16
%19 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @getfile.filename, i64 0, i64 0), %16 ], [ %23, %22 ]
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = getelementptr inbounds i8, i8* %19, i64 1
%24 = icmp eq i8 %20, 32
br i1 %24, label %25, label %18
25: ; preds = %18, %22
%26 = phi i8* [ %23, %22 ], [ %19, %18 ]
store i8 0, i8* %26
br label %27
27: ; preds = %13, %1, %25
%28 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @getfile.filename, i64 0, i64 0), %25 ], [ null, %1 ], [ null, %13 ]
ret i8* %28
}