#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int PATH_MAX;
int /*<<< orphan*/ SYS_readlink;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int syscall(int /*<<< orphan*/, char *, char *, int);
int main(int argc, char *argv[]) {
  char path[PATH_MAX];
  int status;
  if (argc != 2) {
    fprintf(stderr, "usage: readlink FILE\n");
    exit(EXIT_FAILURE);
  }
  status = syscall(SYS_readlink, argv[1], path, PATH_MAX);
  if (status < 0) {
    perror("readlink()");
    exit(EXIT_FAILURE);
  }
  path[status] = '\0';
  puts(path);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11bf <main+0x6f>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x30(%rbp),%rdx
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    0x2e15(%rip),%rax
mov    (%rax),%ecx
call   1050 <syscall@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1209 <main+0xb9>
lea    0xe20(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x30(%rbp),%rdi
movslq -0x24(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
call   1030 <puts@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    0x2e93(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
lea    0xf(%rcx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x2,%edi
jne    119c <main+0x4c>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsi),%rsi
mov    %rbx,%rdx
call   1050 <syscall@plt>
test   %eax,%eax
jns    11bf <main+0x6f>
lea    0xe81(%rip),%rdi
call   1060 <perror@plt>
jmp    11b1 <main+0x61>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"usage: readlink FILE\0A\00"
@EXIT_FAILURE = global i32 0
@SYS_readlink = global i32 0
@.str.1 = [11 x i8] c"readlink()\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i32, i32* @SYS_readlink
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @PATH_MAX
%26 = call i32 @syscall(i32 %21, i8* %24, i8* %12, i32 %25)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %20
%30 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %20
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %12, i64 %35
store i8 0, i8* %36
%37 = call i32 @puts(i8* %12)
%38 = load i32, i32* @EXIT_SUCCESS
%39 = call i32 @exit(i32 %38)
unreachable
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"usage: readlink FILE\0A\00"
@EXIT_FAILURE = global i32 0
@SYS_readlink = global i32 0
@.str.1 = [11 x i8] c"readlink()\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp eq i32 %0, 2
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = load i32, i32* @SYS_readlink
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @syscall(i32 %13, i8* %15, i8* %5, i32 %3)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %12
%23 = zext i32 %16 to i64
%24 = getelementptr inbounds i8, i8* %5, i64 %23
store i8 0, i8* %24
%25 = call i32 @puts(i8* %5)
%26 = load i32, i32* @EXIT_SUCCESS
%27 = call i32 @exit(i32 %26)
unreachable
}