#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*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
scalar_t__ realpath(char *, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *canonicalize(char *path) {
  char *canonical;
  if (path == NULL) {
    return NULL;
  }
  if (strlen(path) > PATH_MAX) {
    fprintf(stderr, "Mount point string too long\n");
    return NULL;
  }
  canonical = (char *)malloc(PATH_MAX + 1);
  if (!canonical) {
    fprintf(stderr, "Error! Not enough memory!\n");
    return NULL;
  }
  if (realpath(path, canonical))
    return canonical;
  strncpy(canonical, path, PATH_MAX);
  canonical[PATH_MAX] = '\0';
  return canonical;
}


x86 assembly (clang, -O0):
<canonicalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1174 <canonicalize+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1244 <canonicalize+0xf4>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%eax
jle    11ae <canonicalize+0x5e>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1244 <canonicalize+0xf4>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f0 <canonicalize+0xa0>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1244 <canonicalize+0xf4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <realpath@plt>
cmp    $0x0,%rax
je     1214 <canonicalize+0xc4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1244 <canonicalize+0xf4>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    0x2dbb(%rip),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canonicalize>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     11cf <canonicalize+0x7f>
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    0x2e87(%rip),%r15
mov    (%r15),%edi
cmp    %edi,%eax
jle    1182 <canonicalize+0x32>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
jmp    11ca <canonicalize+0x7a>
add    $0x1,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11ba <canonicalize+0x6a>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <realpath@plt>
test   %rax,%rax
jne    11d2 <canonicalize+0x82>
mov    (%r15),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
movslq (%r15),%rax
movb   $0x0,(%r14,%rax,1)
jmp    11d2 <canonicalize+0x82>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1050 <fprintf@plt>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"Mount point string too long\0A\00"
@.str.1 = [27 x i8] c"Error! Not enough memory!\0A\00"
define i8* @canonicalize(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* null, i8** %2
br label %43
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = load i32, i32* @PATH_MAX
%12 = icmp sgt i32 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %43
16: ; preds = %8
%17 = load i32, i32* @PATH_MAX
%18 = add nsw i32 %17, 1
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = icmp ne i8* %21, null
br i1 %22, label %26, label %23
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %43
26: ; preds = %16
%27 = load i8*, i8** %3
%28 = load i8*, i8** %4
%29 = call i64 @realpath(i8* %27, i8* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = load i8*, i8** %4
store i8* %32, i8** %2
br label %43
33: ; preds = %26
%34 = load i8*, i8** %4
%35 = load i8*, i8** %3
%36 = load i32, i32* @PATH_MAX
%37 = call i32 @strncpy(i8* %34, i8* %35, i32 %36)
%38 = load i8*, i8** %4
%39 = load i32, i32* @PATH_MAX
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 0, i8* %41
%42 = load i8*, i8** %4
store i8* %42, i8** %2
br label %43
43: ; preds = %33, %31, %23, %13, %7
%44 = load i8*, i8** %2
ret i8* %44
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"Mount point string too long\0A\00"
@.str.1 = [27 x i8] c"Error! Not enough memory!\0A\00"
define i8* @canonicalize(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %27, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = load i32, i32* @PATH_MAX
%6 = icmp sgt i32 %4, %5
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %27
10: ; preds = %3
%11 = add nsw i32 %5, 1
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = icmp eq i64 %12, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %27
18: ; preds = %10
%19 = tail call i64 @realpath(i8* %0, i8* %13)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i32, i32* @PATH_MAX
%23 = tail call i32 @strncpy(i8* %13, i8* %0, i32 %22)
%24 = load i32, i32* @PATH_MAX
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %13, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %18, %1, %21, %15, %7
%28 = phi i8* [ null, %7 ], [ %13, %21 ], [ null, %15 ], [ null, %1 ], [ %13, %18 ]
ret i8* %28
}