#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 canonicalize(char const *, char *, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
char *realpath(const char *path, char *resolved) {
  int rc;
  char *buffer = ((void *)0);
  if (!resolved)
    resolved = buffer = malloc(256);
  rc = canonicalize(path, resolved, 256);
  if (rc < 0) {
    resolved = ((void *)0);
    if (buffer)
      free(buffer);
  }
  return resolved;
}


x86 assembly (clang, -O0):
<realpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1165 <realpath+0x35>
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1040 <canonicalize@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11a5 <realpath+0x75>
movq   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a0 <realpath+0x70>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    11a5 <realpath+0x75>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<realpath>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
test   %rsi,%rsi
je     1158 <realpath+0x28>
mov    %rsi,%rbx
mov    %r15,%rdi
mov    $0x100,%edx
call   1040 <canonicalize@plt>
xor    %r14d,%r14d
test   %eax,%eax
cmovns %rbx,%r14
jmp    1189 <realpath+0x59>
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    %rax,%rsi
mov    $0x100,%edx
call   1040 <canonicalize@plt>
test   %eax,%eax
jns    1189 <realpath+0x59>
test   %r14,%r14
je     1186 <realpath+0x56>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @realpath(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%6 = tail call i32 @canonicalize(i8* %0, i8* %5, i32 256)
%7 = icmp slt i32 %6, 0
br i1 %7, label %12, label %16
8: ; preds = %2
%9 = tail call i32 @canonicalize(i8* %0, i8* %1, i32 256)
%10 = icmp slt i32 %9, 0
%11 = select i1 %10, i8* null, i8* %1
br label %16
12: ; preds = %4
%13 = icmp eq i8* %5, null
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = tail call i32 @free(i8* %5)
br label %16
16: ; preds = %8, %12, %14, %4
%17 = phi i8* [ null, %14 ], [ null, %12 ], [ %5, %4 ], [ %11, %8 ]
ret i8* %17
}