#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*/ getcwd(char *, int);
char *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
char *getDirectory() {
  char cwd[256];
  char *result = malloc(256);
  getcwd(cwd, 256);
  int lastSlash = 0;
  for (int i = 0; i < 256; i++) {
    if (cwd[i] == '/')
      lastSlash = i;
  }
  strcpy(result, cwd + lastSlash + 1);
  return result;
}


x86 assembly (clang, -O0):
<getDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,-0x108(%rbp)
lea    -0x100(%rbp),%rdi
mov    $0x100,%esi
call   1040 <getcwd@plt>
movl   $0x0,-0x10c(%rbp)
movl   $0x0,-0x110(%rbp)
cmpl   $0x100,-0x110(%rbp)
jge    11be <getDirectory+0x8e>
movslq -0x110(%rbp),%rax
movsbl -0x100(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    11a5 <getDirectory+0x75>
mov    -0x110(%rbp),%eax
mov    %eax,-0x10c(%rbp)
jmp    11aa <getDirectory+0x7a>
mov    -0x110(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x110(%rbp)
jmp    1171 <getDirectory+0x41>
mov    -0x108(%rbp),%rdi
lea    -0x100(%rbp),%rsi
movslq -0x10c(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
mov    -0x108(%rbp),%rax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDirectory>:
push   %rbx
sub    $0x100,%rsp
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1040 <getcwd@plt>
xor    %eax,%eax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
cmpb   $0x2f,(%rsp,%rax,1)
cmove  %eax,%ecx
cmpb   $0x2f,0x1(%rsp,%rax,1)
lea    0x1(%rax),%edx
cmovne %ecx,%edx
lea    0x2(%rax),%esi
cmpb   $0x2f,0x2(%rsp,%rax,1)
cmovne %edx,%esi
lea    0x3(%rax),%ecx
cmpb   $0x2f,0x3(%rsp,%rax,1)
cmovne %esi,%ecx
add    $0x4,%rax
cmp    $0x100,%rax
jne    1160 <getDirectory+0x30>
movslq %ecx,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x1,%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i8* @getDirectory() {
%1 = alloca [256 x i8]
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = call i8* @malloc(i32 256)
store i8* %5, i8** %2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%7 = call i32 @getcwd(i8* %6, i32 256)
store i32 0, i32* %3
store i32 0, i32* %4
br label %8
8: ; preds = %21, %0
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 256
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 47
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = load i32, i32* %4
store i32 %19, i32* %3
br label %20
20: ; preds = %18, %11
br label %21
21: ; preds = %20
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %8
24: ; preds = %8
%25 = load i8*, i8** %2
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = call i32 @strcpy(i8* %25, i8* %30)
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
define i8* @getDirectory() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%4 = call i32 @getcwd(i8* %2, i32 256)
br label %10
5: ; preds = %10
%6 = sext i32 %35 to i64
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %6
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = call i32 @strcpy(i8* %3, i8* %8)
ret i8* %3
10: ; preds = %10, %0
%11 = phi i64 [ 0, %0 ], [ %36, %10 ]
%12 = phi i32 [ 0, %0 ], [ %35, %10 ]
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %11
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 47
%16 = trunc i64 %11 to i32
%17 = select i1 %15, i32 %16, i32 %12
%18 = or i64 %11, 1
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 47
%22 = trunc i64 %18 to i32
%23 = select i1 %21, i32 %22, i32 %17
%24 = or i64 %11, 2
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 47
%28 = trunc i64 %24 to i32
%29 = select i1 %27, i32 %28, i32 %23
%30 = or i64 %11, 3
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 47
%34 = trunc i64 %30 to i32
%35 = select i1 %33, i32 %34, i32 %29
%36 = add nuw nsw i64 %11, 4
%37 = icmp eq i64 %36, 256
br i1 %37, label %5, label %10
}