#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*/ tmp_path;

/* Variables and functions */
int EINVAL;
int ENOBUFS;
int PATH_MAX;
char *basename(char *);
char *dirname(char *);
int dot_to_absolute(char *, size_t);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
int get_directory_and_base_name(char *dir_path, size_t dir_path_size,
                                char *base_name, size_t base_name_size,
                                const char *path) {
  char tmp_path[PATH_MAX];
  int ret;
  if (!path)
    return EINVAL;
  if (!dir_path || dir_path_size < 1)
    return ENOBUFS;
  if (!base_name || base_name_size < 1)
    return ENOBUFS;
  strncpy(tmp_path, path, sizeof(tmp_path));
  if (tmp_path[sizeof(tmp_path) - 1] != '\0')
    return ENOBUFS;
  strncpy(base_name, basename(tmp_path), base_name_size);
  if (base_name[base_name_size - 1] != '\0')
    return ENOBUFS;
  strncpy(tmp_path, path, sizeof(tmp_path));
  if (tmp_path[sizeof(tmp_path) - 1] != '\0')
    return ENOBUFS;
  strncpy(dir_path, dirname(tmp_path), dir_path_size);
  if (dir_path[dir_path_size - 1] != '\0')
    return ENOBUFS;
  ret = dot_to_absolute(dir_path, dir_path_size);
  if (ret != 0) {
    return ret;
  }
  if (strcmp(base_name, ".") == 0) {
    strncpy(base_name, "", base_name_size);
    if (base_name[base_name_size - 1] != '\0')
      return ENOBUFS;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_directory_and_base_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x58(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11bf <get_directory_and_base_name+0x6f>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    13e1 <get_directory_and_base_name+0x291>
cmpq   $0x0,-0x10(%rbp)
je     11d5 <get_directory_and_base_name+0x85>
cmpq   $0x1,-0x18(%rbp)
jae    11ed <get_directory_and_base_name+0x9d>
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    13e1 <get_directory_and_base_name+0x291>
cmpq   $0x0,-0x20(%rbp)
je     1203 <get_directory_and_base_name+0xb3>
cmpq   $0x1,-0x28(%rbp)
jae    121b <get_directory_and_base_name+0xcb>
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    13e1 <get_directory_and_base_name+0x291>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    -0x30(%rbp),%rsi
call   1030 <strncpy@plt>
mov    -0x58(%rbp),%rcx
mov    -0x50(%rbp),%rax
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     125d <get_directory_and_base_name+0x10d>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    13e1 <get_directory_and_base_name+0x291>
mov    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
call   1060 <basename@plt>
mov    -0x60(%rbp),%rdi
mov    %rax,%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     12af <get_directory_and_base_name+0x15f>
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    13e1 <get_directory_and_base_name+0x291>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    -0x30(%rbp),%rsi
call   1030 <strncpy@plt>
mov    -0x58(%rbp),%rcx
mov    -0x50(%rbp),%rax
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     12f1 <get_directory_and_base_name+0x1a1>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    13e1 <get_directory_and_base_name+0x291>
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
call   1040 <dirname@plt>
mov    -0x68(%rbp),%rdi
mov    %rax,%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1343 <get_directory_and_base_name+0x1f3>
mov    0x2cc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    13e1 <get_directory_and_base_name+0x291>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <dot_to_absolute@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     136f <get_directory_and_base_name+0x21f>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    13e1 <get_directory_and_base_name+0x291>
mov    -0x20(%rbp),%rdi
lea    0xc86(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    13d3 <get_directory_and_base_name+0x283>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xc69(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     13ce <get_directory_and_base_name+0x27e>
mov    0x2c3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    13e1 <get_directory_and_base_name+0x291>
jmp    13d3 <get_directory_and_base_name+0x283>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_directory_and_base_name>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e80(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r15
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
test   %r8,%r8
je     1230 <get_directory_and_base_name+0xe0>
mov    %rdi,%r13
test   %rdi,%rdi
je     1227 <get_directory_and_base_name+0xd7>
mov    %rsi,%r12
test   %rsi,%rsi
je     1227 <get_directory_and_base_name+0xd7>
test   %rdx,%rdx
je     1227 <get_directory_and_base_name+0xd7>
test   %rcx,%rcx
je     1227 <get_directory_and_base_name+0xd7>
mov    %r8,%rbx
mov    %rdx,-0x30(%rbp)
mov    %rcx,-0x38(%rbp)
mov    %r15,%rdi
mov    %r8,%rsi
mov    %r14,%rdx
call   1030 <strncpy@plt>
cmpb   $0x0,-0x1(%r14,%r15,1)
jne    1227 <get_directory_and_base_name+0xd7>
mov    %r15,%rdi
call   1060 <basename@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
mov    -0x38(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rax
cmpb   $0x0,-0x1(%rax,%rcx,1)
jne    1227 <get_directory_and_base_name+0xd7>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <strncpy@plt>
cmpb   $0x0,-0x1(%r15,%r14,1)
jne    1227 <get_directory_and_base_name+0xd7>
mov    %r15,%rdi
call   1040 <dirname@plt>
mov    %r13,%rdi
mov    %rax,%rsi
mov    %r12,%rdx
call   1030 <strncpy@plt>
cmpb   $0x0,-0x1(%r12,%r13,1)
je     1248 <get_directory_and_base_name+0xf8>
mov    0x2dca(%rip),%rax
jmp    1237 <get_directory_and_base_name+0xe7>
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rdi
mov    %r12,%rsi
call   1070 <dot_to_absolute@plt>
test   %eax,%eax
jne    1239 <get_directory_and_base_name+0xe9>
lea    0xda2(%rip),%rsi
mov    -0x30(%rbp),%rdi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1239 <get_directory_and_base_name+0xe9>
lea    0xd89(%rip),%rsi
mov    -0x30(%rbp),%r14
mov    %r14,%rdi
mov    -0x38(%rbp),%rbx
mov    %rbx,%rdx
call   1030 <strncpy@plt>
xor    %eax,%eax
cmpb   $0x0,-0x1(%r14,%rbx,1)
jne    1227 <get_directory_and_base_name+0xd7>
jmp    1239 <get_directory_and_base_name+0xe9>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@EINVAL = global i32 0
@ENOBUFS = global i32 0
@.str = [2 x i8] c".\00"
@.str.1 = [1 x i8] zeroinitializer
define i32 @get_directory_and_base_name(i8* %0, i64 %1, i8* %2, i64 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %7
store i64 %1, i64* %8
store i8* %2, i8** %9
store i64 %3, i64* %10
store i8* %4, i8** %11
%16 = load i32, i32* @PATH_MAX
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %12
%19 = alloca i8, i64 %17
store i64 %17, i64* %13
%20 = load i8*, i8** %11
%21 = icmp ne i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %5
%23 = load i32, i32* @EINVAL
store i32 %23, i32* %6
store i32 1, i32* %15
br label %115
24: ; preds = %5
%25 = load i8*, i8** %7
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i64, i64* %8
%29 = icmp ult i64 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %27, %24
%31 = load i32, i32* @ENOBUFS
store i32 %31, i32* %6
store i32 1, i32* %15
br label %115
32: ; preds = %27
%33 = load i8*, i8** %9
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i64, i64* %10
%37 = icmp ult i64 %36, 1
br i1 %37, label %38, label %40
38: ; preds = %35, %32
%39 = load i32, i32* @ENOBUFS
store i32 %39, i32* %6
store i32 1, i32* %15
br label %115
40: ; preds = %35
%41 = load i8*, i8** %11
%42 = call i32 @strncpy(i8* %19, i8* %41, i64 %17)
%43 = sub i64 %17, 1
%44 = getelementptr inbounds i8, i8* %19, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %40
%49 = load i32, i32* @ENOBUFS
store i32 %49, i32* %6
store i32 1, i32* %15
br label %115
50: ; preds = %40
%51 = load i8*, i8** %9
%52 = call i8* @basename(i8* %19)
%53 = load i64, i64* %10
%54 = call i32 @strncpy(i8* %51, i8* %52, i64 %53)
%55 = load i8*, i8** %9
%56 = load i64, i64* %10
%57 = sub i64 %56, 1
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %50
%63 = load i32, i32* @ENOBUFS
store i32 %63, i32* %6
store i32 1, i32* %15
br label %115
64: ; preds = %50
%65 = load i8*, i8** %11
%66 = call i32 @strncpy(i8* %19, i8* %65, i64 %17)
%67 = sub i64 %17, 1
%68 = getelementptr inbounds i8, i8* %19, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %64
%73 = load i32, i32* @ENOBUFS
store i32 %73, i32* %6
store i32 1, i32* %15
br label %115
74: ; preds = %64
%75 = load i8*, i8** %7
%76 = call i8* @dirname(i8* %19)
%77 = load i64, i64* %8
%78 = call i32 @strncpy(i8* %75, i8* %76, i64 %77)
%79 = load i8*, i8** %7
%80 = load i64, i64* %8
%81 = sub i64 %80, 1
%82 = getelementptr inbounds i8, i8* %79, i64 %81
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %74
%87 = load i32, i32* @ENOBUFS
store i32 %87, i32* %6
store i32 1, i32* %15
br label %115
88: ; preds = %74
%89 = load i8*, i8** %7
%90 = load i64, i64* %8
%91 = call i32 @dot_to_absolute(i8* %89, i64 %90)
store i32 %91, i32* %14
%92 = load i32, i32* %14
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %96
94: ; preds = %88
%95 = load i32, i32* %14
store i32 %95, i32* %6
store i32 1, i32* %15
br label %115
96: ; preds = %88
%97 = load i8*, i8** %9
%98 = call i64 @strcmp(i8* %97, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%99 = icmp eq i64 %98, 0
br i1 %99, label %100, label %114
100: ; preds = %96
%101 = load i8*, i8** %9
%102 = load i64, i64* %10
%103 = call i32 @strncpy(i8* %101, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i64 %102)
%104 = load i8*, i8** %9
%105 = load i64, i64* %10
%106 = sub i64 %105, 1
%107 = getelementptr inbounds i8, i8* %104, i64 %106
%108 = load i8, i8* %107
%109 = sext i8 %108 to i32
%110 = icmp ne i32 %109, 0
br i1 %110, label %111, label %113
111: ; preds = %100
%112 = load i32, i32* @ENOBUFS
store i32 %112, i32* %6
store i32 1, i32* %15
br label %115
113: ; preds = %100
br label %114
114: ; preds = %113, %96
store i32 0, i32* %6
store i32 1, i32* %15
br label %115
115: ; preds = %114, %111, %94, %86, %72, %62, %48, %38, %30, %22
%116 = load i8*, i8** %12
%117 = load i32, i32* %6
ret i32 %117
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@EINVAL = global i32 0
@ENOBUFS = global i32 0
@.str = [2 x i8] c".\00"
@.str.1 = [1 x i8] zeroinitializer
define i32 @get_directory_and_base_name(i8* %0, i64 %1, i8* %2, i64 %3, i8* %4) {
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = icmp eq i8* %4, null
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = load i32, i32* @EINVAL
br label %68
12: ; preds = %5
%13 = icmp eq i8* %0, null
%14 = icmp eq i64 %1, 0
%15 = or i1 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load i32, i32* @ENOBUFS
br label %68
18: ; preds = %12
%19 = icmp eq i8* %2, null
%20 = icmp eq i64 %3, 0
%21 = or i1 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = load i32, i32* @ENOBUFS
br label %68
24: ; preds = %18
%25 = call i32 @strncpy(i8* %8, i8* %4, i64 %7)
%26 = add nsw i64 %7, -1
%27 = getelementptr inbounds i8, i8* %8, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %24
%31 = load i32, i32* @ENOBUFS
br label %68
32: ; preds = %24
%33 = call i8* @basename(i8* %8)
%34 = call i32 @strncpy(i8* %2, i8* %33, i64 %3)
%35 = add i64 %3, -1
%36 = getelementptr inbounds i8, i8* %2, i64 %35
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %32
%40 = load i32, i32* @ENOBUFS
br label %68
41: ; preds = %32
%42 = call i32 @strncpy(i8* %8, i8* %4, i64 %7)
%43 = load i8, i8* %27
%44 = icmp eq i8 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %41
%46 = load i32, i32* @ENOBUFS
br label %68
47: ; preds = %41
%48 = call i8* @dirname(i8* %8)
%49 = call i32 @strncpy(i8* %0, i8* %48, i64 %1)
%50 = add i64 %1, -1
%51 = getelementptr inbounds i8, i8* %0, i64 %50
%52 = load i8, i8* %51
%53 = icmp eq i8 %52, 0
br i1 %53, label %56, label %54
54: ; preds = %47
%55 = load i32, i32* @ENOBUFS
br label %68
56: ; preds = %47
%57 = call i32 @dot_to_absolute(i8* %0, i64 %1)
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %68
59: ; preds = %56
%60 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %59
%63 = call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i64 %3)
%64 = load i8, i8* %36
%65 = icmp eq i8 %64, 0
%66 = load i32, i32* @ENOBUFS
%67 = select i1 %65, i32 0, i32 %66
br label %68
68: ; preds = %62, %59, %56, %54, %45, %39, %30, %22, %16, %10
%69 = phi i32 [ %17, %16 ], [ %23, %22 ], [ %31, %30 ], [ %40, %39 ], [ %46, %45 ], [ %55, %54 ], [ %11, %10 ], [ %57, %56 ], [ 0, %59 ], [ %67, %62 ]
ret i32 %69
}