#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ readlink(char *, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char buf[2048];
  int bytes;
  if (argc != 2) {
    fputs("Usage: rl <symlink>\n", stderr);
    return 1;
  }
  memset(buf, 0, 2048);
  bytes = (int)readlink(*++argv, buf, 2048);
  if (bytes == -1) {
    perror("rl");
    return 1;
  } else if (bytes == 2048) {
    fprintf(stderr, "rl: too long\n");
    return 1;
  } else {
    printf("%s\n", buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a4 <main+0x44>
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
lea    0xe6d(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    1256 <main+0xf6>
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    -0x810(%rbp),%rsi
mov    $0x800,%edx
call   1030 <readlink@plt>
mov    %eax,-0x814(%rbp)
cmpl   $0xffffffff,-0x814(%rbp)
jne    1206 <main+0xa6>
lea    0xe20(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1256 <main+0xf6>
cmpl   $0x800,-0x814(%rbp)
jne    1237 <main+0xd7>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1256 <main+0xf6>
lea    -0x810(%rbp),%rsi
lea    0xde1(%rip),%rdi
call   1040 <printf@plt>
jmp    124f <main+0xef>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x808,%rsp
cmp    $0x2,%edi
jne    11b4 <main+0x54>
mov    %rsi,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
mov    $0x800,%edx
call   1030 <readlink@plt>
cmp    $0x800,%eax
je     11cb <main+0x6b>
cmp    $0xffffffff,%eax
je     11f0 <main+0x90>
lea    0xe7e(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
jmp    11e5 <main+0x85>
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
lea    0xe3c(%rip),%rdi
call   1050 <fputs@plt>
jmp    11e0 <main+0x80>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe1e(%rip),%rdi
call   1080 <perror@plt>
jmp    11e0 <main+0x80>

LLVM IR (-O0):
@.str = [21 x i8] c"Usage: rl <symlink>\0A\00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"rl\00"
@.str.2 = [14 x i8] c"rl: too long\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2048 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fputs(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 1, i32* %3
br label %37
13: ; preds = %2
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 2048)
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i32 1
store i8** %17, i8*** %5
%18 = load i8*, i8** %17
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%20 = call i64 @readlink(i8* %18, i8* %19, i32 2048)
%21 = trunc i64 %20 to i32
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %13
%25 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %37
26: ; preds = %13
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, 2048
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %37
32: ; preds = %26
%33 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %32
br label %36
36: ; preds = %35
store i32 0, i32* %3
br label %37
37: ; preds = %36, %29, %24, %10
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [21 x i8] c"Usage: rl <symlink>\0A\00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"rl\00"
@.str.2 = [14 x i8] c"rl: too long\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fputs(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %22
9: ; preds = %2
%10 = call i32 @memset(i8* %4, i32 0, i32 2048)
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @readlink(i8* %12, i8* %4, i32 2048)
%14 = trunc i64 %13 to i32
switch i32 %14, label %20 [
i32 -1, label %15
i32 2048, label %17
]
15: ; preds = %9
%16 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %22
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %22
20: ; preds = %9
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %22
22: ; preds = %20, %17, %15, %6
%23 = phi i32 [ 1, %6 ], [ 1, %15 ], [ 1, %17 ], [ 0, %20 ]
ret i32 %23
}