#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 /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ rename(char const *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
void fc_backup_oldfile(const char *filename) {
  char *newname;
  if (!filename)
    return;
  newname = malloc(strlen(filename) + 3);
  strcpy(newname, filename);
  strcat(newname, ".");
  rename(filename, newname);
  free(newname);
}


x86 assembly (clang, -O0):
<fc_backup_oldfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117c <fc_backup_oldfile+0x1c>
jmp    11c8 <fc_backup_oldfile+0x68>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <rename@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fc_backup_oldfile>:
test   %rdi,%rdi
je     11b1 <fc_backup_oldfile+0x51>
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <strlen@plt>
lea    0x3(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <rename@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define void @fc_backup_oldfile(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
br label %22
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 3
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = load i8*, i8** %2
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = load i8*, i8** %3
%16 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %2
%18 = load i8*, i8** %3
%19 = call i32 @rename(i8* %17, i8* %18)
%20 = load i8*, i8** %3
%21 = call i32 @free(i8* %20)
br label %22
22: ; preds = %7, %6
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define void @fc_backup_oldfile(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = add nsw i64 %4, 3
%6 = tail call i8* @malloc(i64 %5)
%7 = tail call i32 @strcpy(i8* %6, i8* %0)
%8 = tail call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @rename(i8* %0, i8* %6)
%10 = tail call i32 @free(i8* %6)
br label %11
11: ; preds = %1, %3
ret void
}