#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *GetIniDirectoryName(char *pcFilename) {
  int iLengthFilename;
  int iLastBackSlashIndex;
  int iNOBackSlashes;
  int iDone;
  char *pcResultString;
  iLengthFilename = (int)strlen(pcFilename);
  iLastBackSlashIndex = 0;
  iNOBackSlashes = 2;
  iDone = ((int)0);
  pcResultString = (char *)calloc(80, sizeof(char));
  while ((iLengthFilename >= 0) && (iDone == ((int)0))) {
    if (pcFilename[iLengthFilename] == '/') {
      iLastBackSlashIndex = iLengthFilename;
      iNOBackSlashes--;
      if (0 == iNOBackSlashes) {
        iDone = ((int)1);
      }
    }
    iLengthFilename--;
  }
  if (((int)1) == iDone) {
    strncpy(pcResultString, pcFilename, iLastBackSlashIndex);
    strcat(pcResultString, "/etc/");
  } else {
    if (iNOBackSlashes == 2) {
      strcpy(pcResultString, "../etc/");
    } else {
      if (pcFilename[0] == '.') {
        strcpy(pcResultString, "../etc/");
      } else {
        strcpy(pcResultString, "etc/");
      }
    }
  }
  return (pcResultString);
}


x86 assembly (clang, -O0):
<GetIniDirectoryName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x50,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x21(%rbp)
jl     11a9 <GetIniDirectoryName+0x59>
cmpl   $0x0,-0x18(%rbp)
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11b9 <GetIniDirectoryName+0x69>
jmp    1202 <GetIniDirectoryName+0xb2>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11f4 <GetIniDirectoryName+0xa4>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    11ef <GetIniDirectoryName+0x9f>
movl   $0x1,-0x18(%rbp)
jmp    11f4 <GetIniDirectoryName+0xa4>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1190 <GetIniDirectoryName+0x40>
mov    $0x1,%eax
cmp    -0x18(%rbp),%eax
jne    1235 <GetIniDirectoryName+0xe5>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xdd7(%rip),%rsi
call   1070 <strcat@plt>
jmp    1293 <GetIniDirectoryName+0x143>
cmpl   $0x2,-0x14(%rbp)
jne    1254 <GetIniDirectoryName+0x104>
mov    -0x20(%rbp),%rdi
lea    0xdb6(%rip),%rsi
call   1040 <strcpy@plt>
jmp    128e <GetIniDirectoryName+0x13e>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1279 <GetIniDirectoryName+0x129>
mov    -0x20(%rbp),%rdi
lea    0xd91(%rip),%rsi
call   1040 <strcpy@plt>
jmp    1289 <GetIniDirectoryName+0x139>
mov    -0x20(%rbp),%rdi
lea    0xd7f(%rip),%rsi
call   1040 <strcpy@plt>
jmp    128e <GetIniDirectoryName+0x13e>
jmp    1293 <GetIniDirectoryName+0x143>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetIniDirectoryName>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %rax,%r12
mov    $0x50,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
test   %r12d,%r12d
js     11e6 <GetIniDirectoryName+0x96>
xor    %edx,%edx
mov    $0x2,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%esi
mov    %r12d,%ecx
add    $0xffffffff,%eax
sete   %bl
cmpb   $0x2f,(%r15,%rcx,1)
sete   %cl
cmove  %r12d,%edx
cmovne %esi,%eax
and    %bl,%cl
sub    $0x1,%r12d
setb   %bl
test   %cl,%cl
jne    11bb <GetIniDirectoryName+0x6b>
test   %bl,%bl
je     1190 <GetIniDirectoryName+0x40>
test   %cl,%cl
je     11db <GetIniDirectoryName+0x8b>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strncpy@plt>
lea    0xe31(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
jmp    11f5 <GetIniDirectoryName+0xa5>
cmp    $0x2,%eax
je     11e6 <GetIniDirectoryName+0x96>
cmpb   $0x2e,(%r15)
jne    1204 <GetIniDirectoryName+0xb4>
lea    0xe13(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdf8(%rip),%rsi
jmp    11ed <GetIniDirectoryName+0x9d>

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

LLVM IR (-O2):
@.str = [6 x i8] c"/etc/\00"
@.str.1 = [8 x i8] c"../etc/\00"
@.str.2 = [5 x i8] c"etc/\00"
define i8* @GetIniDirectoryName(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = tail call i64 @calloc(i32 80, i32 1)
%5 = inttoptr i64 %4 to i8*
%6 = icmp sgt i32 %3, -1
br i1 %6, label %7, label %29
7: ; preds = %1, %7
%8 = phi i32 [ %20, %7 ], [ %3, %1 ]
%9 = phi i32 [ %18, %7 ], [ 2, %1 ]
%10 = phi i32 [ %17, %7 ], [ 0, %1 ]
%11 = zext i32 %8 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 47
%15 = add nsw i32 %9, -1
%16 = icmp eq i32 %15, 0
%17 = select i1 %14, i32 %8, i32 %10
%18 = select i1 %14, i32 %15, i32 %9
%19 = select i1 %14, i1 %16, i1 false
%20 = add nsw i32 %8, -1
%21 = icmp eq i32 %8, 0
%22 = or i1 %19, %21
br i1 %22, label %23, label %7
23: ; preds = %7
br i1 %19, label %24, label %27
24: ; preds = %23
%25 = tail call i32 @strncpy(i8* %5, i8* %0, i32 %17)
%26 = tail call i32 @strcat(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %38
27: ; preds = %23
%28 = icmp eq i32 %18, 2
br i1 %28, label %29, label %31
29: ; preds = %1, %27
%30 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %38
31: ; preds = %27
%32 = load i8, i8* %0
%33 = icmp eq i8 %32, 46
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %38
36: ; preds = %31
%37 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %29, %36, %34, %24
ret i8* %5
}