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


x86 assembly (clang, -O0):
<getConnToolName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a7 <getConnToolName+0x47>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jne    11c9 <getConnToolName+0x69>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1264 <getConnToolName+0x104>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <OPENSSL_malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1213 <getConnToolName+0xb3>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1264 <getConnToolName+0x104>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
add    $0x1,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getConnToolName>:
push   %r14
push   %rbx
push   %rax
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     11c5 <getConnToolName+0x65>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <OPENSSL_malloc@plt>
test   %rax,%rax
je     11d7 <getConnToolName+0x77>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
jmp    11ef <getConnToolName+0x8f>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
jmp    11e7 <getConnToolName+0x87>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1060 <fprintf@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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* @getConnToolName(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%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 = getelementptr inbounds i8, i8* %8, i32 1
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12, %1
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %44
19: ; preds = %12
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 1
%25 = trunc i64 %24 to i32
%26 = call i8* @OPENSSL_malloc(i32 %25)
store i8* %26, i8** %5
%27 = load i8*, i8** %5
%28 = icmp ne i8* %27, null
br i1 %28, label %32, label %29
29: ; preds = %19
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %44
32: ; preds = %19
%33 = load i8*, i8** %5
%34 = load i8*, i8** %4
%35 = call i32 @strlen(i8* %34)
%36 = add nsw i32 %35, 1
%37 = call i32 @memset(i8* %33, i8 signext 0, i32 %36)
%38 = load i8*, i8** %5
%39 = load i8*, i8** %4
%40 = load i8*, i8** %4
%41 = call i32 @strlen(i8* %40)
%42 = call i32 @memcpy(i8* %38, i8* %39, i32 %41)
%43 = load i8*, i8** %5
store i8* %43, i8** %2
br label %44
44: ; preds = %32, %29, %16
%45 = load i8*, i8** %2
ret i8* %45
}

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* @getConnToolName(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = getelementptr inbounds i8, i8* %2, i64 1
%4 = tail call i32 @strlen(i8* %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %23
9: ; preds = %1
%10 = tail call i32 @strlen(i8* %3)
%11 = add nsw i32 %10, 1
%12 = tail call i8* @OPENSSL_malloc(i32 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %23
17: ; preds = %9
%18 = tail call i32 @strlen(i8* %3)
%19 = add nsw i32 %18, 1
%20 = tail call i32 @memset(i8* %12, i8 signext 0, i32 %19)
%21 = tail call i32 @strlen(i8* %3)
%22 = tail call i32 @memcpy(i8* %12, i8* %3, i32 %21)
br label %23
23: ; preds = %17, %14, %6
%24 = phi i8* [ null, %6 ], [ %12, %17 ], [ null, %14 ]
ret i8* %24
}