#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 *filespecname(char const *);
scalar_t__ mem_malloc(scalar_t__);
char *mem_strdup(char const *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *filespecbackup(const char *filespec) {
  char *p, *f;
  if (!filespec)
    return (char *)filespec;
  p = filespecname(filespec);
  if (p[0] == '.' && p[1] == 'B')
    return mem_strdup(filespec);
  f = (char *)mem_malloc(strlen(filespec) + 2 + 1);
  if (f) {
    strcpy(f, filespec);
    strcpy(&f[p - filespec], ".B");
    strcat(f, p);
  }
  return f;
}


x86 assembly (clang, -O0):
<filespecbackup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1184 <filespecbackup+0x24>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    122c <filespecbackup+0xcc>
mov    -0x10(%rbp),%rdi
call   1060 <filespecname@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11c4 <filespecbackup+0x64>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x42,%eax
jne    11c4 <filespecbackup+0x64>
mov    -0x10(%rbp),%rdi
call   1080 <mem_strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    122c <filespecbackup+0xcc>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x2,%rdi
add    $0x1,%rdi
call   1030 <mem_malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1224 <filespecbackup+0xc4>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    %rax,%rdi
lea    0xdee(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filespecbackup>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     11d4 <filespecbackup+0x74>
mov    %rdi,%rbx
call   1060 <filespecname@plt>
mov    %rax,%r14
cmpb   $0x2e,(%rax)
jne    118e <filespecbackup+0x2e>
cmpb   $0x42,0x1(%r14)
jne    118e <filespecbackup+0x2e>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <mem_strdup@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x3(%rax),%rdi
call   1030 <mem_malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     11d7 <filespecbackup+0x77>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
sub    %rbx,%rdi
add    %r15,%rdi
lea    0xe3e(%rip),%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
jmp    11d7 <filespecbackup+0x77>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c".B\00"
define i8* @filespecbackup(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 = icmp ne i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = load i8*, i8** %3
store i8* %9, i8** %2
br label %53
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i8* @filespecname(i8* %11)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 46
br i1 %17, label %18, label %27
18: ; preds = %10
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 66
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i8*, i8** %3
%26 = call i8* @mem_strdup(i8* %25)
store i8* %26, i8** %2
br label %53
27: ; preds = %18, %10
%28 = load i8*, i8** %3
%29 = call i64 @strlen(i8* %28)
%30 = add nsw i64 %29, 2
%31 = add nsw i64 %30, 1
%32 = call i64 @mem_malloc(i64 %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %5
%34 = load i8*, i8** %5
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %51
36: ; preds = %27
%37 = load i8*, i8** %5
%38 = load i8*, i8** %3
%39 = call i32 @strcpy(i8* %37, i8* %38)
%40 = load i8*, i8** %5
%41 = load i8*, i8** %4
%42 = load i8*, i8** %3
%43 = ptrtoint i8* %41 to i64
%44 = ptrtoint i8* %42 to i64
%45 = sub i64 %43, %44
%46 = getelementptr inbounds i8, i8* %40, i64 %45
%47 = call i32 @strcpy(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%48 = load i8*, i8** %5
%49 = load i8*, i8** %4
%50 = call i32 @strcat(i8* %48, i8* %49)
br label %51
51: ; preds = %36, %27
%52 = load i8*, i8** %5
store i8* %52, i8** %2
br label %53
53: ; preds = %51, %24, %8
%54 = load i8*, i8** %2
ret i8* %54
}

LLVM IR (-O2):
@.str = [3 x i8] c".B\00"
define i8* @filespecbackup(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %27, label %3
3: ; preds = %1
%4 = tail call i8* @filespecname(i8* %0)
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 46
br i1 %6, label %7, label %13
7: ; preds = %3
%8 = getelementptr inbounds i8, i8* %4, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 66
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i8* @mem_strdup(i8* %0)
br label %27
13: ; preds = %7, %3
%14 = tail call i64 @strlen(i8* %0)
%15 = add nsw i64 %14, 3
%16 = tail call i64 @mem_malloc(i64 %15)
%17 = inttoptr i64 %16 to i8*
%18 = icmp eq i64 %16, 0
br i1 %18, label %27, label %19
19: ; preds = %13
%20 = tail call i32 @strcpy(i8* %17, i8* %0)
%21 = ptrtoint i8* %4 to i64
%22 = ptrtoint i8* %0 to i64
%23 = sub i64 %21, %22
%24 = getelementptr inbounds i8, i8* %17, i64 %23
%25 = tail call i32 @strcpy(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%26 = tail call i32 @strcat(i8* %17, i8* %4)
br label %27
27: ; preds = %13, %19, %1, %11
%28 = phi i8* [ %12, %11 ], [ null, %1 ], [ %17, %19 ], [ %17, %13 ]
ret i8* %28
}