#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 /*<<< orphan*/ S_IFLNK;
int backup_commands_dir();
int check_exists(char *, int /*<<< orphan*/);
int check_link();
int /*<<< orphan*/ create_symlink_for_commands();
int /*<<< orphan*/ printf(char *, ...);
int init_env() {
  int return_value = 0;
  int commands_dir = check_exists(
      "/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands",
      S_IFLNK);
  if (commands_dir == -1) {
    create_symlink_for_commands();
    printf("preparation is done.\n");
  } else if (commands_dir == 0) {
    int flag = backup_commands_dir();
    if (flag == 0) {
      printf("back up of Command dir is failed\n");
      return 0;
    }
    create_symlink_for_commands();
    printf("preparation is done.\n");
    return_value = 1;
  } else if (commands_dir == 1) {
    int flag = check_link();
    if (flag == 0) {
      printf("invalid link at %s\n",
             "/System/Library/Frameworks/JavaVM.framework/Versions/Current/"
             "Commands");
    } else if (flag == 1) {
      printf("preparation is already done.\n");
      return_value = 1;
    }
  }
  return return_value;
}


x86 assembly (clang, -O0):
<init_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x8(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1030 <check_exists@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    119b <init_env+0x4b>
mov    $0x0,%al
call   1040 <create_symlink_for_commands@plt>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    125f <init_env+0x10f>
cmpl   $0x0,-0xc(%rbp)
jne    11f4 <init_env+0xa4>
mov    $0x0,%al
call   1070 <backup_commands_dir@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11d3 <init_env+0x83>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1265 <init_env+0x115>
mov    $0x0,%al
call   1040 <create_symlink_for_commands@plt>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x8(%rbp)
jmp    125a <init_env+0x10a>
cmpl   $0x1,-0xc(%rbp)
jne    1255 <init_env+0x105>
mov    $0x0,%al
call   1060 <check_link@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    122c <init_env+0xdc>
lea    0xe65(%rip),%rdi
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1250 <init_env+0x100>
cmpl   $0x1,-0x14(%rbp)
jne    124b <init_env+0xfb>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x8(%rbp)
jmp    1250 <init_env+0x100>
jmp    1255 <init_env+0x105>
jmp    125a <init_env+0x10a>
jmp    125f <init_env+0x10f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_env>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1040 <check_exists@plt>
xor    %ebx,%ebx
cmp    $0x1,%eax
je     1198 <init_env+0x38>
test   %eax,%eax
je     11c1 <init_env+0x61>
cmp    $0xffffffff,%eax
jne    11fb <init_env+0x9b>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <create_symlink_for_commands@plt>
lea    0xf02(%rip),%rdi
jmp    11f6 <init_env+0x96>
xor    %eax,%eax
call   1070 <check_link@plt>
cmp    $0x1,%eax
je     11dc <init_env+0x7c>
test   %eax,%eax
jne    11fb <init_env+0x9b>
lea    0xe97(%rip),%rdi
lea    0xe4a(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11fb <init_env+0x9b>
xor    %eax,%eax
call   1080 <backup_commands_dir@plt>
test   %eax,%eax
je     11ef <init_env+0x8f>
xor    %eax,%eax
call   1050 <create_symlink_for_commands@plt>
lea    0xebe(%rip),%rdi
jmp    11e3 <init_env+0x83>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    11fb <init_env+0x9b>
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [70 x i8] c"/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands\00"
@S_IFLNK = global i32 0
@.str.1 = [22 x i8] c"preparation is done.\0A\00"
@.str.2 = [34 x i8] c"back up of Command dir is failed\0A\00"
@.str.3 = [20 x i8] c"invalid link at %s\0A\00"
@.str.4 = [30 x i8] c"preparation is already done.\0A\00"
define i32 @init_env() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %2
%6 = load i32, i32* @S_IFLNK
%7 = call i32 @check_exists(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 (...) @create_symlink_for_commands()
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %43
13: ; preds = %0
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = call i32 (...) @backup_commands_dir()
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %45
22: ; preds = %16
%23 = call i32 (...) @create_symlink_for_commands()
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %42
25: ; preds = %13
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %41
28: ; preds = %25
%29 = call i32 (...) @check_link()
store i32 %29, i32* %5
%30 = load i32, i32* %5
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
br label %40
34: ; preds = %28
%35 = load i32, i32* %5
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
br label %39
39: ; preds = %37, %34
br label %40
40: ; preds = %39, %32
br label %41
41: ; preds = %40, %25
br label %42
42: ; preds = %41, %22
br label %43
43: ; preds = %42, %10
%44 = load i32, i32* %2
store i32 %44, i32* %1
br label %45
45: ; preds = %43, %20
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str = [70 x i8] c"/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands\00"
@S_IFLNK = global i32 0
@.str.3 = [20 x i8] c"invalid link at %s\0A\00"
@str = [29 x i8] c"preparation is already done.\00"
@str.6 = [33 x i8] c"back up of Command dir is failed\00"
@str.7 = [21 x i8] c"preparation is done.\00"
define i32 @init_env() {
%1 = load i32, i32* @S_IFLNK
%2 = tail call i32 @check_exists(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 %1)
switch i32 %2, label %20 [
i32 -1, label %3
i32 0, label %6
i32 1, label %14
]
3: ; preds = %0
%4 = tail call i32 (...) @create_symlink_for_commands()
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.7, i64 0, i64 0))
br label %20
6: ; preds = %0
%7 = tail call i32 (...) @backup_commands_dir()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.6, i64 0, i64 0))
br label %20
11: ; preds = %6
%12 = tail call i32 (...) @create_symlink_for_commands()
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.7, i64 0, i64 0))
br label %20
14: ; preds = %0
%15 = tail call i32 (...) @check_link()
switch i32 %15, label %20 [
i32 0, label %16
i32 1, label %18
]
16: ; preds = %14
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
br label %20
18: ; preds = %14
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %3, %0, %14, %18, %16, %11, %9
%21 = phi i32 [ 0, %9 ], [ 0, %3 ], [ 1, %11 ], [ 0, %0 ], [ 0, %16 ], [ 1, %18 ], [ 0, %14 ]
ret i32 %21
}