#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 change_link(char *);
int check_exists_dir(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int strlen(char *);
int change_version(char *version) {
  char *buffer;
  int value;
  buffer = (char *)malloc(
      sizeof(char) *
      (strlen("/Library/Java/JavaVirtualMachines") + strlen(version) + 2));
  sprintf(buffer, "%s/%s", "/Library/Java/JavaVirtualMachines", version);
  value = check_exists_dir(buffer);
  if (value == -1) {
    printf("%s: unavailable version\n", version);
  } else if (value == 1) {
    printf("%s: initialization error\n", version);
  } else if (value == 0) {
    value = change_link(buffer);
  }
  free(buffer);
  return value;
}


x86 assembly (clang, -O0):
<change_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe7d(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rcx
lea    0xe64(%rip),%rsi
lea    0xe3b(%rip),%rdx
call   1080 <sprintf@plt>
mov    -0x10(%rbp),%rdi
call   1090 <check_exists_dir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11f5 <change_version+0x85>
mov    -0x8(%rbp),%rsi
lea    0xe3d(%rip),%rdi
call   1060 <printf@plt>
jmp    1234 <change_version+0xc4>
cmpl   $0x1,-0x14(%rbp)
jne    1214 <change_version+0xa4>
mov    -0x8(%rbp),%rsi
lea    0xe37(%rip),%rdi
call   1060 <printf@plt>
jmp    122f <change_version+0xbf>
cmpl   $0x0,-0x14(%rbp)
jne    122a <change_version+0xba>
mov    -0x10(%rbp),%rdi
call   1040 <change_link@plt>
mov    %eax,-0x14(%rbp)
jmp    122f <change_version+0xbf>
jmp    1234 <change_version+0xc4>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_version>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe82(%rip),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe7d(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
mov    %r14,%rcx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1090 <check_exists_dir@plt>
cmp    $0x1,%eax
je     11e1 <change_version+0x71>
mov    %eax,%ebp
test   %eax,%eax
je     11f7 <change_version+0x87>
cmp    $0xffffffff,%ebp
jne    1201 <change_version+0x91>
lea    0xe56(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
mov    $0xffffffff,%ebp
jmp    1201 <change_version+0x91>
lea    0xe59(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
mov    $0x1,%ebp
jmp    1201 <change_version+0x91>
mov    %rbx,%rdi
call   1040 <change_link@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"/Library/Java/JavaVirtualMachines\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [25 x i8] c"%s: unavailable version\0A\00"
@.str.3 = [26 x i8] c"%s: initialization error\0A\00"
define i32 @change_version(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 @strlen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = add nsw i32 %5, %7
%9 = add nsw i32 %8, 2
%10 = sext i32 %9 to i64
%11 = mul i64 1, %10
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %3
%15 = load i8*, i8** %3
%16 = load i8*, i8** %2
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %3
%19 = call i32 @check_exists_dir(i8* %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %1
%23 = load i8*, i8** %2
%24 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %39
25: ; preds = %1
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i8*, i8** %2
%30 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %29)
br label %38
31: ; preds = %25
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i8*, i8** %3
%36 = call i32 @change_link(i8* %35)
store i32 %36, i32* %4
br label %37
37: ; preds = %34, %31
br label %38
38: ; preds = %37, %28
br label %39
39: ; preds = %38, %22
%40 = load i8*, i8** %3
%41 = call i32 @free(i8* %40)
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
@.str = [34 x i8] c"/Library/Java/JavaVirtualMachines\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [25 x i8] c"%s: unavailable version\0A\00"
@.str.3 = [26 x i8] c"%s: initialization error\0A\00"
define i32 @change_version(i8* %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @strlen(i8* %0)
%4 = add i32 %2, 2
%5 = add i32 %4, %3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = tail call i32 @check_exists_dir(i8* %7)
switch i32 %9, label %16 [
i32 -1, label %10
i32 1, label %12
i32 0, label %14
]
10: ; preds = %1
%11 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %16
12: ; preds = %1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %16
14: ; preds = %1
%15 = tail call i32 @change_link(i8* %7)
br label %16
16: ; preds = %1, %12, %14, %10
%17 = phi i32 [ -1, %10 ], [ 1, %12 ], [ %15, %14 ], [ %9, %1 ]
%18 = tail call i32 @free(i8* %7)
ret i32 %17
}