#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__ eslib_file_path_check(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
scalar_t__ strnlen(char *, int);
int eslib_file_getparent(char *inpath, char outpath[2048]) {
  int i;
  if (inpath == NULL || outpath == NULL)
    return -1;
  if (eslib_file_path_check(inpath))
    return -1;
  i = (int)strnlen(inpath, 2048);
  if (i >= 2048 || i == 0)
    return -1;
  strncpy(outpath, inpath, (size_t)i);
  outpath[i] = '\0';
  while (i >= 0) {
    if (outpath[i] == '/') {
      outpath[i] = '\0';
      break;
    }
    outpath[i] = '\0';
    --i;
  }
  if (i < 0) {
    printf("eslib bad path?\n");
    return -1;
  }
  if (i == 0)
    goto return_root;
  return 0;
return_root:
  outpath[0] = '/';
  outpath[1] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<eslib_file_getparent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1166 <eslib_file_getparent+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1172 <eslib_file_getparent+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    127f <eslib_file_getparent+0x13f>
mov    -0x10(%rbp),%rdi
call   1040 <eslib_file_path_check@plt>
cmp    $0x0,%rax
je     1191 <eslib_file_getparent+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    127f <eslib_file_getparent+0x13f>
mov    -0x10(%rbp),%rdi
mov    $0x800,%esi
call   1060 <strnlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x800,-0x1c(%rbp)
jge    11b9 <eslib_file_getparent+0x79>
cmpl   $0x0,-0x1c(%rbp)
jne    11c5 <eslib_file_getparent+0x85>
movl   $0xffffffff,-0x4(%rbp)
jmp    127f <eslib_file_getparent+0x13f>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x1c(%rbp)
jl     122c <eslib_file_getparent+0xec>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1212 <eslib_file_getparent+0xd2>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    122c <eslib_file_getparent+0xec>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e2 <eslib_file_getparent+0xa2>
cmpl   $0x0,-0x1c(%rbp)
jge    124e <eslib_file_getparent+0x10e>
lea    0xdc3(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127f <eslib_file_getparent+0x13f>
cmpl   $0x0,-0x1c(%rbp)
jne    125d <eslib_file_getparent+0x11d>
jmp    1269 <eslib_file_getparent+0x129>
movl   $0x0,-0x4(%rbp)
jmp    127f <eslib_file_getparent+0x13f>
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eslib_file_getparent>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     1168 <eslib_file_getparent+0x28>
mov    %rsi,%r15
test   %rsi,%rsi
je     1168 <eslib_file_getparent+0x28>
mov    %rdi,%rbx
call   1040 <eslib_file_path_check@plt>
test   %rax,%rax
je     1174 <eslib_file_getparent+0x34>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    $0x800,%esi
call   1060 <strnlen@plt>
mov    %rax,%rbp
cmp    $0x7ff,%ebp
jg     1168 <eslib_file_getparent+0x28>
test   %ebp,%ebp
je     1168 <eslib_file_getparent+0x28>
movslq %ebp,%r12
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%r12,1)
test   %ebp,%ebp
js     11c7 <eslib_file_getparent+0x87>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%eax
cmpb   $0x2f,(%r15,%rax,1)
movb   $0x0,(%r15,%rax,1)
je     11d5 <eslib_file_getparent+0x95>
lea    -0x1(%rbp),%eax
test   %ebp,%ebp
mov    %eax,%ebp
jg     11b0 <eslib_file_getparent+0x70>
lea    0xe32(%rip),%rdi
call   1050 <puts@plt>
jmp    1168 <eslib_file_getparent+0x28>
xor    %r14d,%r14d
test   %ebp,%ebp
jne    1168 <eslib_file_getparent+0x28>
movw   $0x2f,(%r15)
jmp    1168 <eslib_file_getparent+0x28>

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

LLVM IR (-O2):
@str = [16 x i8] c"eslib bad path?\00"
define i32 @eslib_file_getparent(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %36, label %6
6: ; preds = %2
%7 = tail call i64 @eslib_file_path_check(i8* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %36
9: ; preds = %6
%10 = tail call i64 @strnlen(i8* %0, i32 2048)
%11 = trunc i64 %10 to i32
%12 = icmp sgt i32 %11, 2047
%13 = icmp eq i32 %11, 0
%14 = or i1 %12, %13
br i1 %14, label %36, label %15
15: ; preds = %9
%16 = shl i64 %10, 32
%17 = ashr exact i64 %16, 32
%18 = tail call i32 @strncpy(i8* %1, i8* %0, i64 %17)
%19 = getelementptr inbounds i8, i8* %1, i64 %17
store i8 0, i8* %19
%20 = icmp sgt i32 %11, -1
br i1 %20, label %21, label %30
21: ; preds = %15, %27
%22 = phi i32 [ %28, %27 ], [ %11, %15 ]
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %1, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 47
store i8 0, i8* %24
br i1 %26, label %32, label %27
27: ; preds = %21
%28 = add nsw i32 %22, -1
%29 = icmp sgt i32 %22, 0
br i1 %29, label %21, label %30
30: ; preds = %27, %15
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %36
32: ; preds = %21
%33 = icmp eq i32 %22, 0
br i1 %33, label %34, label %36
34: ; preds = %32
store i8 47, i8* %1
%35 = getelementptr inbounds i8, i8* %1, i64 1
store i8 0, i8* %35
br label %36
36: ; preds = %32, %9, %6, %2, %34, %30
%37 = phi i32 [ -1, %30 ], [ 0, %34 ], [ -1, %2 ], [ -1, %6 ], [ -1, %9 ], [ 0, %32 ]
ret i32 %37
}