#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 int ssize_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int readlink(char *, char *, int);
int symlink(char *, char *);
int /*<<< orphan*/ unlink(char *);
int main(void) {
  char buf[7];
  int ret;
  ssize_t rl_ret;
  unlink("rdlnk.file");
  ret = symlink("readlink.test", "rdlnk.file");
  if (ret == -1) {
    exit(1);
  }
  rl_ret = readlink("rdlnk.file", buf, sizeof(buf));
  if (rl_ret == -1) {
    unlink("rdlnk.file");
    exit(1);
  }
  unlink("rdlnk.file");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <unlink@plt>
lea    0xea9(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1050 <symlink@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1185 <main+0x45>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    -0xb(%rbp),%rsi
lea    0xe70(%rip),%rdi
mov    $0x7,%edx
call   1040 <readlink@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11bd <main+0x7d>
lea    0xe52(%rip),%rdi
call   1030 <unlink@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe3c(%rip),%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rbx
mov    %rbx,%rdi
call   1030 <unlink@plt>
lea    0xeb2(%rip),%rdi
mov    %rbx,%rsi
call   1050 <symlink@plt>
cmp    $0xffffffff,%eax
je     118e <main+0x4e>
lea    0xe93(%rip),%rbx
lea    0x1(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1040 <readlink@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%ebp
jne    1198 <main+0x58>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"rdlnk.file\00"
@.str.1 = [14 x i8] c"readlink.test\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [7 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @symlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%13 = call i32 @readlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %12, i32 7)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %11
%20 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"rdlnk.file\00"
@.str.1 = [14 x i8] c"readlink.test\00"
define i32 @main() {
%1 = alloca [7 x i8]
%2 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @symlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = call i32 @readlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %2, i32 7)
%10 = icmp eq i32 %9, -1
%11 = tail call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br i1 %10, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8
%15 = tail call i32 @exit(i32 0)
unreachable
}