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

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
size_t readlink(char *, char *, int);
int main(void) {
  char sympath[] = "/data/dev";
  ssize_t size;
  char buf[1024];
  if ((size = readlink(sympath, buf, 1024)) < 0) {
    printf("readlink error for %s\n", sympath);
    perror("error");
    return 1;
  } else {
    buf[size] = '\0';
    printf("%s\n", buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0xe(%rbp)
mov    0xeb4(%rip),%ax
mov    %ax,-0x6(%rbp)
lea    -0xe(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1030 <readlink@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jae    11a3 <main+0x73>
lea    -0xe(%rbp),%rsi
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8f(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c9 <main+0x99>
mov    -0x18(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rsi
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x410,%rsp
movabs $0x65642f617461642f,%rax
2f 64 65
mov    %rax,(%rsp)
movw   $0x76,0x8(%rsp)
mov    %rsp,%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x400,%edx
call   1030 <readlink@plt>
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xeac(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.sympath = [10 x i8] c"/data/dev\00"
@.str = [23 x i8] c"readlink error for %s\0A\00"
@.str.1 = [6 x i8] c"error\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i64
%4 = alloca [1024 x i8]
store i32 0, i32* %1
%5 = bitcast [10 x i8]* %2 to i8*
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = call i64 @readlink(i8* %6, i8* %7, i32 1024)
store i64 %8, i64* %3
%9 = icmp ult i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%12 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %20
14: ; preds = %0
%15 = load i64, i64* %3
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %15
store i8 0, i8* %16
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %14
store i32 0, i32* %1
br label %20
20: ; preds = %19, %10
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@__const.main.sympath = [10 x i8] c"/data/dev\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = call i64 @readlink(i8* %3, i8* %4, i32 1024)
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %5
store i8 0, i8* %6
%7 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4)
ret i32 0
}