#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 */
char *getenv(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strchr(char *, char);
scalar_t__ strlen(char *);
char *get_java_bin_path(void) {
  char *ps = getenv("JAVA_HOME");
  if (ps) {
    char *res = (char *)malloc(strlen(ps) + 6);
    sprintf(res, (strchr(ps, '/') ? "%s/bin/" : "%s\\bin\\"), ps);
    return res;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_java_bin_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d5 <get_java_bin_path+0x85>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x6,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    -0x20(%rbp),%rdi
mov    %rax,%rcx
lea    0xe62(%rip),%rsi
lea    0xe53(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
mov    -0x10(%rbp),%rdx
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11dd <get_java_bin_path+0x8d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_java_bin_path>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ab <get_java_bin_path+0x5b>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x6(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
lea    0xe7f(%rip),%rax
lea    0xe70(%rip),%rsi
cmove  %rax,%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1070 <sprintf@plt>
jmp    11ae <get_java_bin_path+0x5e>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"JAVA_HOME\00"
@.str.1 = [8 x i8] c"%s/bin/\00"
@.str.2 = [8 x i8] c"%s\\bin\\\00"
define i8* @get_java_bin_path() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %22
7: ; preds = %0
%8 = load i8*, i8** %2
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 6
%11 = call i64 @malloc(i64 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = load i8*, i8** %2
%15 = call i64 @strchr(i8* %14, i8 signext 47)
%16 = icmp ne i64 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0)
%19 = load i8*, i8** %2
%20 = call i32 @sprintf(i8* %13, i8* %18, i8* %19)
%21 = load i8*, i8** %3
store i8* %21, i8** %1
br label %23
22: ; preds = %0
store i8* null, i8** %1
br label %23
23: ; preds = %22, %7
%24 = load i8*, i8** %1
ret i8* %24
}

LLVM IR (-O2):
@.str = [10 x i8] c"JAVA_HOME\00"
@.str.1 = [8 x i8] c"%s/bin/\00"
@.str.2 = [8 x i8] c"%s\\bin\\\00"
define i8* @get_java_bin_path() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %12, label %3
3: ; preds = %0
%4 = tail call i64 @strlen(i8* %1)
%5 = add nsw i64 %4, 6
%6 = tail call i64 @malloc(i64 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i64 @strchr(i8* %1, i8 signext 47)
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0)
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) %10, i8* %1)
br label %12
12: ; preds = %0, %3
%13 = phi i8* [ %7, %3 ], [ null, %0 ]
ret i8* %13
}