#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ PATH_MAX;
int /*<<< orphan*/ _ls_error(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char *);
int readlink(char const *, char *, int);
void _print_link(char const *filename) {
  char buf[PATH_MAX + 1];
  int len;
  if ((len = readlink(filename, buf, sizeof(buf) - 1)) == -1) {
    _ls_error(filename, 0);
    return;
  }
  buf[len] = '\0';
  printf("%s%s", " -> ", buf);
}


x86 assembly (clang, -O0):
<_print_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x28(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
sub    $0x1,%rax
mov    %eax,%edx
call   1030 <readlink@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    119d <_print_link+0x6d>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <_ls_error@plt>
movl   $0x1,-0x20(%rbp)
jmp    11c3 <_print_link+0x93>
mov    -0x28(%rbp),%rdx
movslq -0x1c(%rbp),%rax
movb   $0x0,(%rdx,%rax,1)
lea    0xe50(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_print_link>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2eaf(%rip),%rax
mov    (%rax),%edx
lea    0x1(%rdx),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rsi
call   1030 <readlink@plt>
cmp    $0xffffffff,%eax
je     1189 <_print_link+0x59>
cltq
movb   $0x0,(%rbx,%rax,1)
lea    0xe8f(%rip),%rdi
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdx
call   1040 <printf@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14,%rdi
xor    %esi,%esi
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <_ls_error@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [5 x i8] c" -> \00"
define void @_print_link(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i32, i32* @PATH_MAX
%8 = add nsw i32 %7, 1
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i8, i64 %9
store i64 %9, i64* %4
%12 = load i8*, i8** %2
%13 = sub i64 %9, 1
%14 = trunc i64 %13 to i32
%15 = call i32 @readlink(i8* %12, i8* %11, i32 %14)
store i32 %15, i32* %5
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = load i8*, i8** %2
%19 = call i32 @_ls_error(i8* %18, i32 0)
store i32 1, i32* %6
br label %25
20: ; preds = %1
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %11, i64 %22
store i8 0, i8* %23
%24 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %11)
store i32 0, i32* %6
br label %25
25: ; preds = %20, %17
%26 = load i8*, i8** %3
%27 = load i32, i32* %6
switch i32 %27, label %29 [
i32 0, label %28
i32 1, label %28
]
28: ; preds = %25, %25
ret void
29: ; preds = %25
unreachable
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [5 x i8] c" -> \00"
define void @_print_link(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @readlink(i8* %0, i8* %5, i32 %2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @_ls_error(i8* %0, i32 0)
br label %14
10: ; preds = %1
%11 = sext i32 %6 to i64
%12 = getelementptr inbounds i8, i8* %5, i64 %11
store i8 0, i8* %12
%13 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %14
14: ; preds = %10, %8
ret void
}