#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 *OPENSSL_malloc(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ stderr;
int strlen(char *);
char *strrchr(char *, char);
char *getConnToolPath(char *str) {
  char *p;
  char *res = NULL;
  ;
  p = strrchr(str, '/');
  if ((!p) || ((strlen(str) - strlen(p)) == 0)) {
    fprintf(stderr, "ERROR: Faulty Path and Program\n");
    ;
    return NULL;
  }
  res = OPENSSL_malloc((strlen(str) - strlen(p) + 1) * sizeof(char));
  if (!res) {
    fprintf(stderr, "ERROR: Memory Allocation Failed\n");
    ;
    return NULL;
  }
  memset(res, '\0', (strlen(str) - strlen(p) + 1));
  memcpy(res, str, (strlen(str) - strlen(p)));
  return res;
}


x86 assembly (clang, -O0):
<getConnToolPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b6 <getConnToolPath+0x56>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
cmp    $0x0,%eax
jne    11d8 <getConnToolPath+0x78>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12a4 <getConnToolPath+0x144>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <OPENSSL_malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1235 <getConnToolPath+0xd5>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12a4 <getConnToolPath+0x144>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x4c(%rbp),%edx
mov    -0x48(%rbp),%rdi
sub    %eax,%edx
add    $0x1,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x3c(%rbp),%edx
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
sub    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getConnToolPath>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1192 <getConnToolPath+0x32>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebx
jne    11ab <getConnToolPath+0x4b>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1060 <fprintf@plt>
xor    %ebx,%ebx
jmp    1215 <getConnToolPath+0xb5>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebx
add    $0x1,%ebx
mov    %ebx,%edi
call   1080 <OPENSSL_malloc@plt>
test   %rax,%rax
je     1223 <getConnToolPath+0xc3>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
add    $0x1,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1070 <memcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
jmp    11a2 <getConnToolPath+0x42>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"ERROR: Faulty Path and Program\0A\00"
@.str.1 = [33 x i8] c"ERROR: Memory Allocation Failed\0A\00"
define i8* @getConnToolPath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %5
%6 = load i8*, i8** %3
%7 = call i8* @strrchr(i8* %6, i8 signext 47)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %17
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = sub nsw i32 %12, %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %10, %1
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %54
20: ; preds = %10
%21 = load i8*, i8** %3
%22 = call i32 @strlen(i8* %21)
%23 = load i8*, i8** %4
%24 = call i32 @strlen(i8* %23)
%25 = sub nsw i32 %22, %24
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 1
%29 = trunc i64 %28 to i32
%30 = call i8* @OPENSSL_malloc(i32 %29)
store i8* %30, i8** %5
%31 = load i8*, i8** %5
%32 = icmp ne i8* %31, null
br i1 %32, label %36, label %33
33: ; preds = %20
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %54
36: ; preds = %20
%37 = load i8*, i8** %5
%38 = load i8*, i8** %3
%39 = call i32 @strlen(i8* %38)
%40 = load i8*, i8** %4
%41 = call i32 @strlen(i8* %40)
%42 = sub nsw i32 %39, %41
%43 = add nsw i32 %42, 1
%44 = call i32 @memset(i8* %37, i8 signext 0, i32 %43)
%45 = load i8*, i8** %5
%46 = load i8*, i8** %3
%47 = load i8*, i8** %3
%48 = call i32 @strlen(i8* %47)
%49 = load i8*, i8** %4
%50 = call i32 @strlen(i8* %49)
%51 = sub nsw i32 %48, %50
%52 = call i32 @memcpy(i8* %45, i8* %46, i32 %51)
%53 = load i8*, i8** %5
store i8* %53, i8** %2
br label %54
54: ; preds = %36, %33, %17
%55 = load i8*, i8** %2
ret i8* %55
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"ERROR: Faulty Path and Program\0A\00"
@.str.1 = [33 x i8] c"ERROR: Memory Allocation Failed\0A\00"
define i8* @getConnToolPath(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i32 @strlen(i8* %2)
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %11
8: ; preds = %4, %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %31
11: ; preds = %4
%12 = tail call i32 @strlen(i8* %0)
%13 = tail call i32 @strlen(i8* %2)
%14 = add i32 %12, 1
%15 = sub i32 %14, %13
%16 = tail call i8* @OPENSSL_malloc(i32 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %31
21: ; preds = %11
%22 = tail call i32 @strlen(i8* %0)
%23 = tail call i32 @strlen(i8* %2)
%24 = add i32 %22, 1
%25 = sub i32 %24, %23
%26 = tail call i32 @memset(i8* %16, i8 signext 0, i32 %25)
%27 = tail call i32 @strlen(i8* %0)
%28 = tail call i32 @strlen(i8* %2)
%29 = sub nsw i32 %27, %28
%30 = tail call i32 @memcpy(i8* %16, i8* %0, i32 %29)
br label %31
31: ; preds = %21, %18, %8
%32 = phi i8* [ null, %8 ], [ %16, %21 ], [ null, %18 ]
ret i8* %32
}