#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 *chaz_CC_obj_ext();
char *chaz_OS_dir_sep();
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
char *S_chaz_MakeBinary_obj_path(const char *src_path) {
  const char *dir_sep = chaz_OS_dir_sep();
  const char *obj_ext = chaz_CC_obj_ext();
  size_t obj_ext_len = strlen(obj_ext);
  size_t i = strlen(src_path);
  char *retval;
  while (i > 0) {
    i -= 1;
    if (src_path[i] == dir_sep[0]) {
      return NULL;
    }
    if (src_path[i] == '.') {
      break;
    }
  }
  if (src_path[i] != '.') {
    return NULL;
  }
  retval = (char *)malloc(i + obj_ext_len + 1);
  memcpy(retval, src_path, i);
  memcpy(retval + i, obj_ext, obj_ext_len + 1);
  return retval;
}


x86 assembly (clang, -O0):
<S_chaz_MakeBinary_obj_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <chaz_OS_dir_sep@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1070 <chaz_CC_obj_ext@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jbe    11ea <S_chaz_MakeBinary_obj_path+0x9a>
mov    -0x30(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11cb <S_chaz_MakeBinary_obj_path+0x7b>
movq   $0x0,-0x8(%rbp)
jmp    1253 <S_chaz_MakeBinary_obj_path+0x103>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11e5 <S_chaz_MakeBinary_obj_path+0x95>
jmp    11ea <S_chaz_MakeBinary_obj_path+0x9a>
jmp    118c <S_chaz_MakeBinary_obj_path+0x3c>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     120c <S_chaz_MakeBinary_obj_path+0xbc>
movq   $0x0,-0x8(%rbp)
jmp    1253 <S_chaz_MakeBinary_obj_path+0x103>
mov    -0x30(%rbp),%rdi
add    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%rdi
add    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
add    $0x1,%rdx
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<S_chaz_MakeBinary_obj_path>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r13
xor    %eax,%eax
call   1060 <chaz_OS_dir_sep@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1070 <chaz_CC_obj_ext@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %r13,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     11e6 <S_chaz_MakeBinary_obj_path+0x96>
mov    (%rbx),%dl
xor    %r12d,%r12d
nopl   (%rax)
movzbl -0x1(%r13,%rax,1),%ecx
cmp    %dl,%cl
je     11f4 <S_chaz_MakeBinary_obj_path+0xa4>
lea    -0x1(%rax),%rbx
cmp    $0x2e,%cl
je     11ac <S_chaz_MakeBinary_obj_path+0x5c>
cmp    $0x1,%rax
mov    %rbx,%rax
jne    1190 <S_chaz_MakeBinary_obj_path+0x40>
cmp    $0x2e,%cl
jne    11f1 <S_chaz_MakeBinary_obj_path+0xa1>
lea    (%r15,%rbx,1),%rdi
add    $0x1,%rdi
add    $0x1,%r15
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
mov    %r12,%rdi
add    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <memcpy@plt>
jmp    11f4 <S_chaz_MakeBinary_obj_path+0xa4>
mov    0x0(%r13),%cl
xor    %ebx,%ebx
cmp    $0x2e,%cl
je     11b1 <S_chaz_MakeBinary_obj_path+0x61>
xor    %r12d,%r12d
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @S_chaz_MakeBinary_obj_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %3
%9 = call i8* (...) @chaz_OS_dir_sep()
store i8* %9, i8** %4
%10 = call i8* (...) @chaz_CC_obj_ext()
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %6
%13 = load i8*, i8** %3
%14 = call i64 @strlen(i8* %13)
store i64 %14, i64* %7
br label %15
15: ; preds = %40, %1
%16 = load i64, i64* %7
%17 = icmp ugt i64 %16, 0
br i1 %17, label %18, label %41
18: ; preds = %15
%19 = load i64, i64* %7
%20 = sub i64 %19, 1
store i64 %20, i64* %7
%21 = load i8*, i8** %3
%22 = load i64, i64* %7
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %25, %29
br i1 %30, label %31, label %32
31: ; preds = %18
store i8* null, i8** %2
br label %68
32: ; preds = %18
%33 = load i8*, i8** %3
%34 = load i64, i64* %7
%35 = getelementptr inbounds i8, i8* %33, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 46
br i1 %38, label %39, label %40
39: ; preds = %32
br label %41
40: ; preds = %32
br label %15
41: ; preds = %39, %15
%42 = load i8*, i8** %3
%43 = load i64, i64* %7
%44 = getelementptr inbounds i8, i8* %42, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 46
br i1 %47, label %48, label %49
48: ; preds = %41
store i8* null, i8** %2
br label %68
49: ; preds = %41
%50 = load i64, i64* %7
%51 = load i64, i64* %6
%52 = add i64 %50, %51
%53 = add i64 %52, 1
%54 = call i64 @malloc(i64 %53)
%55 = inttoptr i64 %54 to i8*
store i8* %55, i8** %8
%56 = load i8*, i8** %8
%57 = load i8*, i8** %3
%58 = load i64, i64* %7
%59 = call i32 @memcpy(i8* %56, i8* %57, i64 %58)
%60 = load i8*, i8** %8
%61 = load i64, i64* %7
%62 = getelementptr inbounds i8, i8* %60, i64 %61
%63 = load i8*, i8** %5
%64 = load i64, i64* %6
%65 = add i64 %64, 1
%66 = call i32 @memcpy(i8* %62, i8* %63, i64 %65)
%67 = load i8*, i8** %8
store i8* %67, i8** %2
br label %68
68: ; preds = %49, %48, %31
%69 = load i8*, i8** %2
ret i8* %69
}

LLVM IR (-O2):
define i8* @S_chaz_MakeBinary_obj_path(i8* %0) {
%2 = tail call i8* (...) @chaz_OS_dir_sep()
%3 = tail call i8* (...) @chaz_CC_obj_ext()
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i8, i8* %0
br label %21
9: ; preds = %1
%10 = load i8, i8* %2
br label %11
11: ; preds = %9, %17
%12 = phi i64 [ %13, %17 ], [ %5, %9 ]
%13 = add i64 %12, -1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, %10
br i1 %16, label %33, label %17
17: ; preds = %11
%18 = icmp ne i8 %15, 46
%19 = icmp ne i64 %13, 0
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %11, label %21
21: ; preds = %17, %7
%22 = phi i8 [ %8, %7 ], [ %15, %17 ]
%23 = phi i64 [ 0, %7 ], [ %13, %17 ]
%24 = icmp eq i8 %22, 46
br i1 %24, label %25, label %33
25: ; preds = %21
%26 = add i64 %4, 1
%27 = add i64 %26, %23
%28 = tail call i64 @malloc(i64 %27)
%29 = inttoptr i64 %28 to i8*
%30 = tail call i32 @memcpy(i8* %29, i8* %0, i64 %23)
%31 = getelementptr inbounds i8, i8* %29, i64 %23
%32 = tail call i32 @memcpy(i8* %31, i8* %3, i64 %26)
br label %33
33: ; preds = %11, %21, %25
%34 = phi i8* [ %29, %25 ], [ null, %21 ], [ null, %11 ]
ret i8* %34
}