#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 *e_new_qual(char *, char *, char *);
char *getenv(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *e_bakfilename(char *s) {
  static char *bak = NULL;
  char *result;
  if (!bak) {
    bak = getenv("SIMPLE_BACKUP_SUFFIX");
    if (!bak)
      bak = "";
  }
  result = malloc(strlen(s) + strlen(bak) + 5);
  if (!*bak)
    return e_new_qual(s, "bak", result);
  else {
    strcpy(result, s);
    strcat(result, bak);
    return result;
  }
}


x86 assembly (clang, -O0):
<e_bakfilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,0x2ee4(%rip)
jne    11ae <e_bakfilename+0x4e>
lea    0xe7f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2ecb(%rip)
cmpq   $0x0,0x2ec3(%rip)
jne    11a9 <e_bakfilename+0x49>
lea    0xe72(%rip),%rax
mov    %rax,0x2eaf(%rip)
jmp    11ae <e_bakfilename+0x4e>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e96(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x5,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e76(%rip),%rax
cmpb   $0x0,(%rax)
jne    1208 <e_bakfilename+0xa8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe1b(%rip),%rsi
call   1080 <e_new_qual@plt>
mov    %rax,-0x8(%rbp)
jmp    122d <e_bakfilename+0xcd>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e38(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<e_bakfilename>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2ee9(%rip),%rbx
test   %rbx,%rbx
jne    1195 <e_bakfilename+0x35>
lea    0xe85(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe8a(%rip),%rbx
cmovne %rax,%rbx
mov    %rbx,0x2ec3(%rip)
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x5,%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
cmpb   $0x0,(%rbx)
je     11e0 <e_bakfilename+0x80>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    0x2e89(%rip),%rsi
mov    %r15,%rdi
call   1070 <strcat@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe2e(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <e_new_qual@plt>

LLVM IR (-O0):
@e_bakfilename.bak = internal global i8* null
@.str = [21 x i8] c"SIMPLE_BACKUP_SUFFIX\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [4 x i8] c"bak\00"
define i8* @e_bakfilename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** @e_bakfilename.bak
%6 = icmp ne i8* %5, null
br i1 %6, label %13, label %7
7: ; preds = %1
%8 = call i8* @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** @e_bakfilename.bak
%9 = load i8*, i8** @e_bakfilename.bak
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %7
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** @e_bakfilename.bak
br label %12
12: ; preds = %11, %7
br label %13
13: ; preds = %12, %1
%14 = load i8*, i8** %3
%15 = call i64 @strlen(i8* %14)
%16 = load i8*, i8** @e_bakfilename.bak
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %15, %17
%19 = add nsw i64 %18, 5
%20 = call i8* @malloc(i64 %19)
store i8* %20, i8** %4
%21 = load i8*, i8** @e_bakfilename.bak
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %13
%25 = load i8*, i8** %3
%26 = load i8*, i8** %4
%27 = call i8* @e_new_qual(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %26)
store i8* %27, i8** %2
br label %36
28: ; preds = %13
%29 = load i8*, i8** %4
%30 = load i8*, i8** %3
%31 = call i32 @strcpy(i8* %29, i8* %30)
%32 = load i8*, i8** %4
%33 = load i8*, i8** @e_bakfilename.bak
%34 = call i32 @strcat(i8* %32, i8* %33)
%35 = load i8*, i8** %4
store i8* %35, i8** %2
br label %36
36: ; preds = %28, %24
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
@e_bakfilename.bak = internal unnamed_addr global i8* null
@.str = [21 x i8] c"SIMPLE_BACKUP_SUFFIX\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [4 x i8] c"bak\00"
define i8* @e_bakfilename(i8* %0) {
%2 = load i8*, i8** @e_bakfilename.bak
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
%7 = select i1 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %5
store i8* %7, i8** @e_bakfilename.bak
br label %8
8: ; preds = %4, %1
%9 = phi i8* [ %7, %4 ], [ %2, %1 ]
%10 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%11 = tail call i64 @strlen(i8* dereferenceable(1) %9)
%12 = add i64 %10, 5
%13 = add i64 %12, %11
%14 = tail call i8* @malloc(i64 %13)
%15 = load i8, i8* %9
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %8
%18 = tail call i8* @e_new_qual(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %23
19: ; preds = %8
%20 = tail call i32 @strcpy(i8* %14, i8* %0)
%21 = load i8*, i8** @e_bakfilename.bak
%22 = tail call i32 @strcat(i8* %14, i8* %21)
br label %23
23: ; preds = %19, %17
%24 = phi i8* [ %14, %19 ], [ %18, %17 ]
ret i8* %24
}