#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 MAXPATHLEN;
int /*<<< orphan*/ printf(char *, char *);
int readlink(char *, char *, int);
int /*<<< orphan*/ warn(char *, char *);
void printlink(char *name) {
  int lnklen;
  char path[MAXPATHLEN];
  if ((lnklen = readlink(name, path, MAXPATHLEN - 1)) == -1) {
    warn("%s", name);
    return;
  }
  path[lnklen] = '\0';
  (void)printf(" -> %s", path);
}


x86 assembly (clang, -O0):
<printlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x30(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
call   1040 <readlink@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    11a5 <printlink+0x75>
mov    -0x8(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1030 <warn@plt>
movl   $0x1,-0x24(%rbp)
jmp    11c4 <printlink+0x94>
mov    -0x30(%rbp),%rsi
movslq -0xc(%rbp),%rax
movb   $0x0,(%rsi,%rax,1)
lea    0xe48(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printlink>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2ea7(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
lea    -0x1(%rax),%edx
mov    %rbx,%rsi
call   1040 <readlink@plt>
cmp    $0xffffffff,%eax
je     1185 <printlink+0x55>
cltq
movb   $0x0,(%rbx,%rax,1)
lea    0xe8c(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe78(%rip),%rdi
mov    %r14,%rsi
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <warn@plt>

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

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