#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 *getenv(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *getDirName(char *s) {
  char *result = NULL;
  int i = strlen(s);
  int ok = 0;
  while ((i > 0) && (ok == 0)) {
    if (s[i] == '/') {
      ok = 1;
    }
    i--;
  }
  if (ok == 1) {
    int len = strlen(s) + 1;
    result = (char *)malloc(len * sizeof(char) + 1);
    strncpy(result, s, i + 1);
    result[i + 1] = '\0';
  } else {
    result = (char *)malloc(256);
    strcpy(result, getenv("IDL2MATLAB") ? getenv("IDL2MATLAB")
                                        : "/usr/local/lib/idl2matlab");
  }
  return result;
}


x86 assembly (clang, -O0):
<getDirName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x1d(%rbp)
jle    1190 <getDirName+0x40>
cmpl   $0x0,-0x18(%rbp)
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11a0 <getDirName+0x50>
jmp    11ca <getDirName+0x7a>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11bc <getDirName+0x6c>
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1177 <getDirName+0x27>
cmpl   $0x1,-0x18(%rbp)
jne    1223 <getDirName+0xd3>
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
call   1040 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1281 <getDirName+0x131>
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xdc0(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1264 <getDirName+0x114>
lea    0xdaa(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
jmp    1274 <getDirName+0x124>
lea    0xda0(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1274 <getDirName+0x124>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDirName>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
call   1060 <strlen@plt>
test   %eax,%eax
jle    11b9 <getDirName+0x69>
mov    %eax,%ebx
add    $0x1,%rbx
nopl   0x0(%rax)
mov    %eax,%ecx
movzbl (%r15,%rcx,1),%ecx
lea    -0x1(%rax),%ebp
add    $0xffffffffffffffff,%rbx
cmp    $0x2f,%cl
je     118a <getDirName+0x3a>
cmp    $0x1,%eax
mov    %ebp,%eax
ja     1170 <getDirName+0x20>
cmp    $0x2f,%cl
jne    11b9 <getDirName+0x69>
add    $0x1,%ebp
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    0x2(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <strncpy@plt>
movb   $0x0,(%r14,%rbx,1)
jmp    11e8 <getDirName+0x98>
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe33(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe2f(%rip),%rsi
cmovne %rax,%rsi
mov    %r14,%rdi
call   1050 <strcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"IDL2MATLAB\00"
@.str.1 = [26 x i8] c"/usr/local/lib/idl2matlab\00"
define i8* @getDirName(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %3
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %26, %1
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 0
br label %15
15: ; preds = %12, %9
%16 = phi i1 [ false, %9 ], [ %14, %12 ]
br i1 %16, label %17, label %29
17: ; preds = %15
%18 = load i8*, i8** %2
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 47
br i1 %24, label %25, label %26
25: ; preds = %17
store i32 1, i32* %5
br label %26
26: ; preds = %25, %17
%27 = load i32, i32* %4
%28 = add nsw i32 %27, -1
store i32 %28, i32* %4
br label %9
29: ; preds = %15
%30 = load i32, i32* %5
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %53
32: ; preds = %29
%33 = load i8*, i8** %2
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = mul i64 %37, 1
%39 = add i64 %38, 1
%40 = trunc i64 %39 to i32
%41 = call i64 @malloc(i32 %40)
%42 = inttoptr i64 %41 to i8*
store i8* %42, i8** %3
%43 = load i8*, i8** %3
%44 = load i8*, i8** %2
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
%47 = call i32 @strncpy(i8* %43, i8* %44, i32 %46)
%48 = load i8*, i8** %3
%49 = load i32, i32* %4
%50 = add nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
store i8 0, i8* %52
br label %65
53: ; preds = %29
%54 = call i64 @malloc(i32 256)
%55 = inttoptr i64 %54 to i8*
store i8* %55, i8** %3
%56 = load i8*, i8** %3
%57 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%58 = icmp ne i8* %57, null
br i1 %58, label %59, label %61
59: ; preds = %53
%60 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %62
61: ; preds = %53
br label %62
62: ; preds = %61, %59
%63 = phi i8* [ %60, %59 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), %61 ]
%64 = call i32 @strcpy(i8* %56, i8* %63)
br label %65
65: ; preds = %62, %32
%66 = load i8*, i8** %3
ret i8* %66
}

LLVM IR (-O2):
@.str = [11 x i8] c"IDL2MATLAB\00"
@.str.1 = [26 x i8] c"/usr/local/lib/idl2matlab\00"
define i8* @getDirName(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %22
4: ; preds = %1, %4
%5 = phi i32 [ %10, %4 ], [ %2, %1 ]
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 47
%10 = add nsw i32 %5, -1
%11 = icmp ult i32 %5, 2
%12 = or i1 %9, %11
br i1 %12, label %13, label %4
13: ; preds = %4
br i1 %9, label %14, label %22
14: ; preds = %13
%15 = tail call i32 @strlen(i8* %0)
%16 = add i32 %15, 2
%17 = tail call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
%19 = tail call i32 @strncpy(i8* %18, i8* %0, i32 %5)
%20 = zext i32 %5 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 0, i8* %21
br label %29
22: ; preds = %1, %13
%23 = tail call i64 @malloc(i32 256)
%24 = inttoptr i64 %23 to i8*
%25 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%26 = icmp eq i8* %25, null
%27 = select i1 %26, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %25
%28 = tail call i32 @strcpy(i8* %24, i8* %27)
br label %29
29: ; preds = %22, %14
%30 = phi i8* [ %18, %14 ], [ %24, %22 ]
ret i8* %30
}