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

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int open_testfile(char *);
int readlink(char *, char *, int);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ report_test(int, int /*<<< orphan*/, int /*<<< orphan*/,
                               char *);
void readlink_file(void) {
  char buf[128];
  int fd, rv;
  fd = open_testfile("the question contains an invalid assumption");
  if (fd < 0) {
    return;
  }
  close(fd);
  rv = readlink("badcallfile", buf, sizeof(buf));
  report_test(rv, errno, EINVAL, "readlink on file");
  remove("badcallfile");
}


x86 assembly (clang, -O0):
<readlink_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    0xe9e(%rip),%rdi
call   1070 <open_testfile@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jge    117f <readlink_file+0x2f>
jmp    11d5 <readlink_file+0x85>
mov    -0x84(%rbp),%edi
call   1060 <close@plt>
lea    -0x80(%rbp),%rsi
lea    0xe97(%rip),%rdi
mov    $0x80,%edx
call   1050 <readlink@plt>
mov    %eax,-0x88(%rbp)
mov    -0x88(%rbp),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
lea    0xe74(%rip),%rcx
call   1030 <report_test@plt>
lea    0xe5c(%rip),%rdi
call   1040 <remove@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readlink_file>:
push   %rbx
sub    $0x80,%rsp
lea    0xea1(%rip),%rdi
call   1070 <open_testfile@plt>
test   %eax,%eax
js     11b6 <readlink_file+0x66>
mov    %eax,%edi
call   1060 <close@plt>
lea    0xeb6(%rip),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x80,%edx
call   1050 <readlink@plt>
mov    0x2e53(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e42(%rip),%rcx
mov    (%rcx),%edx
lea    0xe99(%rip),%rcx
mov    %eax,%edi
call   1030 <report_test@plt>
mov    %rbx,%rdi
add    $0x80,%rsp
pop    %rbx
jmp    1040 <remove@plt>
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [44 x i8] c"the question contains an invalid assumption\00"
@.str.1 = [12 x i8] c"badcallfile\00"
@errno = global i32 0
@EINVAL = global i32 0
@.str.2 = [17 x i8] c"readlink on file\00"
define void @readlink_file() {
%1 = alloca [128 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @open_testfile(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %0
br label %18
8: ; preds = %0
%9 = load i32, i32* %2
%10 = call i32 @close(i32 %9)
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%12 = call i32 @readlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 128)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = load i32, i32* @errno
%15 = load i32, i32* @EINVAL
%16 = call i32 @report_test(i32 %13, i32 %14, i32 %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @remove(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %8, %7
ret void
}

LLVM IR (-O2):
@.str = [44 x i8] c"the question contains an invalid assumption\00"
@.str.1 = [12 x i8] c"badcallfile\00"
@errno = global i32 0
@EINVAL = global i32 0
@.str.2 = [17 x i8] c"readlink on file\00"
define void @readlink_file() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @open_testfile(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%4 = icmp slt i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = tail call i32 @close(i32 %3)
%7 = call i32 @readlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 128)
%8 = load i32, i32* @errno
%9 = load i32, i32* @EINVAL
%10 = tail call i32 @report_test(i32 %7, i32 %8, i32 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @remove(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %0, %5
ret void
}