#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 *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int rename(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
int backup_commands_dir() {
  char *newdir;
  int flag;
  int return_value = 0;
  newdir = (char *)malloc(sizeof(char) *
                          (strlen("/System/Library/Frameworks/JavaVM.framework/"
                                  "Versions/Current/Commands") +
                           6));
  sprintf(
      newdir, "%s.back",
      "/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands");
  flag = rename(
      "/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands",
      newdir);
  if (flag != 0) {
    perror(newdir);
  } else {
    return_value = 1;
  }
  free(newdir);
  return return_value;
}


x86 assembly (clang, -O0):
<backup_commands_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x10(%rbp)
lea    0xe8a(%rip),%rdi
call   1040 <strlen@plt>
add    $0x6,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeac(%rip),%rsi
lea    0xe5f(%rip),%rdx
call   1080 <sprintf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe4f(%rip),%rdi
call   1070 <rename@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11d1 <backup_commands_dir+0x71>
mov    -0x8(%rbp),%rdi
call   1060 <perror@plt>
jmp    11d8 <backup_commands_dir+0x78>
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<backup_commands_dir>:
push   %rbp
push   %rbx
push   %rax
lea    0xe96(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x6(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xec2(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
call   1080 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <rename@plt>
mov    $0x1,%ebp
test   %eax,%eax
jne    11b4 <backup_commands_dir+0x54>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %rbx,%rdi
call   1060 <perror@plt>
xor    %ebp,%ebp
jmp    11a3 <backup_commands_dir+0x43>

LLVM IR (-O0):
@.str = [70 x i8] c"/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands\00"
@.str.1 = [8 x i8] c"%s.back\00"
define i32 @backup_commands_dir() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
%4 = call i32 @strlen(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
%5 = add nsw i32 %4, 6
%6 = sext i32 %5 to i64
%7 = mul i64 1, %6
%8 = trunc i64 %7 to i32
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %1
%11 = load i8*, i8** %1
%12 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** %1
%14 = call i32 @rename(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = load i8*, i8** %1
%19 = call i32 @perror(i8* %18)
br label %21
20: ; preds = %0
store i32 1, i32* %3
br label %21
21: ; preds = %20, %17
%22 = load i8*, i8** %1
%23 = call i32 @free(i8* %22)
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [70 x i8] c"/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands\00"
@.str.1 = [8 x i8] c"%s.back\00"
define i32 @backup_commands_dir() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
%2 = add nsw i32 %1, 6
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @rename(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* %4)
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = tail call i32 @perror(i8* %4)
br label %10
10: ; preds = %0, %8
%11 = phi i32 [ 0, %8 ], [ 1, %0 ]
%12 = tail call i32 @free(i8* %4)
ret i32 %11
}