#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*/ die(char *, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
char *realpath(char *, int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void test_realpath(void) {
  char *path = realpath("/tmp/symlink", NULL);
  if (!path)
    die("realpath failed: %s\n", strerror(errno));
  if (strcmp(path, "/tmp/data") != 0)
    die("realpath strcmp failed\n");
  free(path);
}


x86 assembly (clang, -O0):
<test_realpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <realpath@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1195 <test_realpath+0x45>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1060 <die@plt>
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11bd <test_realpath+0x6d>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1060 <die@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_realpath>:
push   %rbx
lea    0xea8(%rip),%rdi
xor    %esi,%esi
call   1050 <realpath@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1185 <test_realpath+0x35>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe91(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <die@plt>
lea    0xe96(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11a7 <test_realpath+0x57>
lea    0xe8c(%rip),%rdi
xor    %eax,%eax
call   1060 <die@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/tmp/symlink\00"
@.str.1 = [21 x i8] c"realpath failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [10 x i8] c"/tmp/data\00"
@.str.3 = [24 x i8] c"realpath strcmp failed\0A\00"
define void @test_realpath() {
%1 = alloca i8*
%2 = call i8* @realpath(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* null)
store i8* %2, i8** %1
%3 = load i8*, i8** %1
%4 = icmp ne i8* %3, null
br i1 %4, label %9, label %5
5: ; preds = %0
%6 = load i32, i32* @errno
%7 = call i32 @strerror(i32 %6)
%8 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %5, %0
%10 = load i8*, i8** %1
%11 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = load i8*, i8** %1
%17 = call i32 @free(i8* %16)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/tmp/symlink\00"
@.str.1 = [21 x i8] c"realpath failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [10 x i8] c"/tmp/data\00"
@.str.3 = [24 x i8] c"realpath strcmp failed\0A\00"
define void @test_realpath() {
%1 = tail call i8* @realpath(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* null)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = load i32, i32* @errno
%5 = tail call i32 @strerror(i32 %4)
%6 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %7
7: ; preds = %3, %0
%8 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = tail call i32 @free(i8* %1)
ret void
}