#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 *concat_string(char const *, char *, char const *, int /*<<< orphan*/ *);
int file_rename(char *, char *);
int /*<<< orphan*/ free(char *);
char *fs_get_write_dir();
int fs_rename(const char *src, const char *dst) {
  const char *write_dir;
  char *real_src, *real_dst;
  int rc = 0;
  if ((write_dir = fs_get_write_dir())) {
    real_src = concat_string(write_dir, "/", src, NULL);
    real_dst = concat_string(write_dir, "/", dst, NULL);
    rc = file_rename(real_src, real_dst);
    free(real_src);
    free(real_dst);
  }
  return rc;
}


x86 assembly (clang, -O0):
<fs_rename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    $0x0,%al
call   1050 <fs_get_write_dir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11c6 <fs_rename+0x86>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe85(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <concat_string@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe69(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <concat_string@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <file_rename@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fs_rename>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <fs_get_write_dir@plt>
test   %rax,%rax
je     11ab <fs_rename+0x6b>
mov    %rax,%rbx
lea    0xe9c(%rip),%r12
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
xor    %ecx,%ecx
call   1060 <concat_string@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1060 <concat_string@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <file_rename@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
jmp    11ad <fs_rename+0x6d>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i32 @fs_rename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %8
%9 = call i8* (...) @fs_get_write_dir()
store i8* %9, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %25
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = load i8*, i8** %3
%14 = call i8* @concat_string(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %13, i32* null)
store i8* %14, i8** %6
%15 = load i8*, i8** %5
%16 = load i8*, i8** %4
%17 = call i8* @concat_string(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %16, i32* null)
store i8* %17, i8** %7
%18 = load i8*, i8** %6
%19 = load i8*, i8** %7
%20 = call i32 @file_rename(i8* %18, i8* %19)
store i32 %20, i32* %8
%21 = load i8*, i8** %6
%22 = call i32 @free(i8* %21)
%23 = load i8*, i8** %7
%24 = call i32 @free(i8* %23)
br label %25
25: ; preds = %11, %2
%26 = load i32, i32* %8
ret i32 %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i32 @fs_rename(i8* %0, i8* %1) {
%3 = tail call i8* (...) @fs_get_write_dir()
%4 = icmp eq i8* %3, null
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i8* @concat_string(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %0, i32* null)
%7 = tail call i8* @concat_string(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %1, i32* null)
%8 = tail call i32 @file_rename(i8* %6, i8* %7)
%9 = tail call i32 @free(i8* %6)
%10 = tail call i32 @free(i8* %7)
br label %11
11: ; preds = %5, %2
%12 = phi i32 [ %8, %5 ], [ 0, %2 ]
ret i32 %12
}