#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 /*<<< orphan*/ PATH_MAX;
int /*<<< orphan*/ free(char *);
char *malloc(int /*<<< orphan*/);
int /*<<< orphan*/ *realpath(char const *, char *);
char *canonicalize_file_name(const char *path) {
  char *s = malloc(PATH_MAX);
  if (s == NULL)
    return NULL;
  if (realpath(path, s) == NULL) {
    free(s);
    return NULL;
  }
  return s;
}


x86 assembly (clang, -O0):
<canonicalize_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1166 <canonicalize_file_name+0x36>
movq   $0x0,-0x8(%rbp)
jmp    119b <canonicalize_file_name+0x6b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <realpath@plt>
cmp    $0x0,%rax
jne    1193 <canonicalize_file_name+0x63>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    119b <canonicalize_file_name+0x6b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canonicalize_file_name>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eb2(%rip),%rax
mov    (%rax),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1165 <canonicalize_file_name+0x35>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <realpath@plt>
test   %rax,%rax
jne    1167 <canonicalize_file_name+0x37>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
define i8* @canonicalize_file_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i32, i32* @PATH_MAX
%6 = call i8* @malloc(i32 %5)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* null, i8** %2
br label %20
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i8*, i8** %4
%13 = call i32* @realpath(i8* %11, i8* %12)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = call i32 @free(i8* %16)
store i8* null, i8** %2
br label %20
18: ; preds = %10
%19 = load i8*, i8** %4
store i8* %19, i8** %2
br label %20
20: ; preds = %18, %15, %9
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
define i8* @canonicalize_file_name(i8* nocapture %0) {
%2 = load i32, i32* @PATH_MAX
%3 = tail call i8* @malloc(i32 %2)
%4 = icmp eq i8* %3, null
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = tail call i32* @realpath(i8* %0, i8* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @free(i8* %3)
br label %10
10: ; preds = %5, %1, %8
%11 = phi i8* [ null, %8 ], [ null, %1 ], [ %3, %5 ]
ret i8* %11
}