#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 */
struct stat {
  scalar_t__ st_size;
};

/* Variables and functions */
scalar_t__ calloc(int, size_t);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ readlink(char const *, char *, size_t);
void file__print_link_target(struct stat *st, const char *full_linkname) {
  size_t length = (size_t)st->st_size + 1;
  char *buffer = (char *)calloc(sizeof(char), length);
  buffer[length - 1] = 0;
  readlink(full_linkname, buffer, length - 1);
  printf("-> %s", buffer);
  free(buffer);
}


x86 assembly (clang, -O0):
<file__print_link_target>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    $0x1,%rdx
call   1040 <readlink@plt>
mov    -0x20(%rbp),%rsi
lea    0xe5f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file__print_link_target>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    (%rdi),%r15
lea    0x1(%r15),%rsi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax,%r15,1)
mov    %r14,%rdi
mov    %rax,%rsi
mov    %r15,%rdx
call   1040 <readlink@plt>
lea    0xe8a(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [6 x i8] c"-> %s\00"
define void @file__print_link_target(%struct.stat* %0, i8* %1) {
%3 = alloca %struct.stat*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store %struct.stat* %0, %struct.stat** %3
store i8* %1, i8** %4
%7 = load %struct.stat*, %struct.stat** %3
%8 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%9 = load i64, i64* %8
%10 = add i64 %9, 1
store i64 %10, i64* %5
%11 = load i64, i64* %5
%12 = call i64 @calloc(i32 1, i64 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = load i64, i64* %5
%16 = sub i64 %15, 1
%17 = getelementptr inbounds i8, i8* %14, i64 %16
store i8 0, i8* %17
%18 = load i8*, i8** %4
%19 = load i8*, i8** %6
%20 = load i64, i64* %5
%21 = sub i64 %20, 1
%22 = call i32 @readlink(i8* %18, i8* %19, i64 %21)
%23 = load i8*, i8** %6
%24 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %6
%26 = call i32 @free(i8* %25)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [6 x i8] c"-> %s\00"
define void @file__print_link_target(%struct.stat* nocapture %0, i8* nocapture %1) {
%3 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 0
%4 = load i64, i64* %3
%5 = add i64 %4, 1
%6 = tail call i64 @calloc(i32 1, i64 %5)
%7 = inttoptr i64 %6 to i8*
%8 = getelementptr inbounds i8, i8* %7, i64 %4
store i8 0, i8* %8
%9 = tail call i32 @readlink(i8* %1, i8* %7, i64 %4)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %7)
%11 = tail call i32 @free(i8* %7)
ret void
}