#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 */
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ memset(char **, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *, char *);
int rename(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int strlen(char *);
int rename_directory(char *path) {
  ssize_t len = strlen(path);
  char moved[len + 2];
  memset(&moved, 0, len + 2);
  snprintf(moved, len + 2, ".%s", path);
  printf("move dir %s to %s\n", path, moved);
  return rename(path, moved);
}


x86 assembly (clang, -O0):
<rename_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edx
add    $0x2,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x2,%esi
mov    -0x8(%rbp),%rcx
lea    0xe4d(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x28(%rbp),%rdx
mov    -0x8(%rbp),%rsi
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%rdi
call   1070 <rename@plt>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rename_directory>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
lea    0x2(%rax),%r15d
mov    %rsp,%rbx
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1060 <memset@plt>
lea    0xe75(%rip),%rdx
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%rcx
call   1050 <snprintf@plt>
lea    0xe64(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <rename@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c".%s\00"
@.str.1 = [19 x i8] c"move dir %s to %s\0A\00"
define i32 @rename_directory(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = add nsw i32 %8, 2
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
%13 = bitcast i8* %12 to i8**
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 2
%16 = call i32 @memset(i8** %13, i32 0, i32 %15)
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 2
%19 = load i8*, i8** %2
%20 = call i32 @snprintf(i8* %12, i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %2
%22 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %12)
%23 = load i8*, i8** %2
%24 = call i32 @rename(i8* %23, i8* %12)
%25 = load i8*, i8** %4
ret i32 %24
}

LLVM IR (-O2):
@.str = [4 x i8] c".%s\00"
@.str.1 = [19 x i8] c"move dir %s to %s\0A\00"
define i32 @rename_directory(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 2
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = bitcast i8* %5 to i8**
%7 = call i32 @memset(i8** %6, i32 0, i32 %3)
%8 = call i32 @snprintf(i8* %5, i32 %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %5)
%10 = call i32 @rename(i8* %0, i8* %5)
ret i32 %10
}