#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*/ ENOMEM;
char *calloc(int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
char *realpath(char const *, char *);
*canonicalize_file_name(const char *name) {
  char *buf;
  int size;
  char *result;
  size = 4096;
  buf = calloc(size + 1, 1);
  if (!buf) {
    errno = ENOMEM;
    return NULL;
  }
  result = realpath(name, buf);
  if (!result)
    free(buf);
  return result;
}


x86 assembly (clang, -O0):
<canonicalize_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x1000,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1181 <canonicalize_file_name+0x51>
mov    0x2e77(%rip),%rax
mov    (%rax),%ecx
mov    0x2e66(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11ae <canonicalize_file_name+0x7e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <realpath@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a6 <canonicalize_file_name+0x76>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canonicalize_file_name>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x1001,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     116b <canonicalize_file_name+0x3b>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <realpath@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1180 <canonicalize_file_name+0x50>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1180 <canonicalize_file_name+0x50>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
mov    0x2e5d(%rip),%rcx
mov    %eax,(%rcx)
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@ENOMEM = global i32 0
@errno = global i32 0
define i32* @canonicalize_file_name(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i32 4096, i32* %5
%7 = load i32, i32* %5
%8 = add nsw i32 %7, 1
%9 = call i8* @calloc(i32 %8, i32 1)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = load i32, i32* @ENOMEM
store i32 %13, i32* @errno
store i32* null, i32** %2
br label %26
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = load i8*, i8** %4
%17 = call i8* @realpath(i8* %15, i8* %16)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = call i32 @free(i8* %21)
br label %23
23: ; preds = %20, %14
%24 = load i8*, i8** %6
%25 = bitcast i8* %24 to i32*
store i32* %25, i32** %2
br label %26
26: ; preds = %23, %12
%27 = load i32*, i32** %2
ret i32* %27
}

LLVM IR (-O2):
@ENOMEM = global i32 0
@errno = global i32 0
define i32* @canonicalize_file_name(i8* nocapture %0) {
%2 = tail call dereferenceable_or_null(4097) i8* @calloc(i32 4097, i32 1)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = load i32, i32* @ENOMEM
store i32 %5, i32* @errno
br label %13
6: ; preds = %1
%7 = tail call i8* @realpath(i8* %0, i8* %2)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @free(i8* %2)
br label %11
11: ; preds = %9, %6
%12 = bitcast i8* %7 to i32*
br label %13
13: ; preds = %11, %4
%14 = phi i32* [ %12, %11 ], [ null, %4 ]
ret i32* %14
}