#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 */
int PATH_MAX;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strsep(char **, char *);
int psys_path_is_canonical(const char *path) {
  char pathcpy[PATH_MAX];
  char *run, *cmp;
  strncpy(pathcpy, path + 1, PATH_MAX);
  run = pathcpy;
  while ((cmp = strsep(&run, "/")) != NULL) {
    if (!strlen(cmp) || !strcmp(cmp, ".") || !strcmp(cmp, ".."))
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<psys_path_is_canonical>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1060 <strsep@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1210 <psys_path_is_canonical+0xd0>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
je     11f8 <psys_path_is_canonical+0xb8>
mov    -0x30(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11f8 <psys_path_is_canonical+0xb8>
mov    -0x30(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    120b <psys_path_is_canonical+0xcb>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    121e <psys_path_is_canonical+0xde>
jmp    1196 <psys_path_is_canonical+0x56>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psys_path_is_canonical>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0x1(%rdi),%rsi
mov    %rbx,%rdi
call   1030 <strncpy@plt>
mov    %rbx,-0x30(%rbp)
lea    0xe7e(%rip),%r14
lea    -0x30(%rbp),%r13
lea    0xe76(%rip),%r15
xor    %ebx,%ebx
nop
mov    %r13,%rdi
mov    %r14,%rsi
call   1060 <strsep@plt>
test   %rax,%rax
je     11d3 <psys_path_is_canonical+0x93>
mov    %rax,%r12
mov    %rax,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11d8 <psys_path_is_canonical+0x98>
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11d8 <psys_path_is_canonical+0x98>
mov    %r12,%rdi
lea    0xe3a(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    1190 <psys_path_is_canonical+0x50>
jmp    11d8 <psys_path_is_canonical+0x98>
mov    $0x1,%ebx
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
define i32 @psys_path_is_canonical(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i32, i32* @PATH_MAX
%16 = call i32 @strncpy(i8* %12, i8* %14, i32 %15)
store i8* %12, i8** %6
br label %17
17: ; preds = %33, %1
%18 = call i8* @strsep(i8** %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %18, i8** %7
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %34
20: ; preds = %17
%21 = load i8*, i8** %7
%22 = call i32 @strlen(i8* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i8*, i8** %7
%26 = call i32 @strcmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i8*, i8** %7
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %28, %24, %20
store i32 0, i32* %2
store i32 1, i32* %8
br label %35
33: ; preds = %28
br label %17
34: ; preds = %17
store i32 1, i32* %2
store i32 1, i32* %8
br label %35
35: ; preds = %34, %32
%36 = load i8*, i8** %4
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
define i32 @psys_path_is_canonical(i8* %0) {
%2 = alloca i8*
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = bitcast i8** %2 to i8*
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = call i32 @strncpy(i8* %5, i8* %7, i32 %3)
store i8* %5, i8** %2
br label %9
9: ; preds = %18, %1
%10 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = call i32 @strlen(i8* %10)
%14 = icmp eq i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = call i32 @strcmp(i8* %10, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = call i32 @strcmp(i8* %10, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %9
21: ; preds = %9, %12, %15, %18
%22 = phi i32 [ 0, %18 ], [ 0, %15 ], [ 0, %12 ], [ 1, %9 ]
ret i32 %22
}