#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 */
scalar_t__ EACCES;
scalar_t__ errno;
int readlink(char *, char *, size_t);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
char *strerror(scalar_t__);
int /*<<< orphan*/ write_message(char *, int);
size_t linktarget(char *s_link, char *s_buffer, size_t buffer_len) {
  int pos;
  pos = readlink(s_link, s_buffer, buffer_len);
  if (0 > pos && errno != EACCES) {
    char s_message[512];
    snprintf(s_message, 512, "ERROR: while resolving softs_link \"%s\", \"%s\"",
             s_link, strerror(errno));
    write_message(s_message, 3);
  }
  if (0 > pos)
    return pos;
  s_buffer[pos] = '\0';
  return pos;
}


x86 assembly (clang, -O0):
<linktarget>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <readlink@plt>
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
cmp    -0x24(%rbp),%eax
jle    11eb <linktarget+0xab>
mov    0x2e5b(%rip),%rax
mov    (%rax),%rax
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%rax
je     11eb <linktarget+0xab>
lea    -0x230(%rbp),%rax
mov    %rax,-0x240(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x238(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x240(%rbp),%rdi
mov    -0x238(%rbp),%rcx
mov    %rax,%r8
mov    $0x200,%esi
lea    0xe2b(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x230(%rbp),%rdi
mov    $0x3,%esi
call   1050 <write_message@plt>
xor    %eax,%eax
cmp    -0x24(%rbp),%eax
jle    1203 <linktarget+0xc3>
movslq -0x24(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1217 <linktarget+0xd7>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movslq -0x24(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linktarget>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <readlink@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1164 <linktarget+0x24>
mov    %ebp,%eax
movb   $0x0,(%rbx,%rax,1)
jmp    11ac <linktarget+0x6c>
mov    0x2e6d(%rip),%rax
mov    (%rax),%rdi
mov    0x2e73(%rip),%rax
cmp    (%rax),%rdi
je     11a9 <linktarget+0x69>
call   1060 <strerror@plt>
lea    0xe7a(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r14,%rcx
mov    %rax,%r8
call   1040 <snprintf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1050 <write_message@plt>
movslq %ebp,%rax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EACCES = global i64 0
@.str = [45 x i8] c"ERROR: while resolving softs_link \22%s\22, \22%s\22\00"
define i64 @linktarget(i8* %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca [512 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i8*, i8** %5
%11 = load i8*, i8** %6
%12 = load i64, i64* %7
%13 = call i32 @readlink(i8* %10, i8* %11, i64 %12)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp sgt i32 0, %14
br i1 %15, label %16, label %28
16: ; preds = %3
%17 = load i64, i64* @errno
%18 = load i64, i64* @EACCES
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%22 = load i8*, i8** %5
%23 = load i64, i64* @errno
%24 = call i8* @strerror(i64 %23)
%25 = call i32 @snprintf(i8* %21, i32 512, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %24)
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%27 = call i32 @write_message(i8* %26, i32 3)
br label %28
28: ; preds = %20, %16, %3
%29 = load i32, i32* %8
%30 = icmp sgt i32 0, %29
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
store i64 %33, i64* %4
br label %41
34: ; preds = %28
%35 = load i8*, i8** %6
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
store i64 %40, i64* %4
br label %41
41: ; preds = %34, %31
%42 = load i64, i64* %4
ret i64 %42
}

LLVM IR (-O2):
@errno = global i64 0
@EACCES = global i64 0
@.str = [45 x i8] c"ERROR: while resolving softs_link \22%s\22, \22%s\22\00"
define i64 @linktarget(i8* %0, i8* nocapture %1, i64 %2) {
%4 = alloca [512 x i8]
%5 = tail call i32 @readlink(i8* %0, i8* %1, i64 %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %3
%8 = load i64, i64* @errno
%9 = load i64, i64* @EACCES
%10 = icmp eq i64 %8, %9
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%13 = tail call i8* @strerror(i64 %8)
%14 = call i32 @snprintf(i8* %12, i32 512, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %13)
%15 = call i32 @write_message(i8* %12, i32 3)
br label %16
16: ; preds = %7, %11
%17 = sext i32 %5 to i64
br label %21
18: ; preds = %3
%19 = zext i32 %5 to i64
%20 = getelementptr inbounds i8, i8* %1, i64 %19
store i8 0, i8* %20
br label %21
21: ; preds = %18, %16
%22 = phi i64 [ %17, %16 ], [ %19, %18 ]
ret i64 %22
}