#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__ EEXIST;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int readlink(char *, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int symlink(char *, char *);
scalar_t__ unlink(char *);
void test_vfs_symlink_basic(void) {
  char *buff = malloc(1024);
  assert(symlink("Hello, world!", "/tmp"
                                  "/testlink") == 0);
  assert(readlink("/tmp"
                  "/testlink",
                  buff, 1024) == 13);
  assert(!strcmp("Hello, world!", buff));
  memset(buff, 0, 13);
  assert(readlink("/tmp"
                  "/testlink",
                  buff, 5) == 5);
  assert(!strcmp("Hello", buff));
  assert(symlink("Hello, world!", "/tmp"
                                  "/testlink") == -1 &&
         errno == EEXIST);
  assert(unlink("/tmp"
                "/testlink") == 0);
  free(buff);
}


x86 assembly (clang, -O0):
<test_vfs_symlink_basic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x400,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x8(%rbp)
lea    0xe63(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1060 <symlink@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x8(%rbp),%rsi
lea    0xe4a(%rip),%rdi
mov    $0x400,%edx
call   1050 <readlink@plt>
cmp    $0xd,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x8(%rbp),%rsi
lea    0xe17(%rip),%rdi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%rsi
lea    0xdf3(%rip),%rdi
mov    $0x5,%edx
call   1050 <readlink@plt>
cmp    $0x5,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x8(%rbp),%rsi
lea    0xddc(%rip),%rdi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
lea    0xda2(%rip),%rdi
lea    0xda9(%rip),%rsi
call   1060 <symlink@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x9(%rbp)
jne    1294 <test_vfs_symlink_basic+0x114>
mov    0x2d57(%rip),%rax
mov    (%rax),%rax
mov    0x2d55(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
lea    0xd66(%rip),%rdi
call   1040 <unlink@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_vfs_symlink_basic>:
push   %r15
push   %r14
push   %rbx
mov    $0x400,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
lea    0xe67(%rip),%r15
lea    0xe6e(%rip),%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <symlink@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <readlink@plt>
xor    %edi,%edi
cmp    $0xd,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <strcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1090 <assert@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1070 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
call   1050 <readlink@plt>
xor    %edi,%edi
cmp    $0x5,%eax
sete   %dil
call   1090 <assert@plt>
lea    0xdfa(%rip),%rdi
mov    %rbx,%rsi
call   1080 <strcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <symlink@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    0x2d89(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2d87(%rip),%rdx
cmp    (%rdx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1090 <assert@plt>
mov    %r14,%rdi
call   1040 <unlink@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1090 <assert@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Hello, world!\00"
@.str.1 = [14 x i8] c"/tmp/testlink\00"
@.str.2 = [6 x i8] c"Hello\00"
@errno = global i64 0
@EEXIST = global i64 0
define void @test_vfs_symlink_basic() {
%1 = alloca i8*
%2 = call i8* @malloc(i32 1024)
store i8* %2, i8** %1
%3 = call i32 @symlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
%5 = zext i1 %4 to i32
%6 = call i32 @assert(i32 %5)
%7 = load i8*, i8** %1
%8 = call i32 @readlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %7, i32 1024)
%9 = icmp eq i32 %8, 13
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8*, i8** %1
%13 = call i32 @strcmp(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i8*, i8** %1
%19 = call i32 @memset(i8* %18, i32 0, i32 13)
%20 = load i8*, i8** %1
%21 = call i32 @readlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32 5)
%22 = icmp eq i32 %21, 5
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i8*, i8** %1
%26 = call i32 @strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = call i32 @symlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %0
%34 = load i64, i64* @errno
%35 = load i64, i64* @EEXIST
%36 = icmp eq i64 %34, %35
br label %37
37: ; preds = %33, %0
%38 = phi i1 [ false, %0 ], [ %36, %33 ]
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = call i64 @unlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
%43 = zext i1 %42 to i32
%44 = call i32 @assert(i32 %43)
%45 = load i8*, i8** %1
%46 = call i32 @free(i8* %45)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"Hello, world!\00"
@.str.1 = [14 x i8] c"/tmp/testlink\00"
@.str.2 = [6 x i8] c"Hello\00"
@errno = global i64 0
@EEXIST = global i64 0
define void @test_vfs_symlink_basic() {
%1 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%2 = tail call i32 @symlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32 %2, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 @readlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 1024)
%7 = icmp eq i32 %6, 13
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @strcmp(i8* dereferenceable(14) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* dereferenceable(1) %1)
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i32 @memset(i8* %1, i32 0, i32 13)
%15 = tail call i32 @readlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 5)
%16 = icmp eq i32 %15, 5
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = tail call i32 @strcmp(i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* dereferenceable(1) %1)
%20 = icmp eq i32 %19, 0
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = tail call i32 @symlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i32 %23, -1
%25 = load i64, i64* @errno
%26 = load i64, i64* @EEXIST
%27 = icmp eq i64 %25, %26
%28 = select i1 %24, i1 %27, i1 false
%29 = zext i1 %28 to i32
%30 = tail call i32 @assert(i32 %29)
%31 = tail call i64 @unlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
%33 = zext i1 %32 to i32
%34 = tail call i32 @assert(i32 %33)
%35 = tail call i32 @free(i8* %1)
ret void
}