#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 canonicalize_path(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ stderr;
int strcmp(char *, char const *);
int zsnprintf(char *, int, char *, char const *);
int test_canonicalize_path(const char *path, const char *expected) {
  char epath[PATH_MAX];
  do {
    int __my_ret__ = zsnprintf(epath, PATH_MAX, "%s", path);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 21,
              "zsnprintf(epath, PATH_MAX, \"%s\", path)");
      return __my_ret__;
    }
  } while (0);
  ;
  if (!expected) {
    do {
      int __my_ret__ = canonicalize_path(epath);
      if (__my_ret__ == 0) {
        fprintf(stderr, "failed on line %d: %s\n", 23,
                "canonicalize_path(epath)");
        return -1;
      }
    } while (0);
    ;
  } else {
    do {
      int __my_ret__ = canonicalize_path(epath);
      if (__my_ret__) {
        fprintf(stderr, "failed on line %d: %s\n", 26,
                "canonicalize_path(epath)");
        return __my_ret__;
      }
    } while (0);
    ;
    do {
      int __my_ret__ = strcmp(epath, expected);
      if (__my_ret__) {
        fprintf(stderr, "failed on line %d: %s\n", 27,
                "strcmp(epath, expected)");
        return __my_ret__;
      }
    } while (0);
    ;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_canonicalize_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x48(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
lea    0xe6c(%rip),%rdx
call   1060 <zsnprintf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11d9 <test_canonicalize_path+0x99>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    $0x15,%edx
lea    0xe58(%rip),%rcx
call   1040 <fprintf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    1313 <test_canonicalize_path+0x1d3>
jmp    11de <test_canonicalize_path+0x9e>
jmp    11e3 <test_canonicalize_path+0xa3>
cmpq   $0x0,-0x18(%rbp)
jne    124c <test_canonicalize_path+0x10c>
jmp    11f3 <test_canonicalize_path+0xb3>
mov    -0x48(%rbp),%rdi
call   1050 <canonicalize_path@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    123d <test_canonicalize_path+0xfd>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
mov    $0x17,%edx
lea    0xe1c(%rip),%rcx
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    1313 <test_canonicalize_path+0x1d3>
jmp    1242 <test_canonicalize_path+0x102>
jmp    1247 <test_canonicalize_path+0x107>
jmp    1305 <test_canonicalize_path+0x1c5>
jmp    1251 <test_canonicalize_path+0x111>
mov    -0x48(%rbp),%rdi
call   1050 <canonicalize_path@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     129a <test_canonicalize_path+0x15a>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
lea    0xd8c(%rip),%rsi
mov    $0x1a,%edx
lea    0xdbe(%rip),%rcx
call   1040 <fprintf@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    1313 <test_canonicalize_path+0x1d3>
jmp    129f <test_canonicalize_path+0x15f>
jmp    12a4 <test_canonicalize_path+0x164>
jmp    12a9 <test_canonicalize_path+0x169>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     12f6 <test_canonicalize_path+0x1b6>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
lea    0xd30(%rip),%rsi
mov    $0x1b,%edx
lea    0xd7b(%rip),%rcx
call   1040 <fprintf@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    1313 <test_canonicalize_path+0x1d3>
jmp    12fb <test_canonicalize_path+0x1bb>
jmp    1300 <test_canonicalize_path+0x1c0>
jmp    1305 <test_canonicalize_path+0x1c5>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_canonicalize_path>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rcx
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe8b(%rip),%rdx
mov    %rbx,%rdi
call   1060 <zsnprintf@plt>
test   %eax,%eax
je     11b5 <test_canonicalize_path+0x75>
mov    %eax,%r15d
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
lea    0xe7f(%rip),%rcx
mov    $0x15,%edx
call   1040 <fprintf@plt>
mov    %r15d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1050 <canonicalize_path@plt>
mov    %eax,%r12d
test   %r14,%r14
je     11f0 <test_canonicalize_path+0xb0>
test   %r12d,%r12d
je     1221 <test_canonicalize_path+0xe1>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
lea    0xe60(%rip),%rcx
mov    $0x1a,%edx
call   1040 <fprintf@plt>
mov    %r12d,%r15d
jmp    11a5 <test_canonicalize_path+0x65>
xor    %r15d,%r15d
test   %r12d,%r12d
jne    11a5 <test_canonicalize_path+0x65>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
lea    0xe32(%rip),%rcx
mov    $0x17,%edx
call   1040 <fprintf@plt>
mov    $0xffffffff,%r15d
jmp    11a5 <test_canonicalize_path+0x65>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1254 <test_canonicalize_path+0x114>
mov    %eax,%r15d
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xdc0(%rip),%rsi
lea    0xe10(%rip),%rcx
mov    $0x1b,%edx
jmp    11a0 <test_canonicalize_path+0x60>
xor    %r15d,%r15d
jmp    11a5 <test_canonicalize_path+0x65>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [39 x i8] c"zsnprintf(epath, PATH_MAX, \22%s\22, path)\00"
@.str.3 = [25 x i8] c"canonicalize_path(epath)\00"
@.str.4 = [24 x i8] c"strcmp(epath, expected)\00"
define i32 @test_canonicalize_path(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%13 = load i32, i32* @PATH_MAX
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = alloca i8, i64 %14
store i64 %14, i64* %7
br label %17
17: ; preds = %2
%18 = load i32, i32* @PATH_MAX
%19 = load i8*, i8** %4
%20 = call i32 @zsnprintf(i8* %16, i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 21, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* %8
store i32 %26, i32* %3
store i32 1, i32* %9
br label %68
27: ; preds = %17
br label %28
28: ; preds = %27
br label %29
29: ; preds = %28
%30 = load i8*, i8** %5
%31 = icmp ne i8* %30, null
br i1 %31, label %43, label %32
32: ; preds = %29
br label %33
33: ; preds = %32
%34 = call i32 @canonicalize_path(i8* %16)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %9
br label %68
40: ; preds = %33
br label %41
41: ; preds = %40
br label %42
42: ; preds = %41
br label %67
43: ; preds = %29
br label %44
44: ; preds = %43
%45 = call i32 @canonicalize_path(i8* %16)
store i32 %45, i32* %11
%46 = load i32, i32* %11
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 26, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%51 = load i32, i32* %11
store i32 %51, i32* %3
store i32 1, i32* %9
br label %68
52: ; preds = %44
br label %53
53: ; preds = %52
br label %54
54: ; preds = %53
br label %55
55: ; preds = %54
%56 = load i8*, i8** %5
%57 = call i32 @strcmp(i8* %16, i8* %56)
store i32 %57, i32* %12
%58 = load i32, i32* %12
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %55
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 27, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%63 = load i32, i32* %12
store i32 %63, i32* %3
store i32 1, i32* %9
br label %68
64: ; preds = %55
br label %65
65: ; preds = %64
br label %66
66: ; preds = %65
br label %67
67: ; preds = %66, %42
store i32 0, i32* %3
store i32 1, i32* %9
br label %68
68: ; preds = %67, %60, %48, %37, %23
%69 = load i8*, i8** %6
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [39 x i8] c"zsnprintf(epath, PATH_MAX, \22%s\22, path)\00"
@.str.3 = [25 x i8] c"canonicalize_path(epath)\00"
@.str.4 = [24 x i8] c"strcmp(epath, expected)\00"
define i32 @test_canonicalize_path(i8* %0, i8* %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @zsnprintf(i8* %5, i32 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 21, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %29
11: ; preds = %2
%12 = icmp eq i8* %1, null
%13 = call i32 @canonicalize_path(i8* %5)
%14 = icmp eq i32 %13, 0
br i1 %12, label %15, label %19
15: ; preds = %11
br i1 %14, label %16, label %29
16: ; preds = %15
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %29
19: ; preds = %11
br i1 %14, label %23, label %20
20: ; preds = %19
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 26, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %29
23: ; preds = %19
%24 = call i32 @strcmp(i8* %5, i8* %1)
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 27, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %23, %15, %26, %20, %16, %8
%30 = phi i32 [ %24, %26 ], [ %13, %20 ], [ %6, %8 ], [ -1, %16 ], [ 0, %15 ], [ 0, %23 ]
ret i32 %30
}