#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 chaz_CC_binary_format();
char *chaz_OS_dir_sep();
int /*<<< orphan*/ chaz_Util_die(char *);
char *chaz_Util_join(char *, char const *, char const *, char const *,
                     char const *, ...);
char *chaz_Util_strdup(char const *);
int /*<<< orphan*/ free(char *);
scalar_t__ strcmp(char const *, char *);
char *chaz_CC_build_lib_filename(const char *dir, const char *prefix,
                                 const char *basename, const char *version,
                                 const char *ext) {
  char *suffix;
  char *retval;
  if (version == NULL) {
    suffix = chaz_Util_strdup(ext);
  } else {
    int binary_format = chaz_CC_binary_format();
    if (binary_format == 3) {
      suffix = chaz_Util_join("", "-", version, ext, NULL);
    } else if (binary_format == 2) {
      suffix = chaz_Util_join("", ".", version, ext, NULL);
    } else if (binary_format == 1) {
      suffix = chaz_Util_join("", ext, ".", version, NULL);
    } else {
      chaz_Util_die("Unsupported binary format");
      return NULL;
    }
  }
  if (dir == NULL || strcmp(dir, ".") == 0) {
    retval = chaz_Util_join("", prefix, basename, suffix, NULL);
  } else {
    const char *dir_sep = chaz_OS_dir_sep();
    retval = chaz_Util_join("", dir, dir_sep, prefix, basename, suffix, NULL);
  }
  free(suffix);
  return retval;
}


x86 assembly (clang, -O0):
<chaz_CC_build_lib_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a9 <chaz_CC_build_lib_filename+0x39>
mov    -0x30(%rbp),%rdi
call   1050 <chaz_Util_strdup@plt>
mov    %rax,-0x38(%rbp)
jmp    127a <chaz_CC_build_lib_filename+0x10a>
mov    $0x0,%al
call   1040 <chaz_CC_binary_format@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x3,-0x44(%rbp)
jne    11e8 <chaz_CC_build_lib_filename+0x78>
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xe35(%rip),%rdi
lea    0xe2d(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   1070 <chaz_Util_join@plt>
mov    %rax,-0x38(%rbp)
jmp    1275 <chaz_CC_build_lib_filename+0x105>
cmpl   $0x2,-0x44(%rbp)
jne    121d <chaz_CC_build_lib_filename+0xad>
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xe00(%rip),%rdi
lea    0xdfa(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   1070 <chaz_Util_join@plt>
mov    %rax,-0x38(%rbp)
jmp    1270 <chaz_CC_build_lib_filename+0x100>
cmpl   $0x1,-0x44(%rbp)
jne    1252 <chaz_CC_build_lib_filename+0xe2>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rcx
lea    0xdcb(%rip),%rdi
lea    0xdc5(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   1070 <chaz_Util_join@plt>
mov    %rax,-0x38(%rbp)
jmp    126b <chaz_CC_build_lib_filename+0xfb>
lea    0xdab(%rip),%rdi
call   1090 <chaz_Util_die@plt>
movq   $0x0,-0x8(%rbp)
jmp    1313 <chaz_CC_build_lib_filename+0x1a3>
jmp    1270 <chaz_CC_build_lib_filename+0x100>
jmp    1275 <chaz_CC_build_lib_filename+0x105>
jmp    127a <chaz_CC_build_lib_filename+0x10a>
cmpq   $0x0,-0x10(%rbp)
je     129f <chaz_CC_build_lib_filename+0x12f>
mov    -0x10(%rbp),%rdi
lea    0xd72(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12c7 <chaz_CC_build_lib_filename+0x157>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xd4f(%rip),%rdi
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   1070 <chaz_Util_join@plt>
mov    %rax,-0x40(%rbp)
jmp    1302 <chaz_CC_build_lib_filename+0x192>
mov    $0x0,%al
call   1080 <chaz_OS_dir_sep@plt>
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x50(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x38(%rbp),%r9
lea    0xd14(%rip),%rdi
xor    %eax,%eax
movq   $0x0,(%rsp)
mov    $0x0,%al
call   1070 <chaz_Util_join@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chaz_CC_build_lib_filename>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r13
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
test   %rcx,%rcx
je     11bb <chaz_CC_build_lib_filename+0x4b>
mov    %rcx,%rbx
xor    %eax,%eax
call   1040 <chaz_CC_binary_format@plt>
cmp    $0x1,%eax
je     11c5 <chaz_CC_build_lib_filename+0x55>
cmp    $0x2,%eax
je     11db <chaz_CC_build_lib_filename+0x6b>
cmp    $0x3,%eax
jne    1279 <chaz_CC_build_lib_filename+0x109>
lea    0xe4f(%rip),%rdi
lea    0xe47(%rip),%rsi
jmp    11e9 <chaz_CC_build_lib_filename+0x79>
mov    %r13,%rdi
call   1050 <chaz_Util_strdup@plt>
jmp    11f9 <chaz_CC_build_lib_filename+0x89>
lea    0xe35(%rip),%rdi
lea    0xe2f(%rip),%rdx
mov    %r13,%rsi
mov    %rbx,%rcx
jmp    11ef <chaz_CC_build_lib_filename+0x7f>
lea    0xe1f(%rip),%rdi
lea    0xe19(%rip),%rsi
mov    %rbx,%rdx
mov    %r13,%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   1070 <chaz_Util_join@plt>
mov    %rax,%r13
test   %r12,%r12
je     1243 <chaz_CC_build_lib_filename+0xd3>
lea    0xdfa(%rip),%rsi
mov    %r12,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1243 <chaz_CC_build_lib_filename+0xd3>
xor    %eax,%eax
call   1080 <chaz_OS_dir_sep@plt>
movq   $0x0,(%rsp)
lea    0xdd6(%rip),%rdi
mov    %r12,%rsi
mov    %rax,%rdx
mov    %r15,%rcx
mov    %r14,%r8
mov    %r13,%r9
xor    %eax,%eax
call   1070 <chaz_Util_join@plt>
jmp    125d <chaz_CC_build_lib_filename+0xed>
lea    0xdb7(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r13,%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   1070 <chaz_Util_join@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd84(%rip),%rdi
call   1090 <chaz_Util_die@plt>
xor    %ebx,%ebx
jmp    1268 <chaz_CC_build_lib_filename+0xf8>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [26 x i8] c"Unsupported binary format\00"
define i8* @chaz_CC_build_lib_filename(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%16 = load i8*, i8** %10
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %5
%19 = load i8*, i8** %11
%20 = call i8* @chaz_Util_strdup(i8* %19)
store i8* %20, i8** %12
br label %48
21: ; preds = %5
%22 = call i32 (...) @chaz_CC_binary_format()
store i32 %22, i32* %14
%23 = load i32, i32* %14
%24 = icmp eq i32 %23, 3
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i8*, i8** %10
%27 = load i8*, i8** %11
%28 = call i8* (i8*, i8*, i8*, i8*, i8*, ...) @chaz_Util_join(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %26, i8* %27, i8* null)
store i8* %28, i8** %12
br label %47
29: ; preds = %21
%30 = load i32, i32* %14
%31 = icmp eq i32 %30, 2
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i8*, i8** %10
%34 = load i8*, i8** %11
%35 = call i8* (i8*, i8*, i8*, i8*, i8*, ...) @chaz_Util_join(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %33, i8* %34, i8* null)
store i8* %35, i8** %12
br label %46
36: ; preds = %29
%37 = load i32, i32* %14
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i8*, i8** %11
%41 = load i8*, i8** %10
%42 = call i8* (i8*, i8*, i8*, i8*, i8*, ...) @chaz_Util_join(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %41, i8* null)
store i8* %42, i8** %12
br label %45
43: ; preds = %36
%44 = call i32 @chaz_Util_die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %6
br label %72
45: ; preds = %39
br label %46
46: ; preds = %45, %32
br label %47
47: ; preds = %46, %25
br label %48
48: ; preds = %47, %18
%49 = load i8*, i8** %7
%50 = icmp eq i8* %49, null
br i1 %50, label %55, label %51
51: ; preds = %48
%52 = load i8*, i8** %7
%53 = call i64 @strcmp(i8* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %51, %48
%56 = load i8*, i8** %8
%57 = load i8*, i8** %9
%58 = load i8*, i8** %12
%59 = call i8* (i8*, i8*, i8*, i8*, i8*, ...) @chaz_Util_join(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %56, i8* %57, i8* %58, i8* null)
store i8* %59, i8** %13
br label %68
60: ; preds = %51
%61 = call i8* (...) @chaz_OS_dir_sep()
store i8* %61, i8** %15
%62 = load i8*, i8** %7
%63 = load i8*, i8** %15
%64 = load i8*, i8** %8
%65 = load i8*, i8** %9
%66 = load i8*, i8** %12
%67 = call i8* (i8*, i8*, i8*, i8*, i8*, ...) @chaz_Util_join(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %62, i8* %63, i8* %64, i8* %65, i8* %66, i8* null)
store i8* %67, i8** %13
br label %68
68: ; preds = %60, %55
%69 = load i8*, i8** %12
%70 = call i32 @free(i8* %69)
%71 = load i8*, i8** %13
store i8* %71, i8** %6
br label %72
72: ; preds = %68, %43
%73 = load i8*, i8** %6
ret i8* %73
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [26 x i8] c"Unsupported binary format\00"
define i8* @chaz_CC_build_lib_filename(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = icmp eq i8* %3, null
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i8* @chaz_Util_strdup(i8* %4)
br label %19
9: ; preds = %5
%10 = tail call i32 (...) @chaz_CC_binary_format()
switch i32 %10, label %17 [
i32 3, label %11
i32 2, label %13
i32 1, label %15
]
11: ; preds = %9
%12 = tail call i8* (i8*, i8*, i8*, i8*, i8*, ...) @chaz_Util_join(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %4, i8* null)
br label %19
13: ; preds = %9
%14 = tail call i8* (i8*, i8*, i8*, i8*, i8*, ...) @chaz_Util_join(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %3, i8* %4, i8* null)
br label %19
15: ; preds = %9
%16 = tail call i8* (i8*, i8*, i8*, i8*, i8*, ...) @chaz_Util_join(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %3, i8* null)
br label %19
17: ; preds = %9
%18 = tail call i32 @chaz_Util_die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %33
19: ; preds = %11, %15, %13, %7
%20 = phi i8* [ %8, %7 ], [ %16, %15 ], [ %14, %13 ], [ %12, %11 ]
%21 = icmp eq i8* %0, null
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22, %19
%26 = tail call i8* (i8*, i8*, i8*, i8*, i8*, ...) @chaz_Util_join(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2, i8* %20, i8* null)
br label %30
27: ; preds = %22
%28 = tail call i8* (...) @chaz_OS_dir_sep()
%29 = tail call i8* (i8*, i8*, i8*, i8*, i8*, ...) @chaz_Util_join(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %28, i8* %1, i8* %2, i8* %20, i8* null)
br label %30
30: ; preds = %27, %25
%31 = phi i8* [ %26, %25 ], [ %29, %27 ]
%32 = tail call i32 @free(i8* %20)
br label %33
33: ; preds = %17, %30
%34 = phi i8* [ %31, %30 ], [ null, %17 ]
ret i8* %34
}