#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 *alloca(size_t);
int /*<<< orphan*/ err(int, char *, char const *, char *);
int rename(char const *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncat(char *, char *, size_t);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
void backup_file(const char *path) {
  size_t len = strlen(path) + 5;
  char *bakpath;
  bakpath = alloca(len + 1);
  *bakpath = 0;
  strncpy(bakpath, path, len);
  strncat(bakpath, ".prev", len);
  int ret;
  ret = rename(path, bakpath);
  if (ret != 0)
    err(1, "rename %s %s", path, bakpath);
}


x86 assembly (clang, -O0):
<backup_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x5,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1060 <alloca@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe4a(%rip),%rsi
call   1050 <strncat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <rename@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11ee <backup_file+0x8e>
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%edi
lea    0xe1d(%rip),%rsi
call   1070 <err@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<backup_file>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
movslq %eax,%rdi
lea    0x5(%rdi),%r15
add    $0x6,%rdi
call   1060 <alloca@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strncpy@plt>
lea    0xe68(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1050 <strncat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <rename@plt>
test   %eax,%eax
je     11ce <backup_file+0x6e>
lea    0xe4d(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <err@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c".prev\00"
@.str.1 = [13 x i8] c"rename %s %s\00"
define void @backup_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = add nsw i32 %7, 5
%9 = sext i32 %8 to i64
store i64 %9, i64* %3
%10 = load i64, i64* %3
%11 = add i64 %10, 1
%12 = call i8* @alloca(i64 %11)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
store i8 0, i8* %13
%14 = load i8*, i8** %4
%15 = load i8*, i8** %2
%16 = load i64, i64* %3
%17 = call i32 @strncpy(i8* %14, i8* %15, i64 %16)
%18 = load i8*, i8** %4
%19 = load i64, i64* %3
%20 = call i32 @strncat(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %19)
%21 = load i8*, i8** %2
%22 = load i8*, i8** %4
%23 = call i32 @rename(i8* %21, i8* %22)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %1
%27 = load i8*, i8** %2
%28 = load i8*, i8** %4
%29 = call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %28)
br label %30
30: ; preds = %26, %1
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c".prev\00"
@.str.1 = [13 x i8] c"rename %s %s\00"
define void @backup_file(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 5
%4 = sext i32 %3 to i64
%5 = add nsw i64 %4, 1
%6 = tail call i8* @alloca(i64 %5)
store i8 0, i8* %6
%7 = tail call i32 @strncpy(i8* %6, i8* %0, i64 %4)
%8 = tail call i32 @strncat(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %4)
%9 = tail call i32 @rename(i8* %0, i8* %6)
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %6)
br label %13
13: ; preds = %11, %1
ret void
}