#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 *, int *, int);
int symlink(char *, char *);
int /*<<< orphan*/ unlink(char *);
main() {
  int 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    $0x30,%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,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1185 <main+0x45>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    -0x20(%rbp),%rsi
lea    0xe70(%rip),%rdi
mov    $0x1c,%edx
call   1040 <readlink@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%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
sub    $0x28,%rsp
lea    0xeb3(%rip),%rbx
mov    %rbx,%rdi
call   1030 <unlink@plt>
lea    0xeaf(%rip),%rdi
mov    %rbx,%rsi
call   1050 <symlink@plt>
cmp    $0xffffffff,%eax
je     118f <main+0x4f>
lea    0xe90(%rip),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x1c,%edx
call   1040 <readlink@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%ebp
jne    1199 <main+0x59>
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 i32]
%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 i32], [7 x i32]* %2, i64 0, i64 0
%13 = call i32 @readlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* %12, i32 28)
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 i32]
%2 = bitcast [7 x i32]* %1 to i8*
%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 = getelementptr inbounds [7 x i32], [7 x i32]* %1, i64 0, i64 0
%10 = call i32 @readlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* %9, i32 28)
%11 = icmp eq i32 %10, -1
%12 = tail call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br i1 %11, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %8
%16 = tail call i32 @exit(i32 0)
unreachable
}