#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 ssize_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int PATH_MAX;
char *basename(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int readlink(char *, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int exit_status = EXIT_SUCCESS;
  for (int argi = 1; argi < argc; ++argi) {
    char *pathname = argv[argi];
    char linkname[PATH_MAX + 1];
    ssize_t retval = readlink(pathname, linkname, sizeof linkname);
    if (retval >= 0) {
      linkname[retval < PATH_MAX + 1 ? retval : PATH_MAX] = '\0';
      printf("%s -> \"%s\"\n", pathname, linkname);
    } else {
      exit_status = EXIT_FAILURE;
      fflush(NULL);
      fprintf(stderr, "%s: %s: %s\n", basename(argv[0]), pathname,
              strerror(errno));
      fflush(NULL);
    }
  }
  return exit_status;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12bb <main+0x15b>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x40(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
call   1030 <readlink@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     123c <main+0xdc>
mov    -0x34(%rbp),%eax
mov    0x2dfa(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    120e <main+0xae>
mov    -0x34(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    121a <main+0xba>
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rdx
mov    -0x44(%rbp),%eax
cltq
movb   $0x0,(%rdx,%rax,1)
mov    -0x20(%rbp),%rsi
lea    0xdce(%rip),%rdi
call   1040 <printf@plt>
jmp    12a6 <main+0x146>
mov    0x2d85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <fflush@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <basename@plt>
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    %rax,%r8
lea    0xd74(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <fflush@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1189 <main+0x29>
mov    -0x14(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,-0x38(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
cmp    $0x2,%edi
jl     1262 <main+0x102>
mov    %edi,%eax
mov    %rax,-0x40(%rbp)
mov    $0x1,%r14d
mov    0x2e53(%rip),%r13
jmp    1208 <main+0xa8>
nop
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
xor    %edi,%edi
call   1070 <fflush@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1060 <basename@plt>
mov    %rax,%r12
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x30(%rbp),%edi
lea    0xe26(%rip),%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1070 <fflush@plt>
mov    %r15,%rsp
add    $0x1,%r14
cmp    %r14,-0x40(%rbp)
je     1262 <main+0x102>
mov    %rsp,%r15
mov    -0x38(%rbp),%rax
mov    (%rax,%r14,8),%rbx
mov    0x0(%r13),%edx
add    $0x1,%edx
mov    %rsp,%r12
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <readlink@plt>
test   %eax,%eax
js     11a0 <main+0x40>
mov    0x0(%r13),%ecx
cmp    %ecx,%eax
cmovg  %ecx,%eax
cltq
movb   $0x0,(%r12,%rax,1)
lea    0xdab(%rip),%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <printf@plt>
jmp    11fb <main+0x9b>
mov    -0x2c(%rbp),%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@PATH_MAX = global i32 0
@.str = [12 x i8] c"%s -> \22%s\22\0A\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [12 x i8] c"%s: %s: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @EXIT_SUCCESS
store i32 %12, i32* %6
store i32 1, i32* %7
br label %13
13: ; preds = %63, %2
%14 = load i32, i32* %7
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %66
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
store i8* %22, i8** %8
%23 = load i32, i32* @PATH_MAX
%24 = add nsw i32 %23, 1
%25 = zext i32 %24 to i64
%26 = call i8* @llvm.stacksave()
store i8* %26, i8** %9
%27 = alloca i8, i64 %25
store i64 %25, i64* %10
%28 = load i8*, i8** %8
%29 = trunc i64 %25 to i32
%30 = call i32 @readlink(i8* %28, i8* %27, i32 %29)
store i32 %30, i32* %11
%31 = load i32, i32* %11
%32 = icmp sge i32 %31, 0
br i1 %32, label %33, label %48
33: ; preds = %17
%34 = load i32, i32* %11
%35 = load i32, i32* @PATH_MAX
%36 = add nsw i32 %35, 1
%37 = icmp slt i32 %34, %36
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = load i32, i32* %11
br label %42
40: ; preds = %33
%41 = load i32, i32* @PATH_MAX
br label %42
42: ; preds = %40, %38
%43 = phi i32 [ %39, %38 ], [ %41, %40 ]
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %27, i64 %44
store i8 0, i8* %45
%46 = load i8*, i8** %8
%47 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %46, i8* %27)
br label %61
48: ; preds = %17
%49 = load i32, i32* @EXIT_FAILURE
store i32 %49, i32* %6
%50 = call i32 @fflush(i32* null)
%51 = load i32, i32* @stderr
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 0
%54 = load i8*, i8** %53
%55 = call i8* @basename(i8* %54)
%56 = load i8*, i8** %8
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %55, i8* %56, i8* %58)
%60 = call i32 @fflush(i32* null)
br label %61
61: ; preds = %48, %42
%62 = load i8*, i8** %9
br label %63
63: ; preds = %61
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %13
66: ; preds = %13
%67 = load i32, i32* %6
ret i32 %67
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@PATH_MAX = global i32 0
@.str = [12 x i8] c"%s -> \22%s\22\0A\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [12 x i8] c"%s: %s: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @EXIT_SUCCESS
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = zext i32 %0 to i64
br label %9
7: ; preds = %38, %2
%8 = phi i32 [ %3, %2 ], [ %39, %38 ]
ret i32 %8
9: ; preds = %5, %38
%10 = phi i64 [ 1, %5 ], [ %40, %38 ]
%11 = phi i32 [ %3, %5 ], [ %39, %38 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %10
%13 = load i8*, i8** %12
%14 = load i32, i32* @PATH_MAX
%15 = add nsw i32 %14, 1
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
%18 = alloca i8, i64 %16
%19 = call i32 @readlink(i8* %13, i8* %18, i32 %15)
%20 = icmp sgt i32 %19, -1
br i1 %20, label %21, label %28
21: ; preds = %9
%22 = load i32, i32* @PATH_MAX
%23 = icmp sgt i32 %19, %22
%24 = select i1 %23, i32 %22, i32 %19
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %18, i64 %25
store i8 0, i8* %26
%27 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %18)
br label %38
28: ; preds = %9
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @fflush(i32* null)
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %1
%33 = call i8* @basename(i8* %32)
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* %13, i8* %35)
%37 = call i32 @fflush(i32* null)
br label %38
38: ; preds = %28, %21
%39 = phi i32 [ %11, %21 ], [ %29, %28 ]
%40 = add nuw nsw i64 %10, 1
%41 = icmp eq i64 %40, %6
br i1 %41, label %7, label %9
}