#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 */
struct ospfs_inode {
  int dummy;
};
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ addsymlink(struct ospfs_inode *, char const *, char *,
                              unsigned long, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ perror(char *);
int readlink(char const *, char *, int);
int /*<<< orphan*/ stderr;
void writesymlink(struct ospfs_inode *dirino, const char *name,
                  unsigned long host_ino, int indent) {
  char linkbuf[(64 - 13) + 1];
  ssize_t linklen;
  if ((linklen = readlink(name, linkbuf, (64 - 13) + 1)) == -1) {
    fprintf(stderr, "readlink %s:", name);
    perror("");
    abort();
  } else if (linklen > (64 - 13)) {
    fprintf(stderr, "readlink %s: symlink name too long, ignored\n", name);
    return;
  }
  linkbuf[linklen] = '\0';
  addsymlink(dirino, name, linkbuf, host_ino, indent);
}


x86 assembly (clang, -O0):
<writesymlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x34,%edx
call   1040 <readlink@plt>
mov    %eax,-0x54(%rbp)
cmp    $0xffffffff,%eax
jne    11b1 <writesymlink+0x61>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe67(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe94(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
cmpl   $0x33,-0x54(%rbp)
jle    11d9 <writesymlink+0x89>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe3e(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1200 <writesymlink+0xb0>
jmp    11de <writesymlink+0x8e>
movslq -0x54(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x50(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
call   1050 <addsymlink@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writesymlink>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x34,%edx
call   1040 <readlink@plt>
cmp    $0xffffffff,%eax
je     11c7 <writesymlink+0x77>
cmp    $0x34,%eax
jl     11a2 <writesymlink+0x52>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdx
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fprintf@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rcx
mov    %r14d,%r8d
call   1050 <addsymlink@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
lea    0xe53(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.ospfs_inode = type { i32 }
@stderr = global i32 0
@.str = [13 x i8] c"readlink %s:\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [45 x i8] c"readlink %s: symlink name too long, ignored\0A\00"
define void @writesymlink(%struct.ospfs_inode* %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca %struct.ospfs_inode*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca [52 x i8]
%10 = alloca i32
store %struct.ospfs_inode* %0, %struct.ospfs_inode** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 %3, i32* %8
%11 = load i8*, i8** %6
%12 = getelementptr inbounds [52 x i8], [52 x i8]* %9, i64 0, i64 0
%13 = call i32 @readlink(i8* %11, i8* %12, i32 52)
store i32 %13, i32* %10
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %4
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %6
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 (...) @abort()
unreachable
21: ; preds = %4
%22 = load i32, i32* %10
%23 = icmp sgt i32 %22, 51
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %6
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %39
28: ; preds = %21
br label %29
29: ; preds = %28
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [52 x i8], [52 x i8]* %9, i64 0, i64 %31
store i8 0, i8* %32
%33 = load %struct.ospfs_inode*, %struct.ospfs_inode** %5
%34 = load i8*, i8** %6
%35 = getelementptr inbounds [52 x i8], [52 x i8]* %9, i64 0, i64 0
%36 = load i64, i64* %7
%37 = load i32, i32* %8
%38 = call i32 @addsymlink(%struct.ospfs_inode* %33, i8* %34, i8* %35, i64 %36, i32 %37)
br label %39
39: ; preds = %29, %24
ret void
}

LLVM IR (-O2):
%struct.ospfs_inode = type { i32 }
@stderr = global i32 0
@.str = [13 x i8] c"readlink %s:\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [45 x i8] c"readlink %s: symlink name too long, ignored\0A\00"
define void @writesymlink(%struct.ospfs_inode* %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca [52 x i8]
%6 = getelementptr inbounds [52 x i8], [52 x i8]* %5, i64 0, i64 0
%7 = call i32 @readlink(i8* %1, i8* %6, i32 52)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %1)
%12 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 (...) @abort()
unreachable
14: ; preds = %4
%15 = icmp sgt i32 %7, 51
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %23
19: ; preds = %14
%20 = sext i32 %7 to i64
%21 = getelementptr inbounds [52 x i8], [52 x i8]* %5, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i32 @addsymlink(%struct.ospfs_inode* %0, i8* %1, i8* %6, i64 %2, i32 %3)
br label %23
23: ; preds = %19, %16
ret void
}