#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 */
int MAXPATHLEN;
int /*<<< orphan*/ perror(char *);
int readlink(char *, char *, int);
scalar_t__ strcmp(char *, char *);
int check_link() {
  char buffer[MAXPATHLEN + 1];
  int size;
  size = readlink(
      "/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands",
      buffer, MAXPATHLEN + 1);
  if (size < 0) {
    perror("readlink");
    return -1;
  }
  if (strcmp(buffer, "/System/Library/Frameworks/JavaVM.framework/Versions/"
                     "CurrentJDK/Contents/Home/bin") == 0 ||
      strcmp(buffer, "../CurrentJDK/Contents/Home/bin") == 0) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x28(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
add    $0x1,%edx
lea    0xe86(%rip),%rdi
call   1030 <readlink@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11ab <check_link+0x7b>
lea    0xeb3(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x20(%rbp)
jmp    1200 <check_link+0xd0>
mov    -0x28(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11df <check_link+0xaf>
mov    -0x28(%rbp),%rdi
lea    0xed1(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11f2 <check_link+0xc2>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x20(%rbp)
jmp    1200 <check_link+0xd0>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_link>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    0x2eab(%rip),%rax
mov    (%rax),%edx
add    $0x1,%edx
mov    %rsp,%rbx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xea6(%rip),%rdi
mov    %rbx,%rsi
call   1030 <readlink@plt>
test   %eax,%eax
js     11a2 <check_link+0x72>
lea    0xee2(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1196 <check_link+0x66>
lea    0xf20(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    119b <check_link+0x6b>
mov    $0x1,%eax
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe9d(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    119b <check_link+0x6b>

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@.str = [70 x i8] c"/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands\00"
@.str.1 = [9 x i8] c"readlink\00"
@.str.2 = [82 x i8] c"/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Contents/Home/bin\00"
@.str.3 = [32 x i8] c"../CurrentJDK/Contents/Home/bin\00"
define i32 @check_link() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = load i32, i32* @MAXPATHLEN
%7 = add nsw i32 %6, 1
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %2
%10 = alloca i8, i64 %8
store i64 %8, i64* %3
%11 = load i32, i32* @MAXPATHLEN
%12 = add nsw i32 %11, 1
%13 = call i32 @readlink(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
store i32 1, i32* %5
br label %26
18: ; preds = %0
%19 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21, %18
store i32 1, i32* %1
store i32 1, i32* %5
br label %26
25: ; preds = %21
store i32 0, i32* %1
store i32 1, i32* %5
br label %26
26: ; preds = %25, %24, %16
%27 = load i8*, i8** %2
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@.str = [70 x i8] c"/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands\00"
@.str.1 = [9 x i8] c"readlink\00"
@.str.2 = [82 x i8] c"/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Contents/Home/bin\00"
@.str.3 = [32 x i8] c"../CurrentJDK/Contents/Home/bin\00"
define i32 @check_link() {
%1 = load i32, i32* @MAXPATHLEN
%2 = add nsw i32 %1, 1
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @readlink(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %16
9: ; preds = %0
%10 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %12, %9, %7
%17 = phi i32 [ -1, %7 ], [ 1, %9 ], [ %15, %12 ]
ret i32 %17
}