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

/* Variables and functions */
int countSubPathComponents(char const *, int);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ getcwd(char *, int);
int countPathComponents(const char *pszPath) {
  int cComponents = 0;
  if (!((pszPath[0]) == '/')) {
    char szCwd[4096];
    if (!getcwd(szCwd, sizeof(szCwd))) {
      err(1, "getcwd");
      return -1;
    }
    cComponents = countSubPathComponents(szCwd, 0);
  }
  return countSubPathComponents(pszPath, cComponents);
}


x86 assembly (clang, -O0):
<countPathComponents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     119e <countPathComponents+0x6e>
lea    -0x1020(%rbp),%rdi
mov    $0x1000,%esi
call   1030 <getcwd@plt>
cmp    $0x0,%eax
jne    118d <countPathComponents+0x5d>
mov    $0x1,%edi
lea    0xe84(%rip),%rsi
call   1040 <err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ad <countPathComponents+0x7d>
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
call   1050 <countSubPathComponents@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <countSubPathComponents@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countPathComponents>:
push   %rbx
sub    $0x1000,%rsp
mov    %rdi,%rbx
xor    %esi,%esi
cmpb   $0x2f,(%rdi)
je     115f <countPathComponents+0x2f>
mov    %rsp,%rdi
mov    $0x1000,%esi
call   1030 <getcwd@plt>
test   %eax,%eax
je     1169 <countPathComponents+0x39>
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <countSubPathComponents@plt>
mov    %eax,%esi
mov    %rbx,%rdi
call   1050 <countSubPathComponents@plt>
jmp    117f <countPathComponents+0x4f>
lea    0xe90(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
mov    $0xffffffff,%eax
add    $0x1000,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"getcwd\00"
define i32 @countPathComponents(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [4096 x i8]
store i8* %0, i8** %3
store i32 0, i32* %4
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 47
br i1 %10, label %20, label %11
11: ; preds = %1
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%13 = call i32 @getcwd(i8* %12, i32 4096)
%14 = icmp ne i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %24
17: ; preds = %11
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%19 = call i32 @countSubPathComponents(i8* %18, i32 0)
store i32 %19, i32* %4
br label %20
20: ; preds = %17, %1
%21 = load i8*, i8** %3
%22 = load i32, i32* %4
%23 = call i32 @countSubPathComponents(i8* %21, i32 %22)
store i32 %23, i32* %2
br label %24
24: ; preds = %20, %15
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [7 x i8] c"getcwd\00"
define i32 @countPathComponents(i8* %0) {
%2 = alloca [4096 x i8]
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 47
br i1 %4, label %13, label %5
5: ; preds = %1
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%7 = call i32 @getcwd(i8* %6, i32 4096)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %16
11: ; preds = %5
%12 = call i32 @countSubPathComponents(i8* %6, i32 0)
br label %13
13: ; preds = %11, %1
%14 = phi i32 [ 0, %1 ], [ %12, %11 ]
%15 = call i32 @countSubPathComponents(i8* %0, i32 %14)
br label %16
16: ; preds = %9, %13
%17 = phi i32 [ %15, %13 ], [ -1, %9 ]
ret i32 %17
}