#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 */
scalar_t__ ioutil_errno(int /*<<< orphan*/);
int ioutil_rename(char *, char *);
int /*<<< orphan*/ lib_free(char *);
char *lib_stralloc(char const *);
char *util_concat(char const *, char *, char const *, int /*<<< orphan*/ *);
unsigned int rawfile_rename(const char *src_name, const char *dst_name,
                            const char *path) {
  char *complete_src, *complete_dst;
  int rc;
  if (path == NULL) {
    complete_src = lib_stralloc(src_name);
    complete_dst = lib_stralloc(dst_name);
  } else {
    complete_src = util_concat(path, "/", src_name, NULL);
    complete_dst = util_concat(path, "/", dst_name, NULL);
  }
  rc = ioutil_rename(complete_src, complete_dst);
  lib_free(complete_src);
  lib_free(complete_dst);
  if (rc < 0) {
    if (ioutil_errno(0))
      return 3;
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rawfile_rename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118e <rawfile_rename+0x3e>
mov    -0x10(%rbp),%rdi
call   1030 <lib_stralloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <lib_stralloc@plt>
mov    %rax,-0x30(%rbp)
jmp    11c6 <rawfile_rename+0x76>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe63(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <util_concat@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe47(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <util_concat@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <ioutil_rename@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <lib_free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <lib_free@plt>
cmpl   $0x0,-0x34(%rbp)
jge    121b <rawfile_rename+0xcb>
xor    %edi,%edi
call   1070 <ioutil_errno@plt>
cmp    $0x0,%rax
je     120f <rawfile_rename+0xbf>
movl   $0x3,-0x4(%rbp)
jmp    1222 <rawfile_rename+0xd2>
movl   $0x1,-0x4(%rbp)
jmp    1222 <rawfile_rename+0xd2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rawfile_rename>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%rdx
test   %rbx,%rbx
je     118f <rawfile_rename+0x3f>
lea    0xe93(%rip),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %ecx,%ecx
call   1060 <util_concat@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1060 <util_concat@plt>
jmp    11a2 <rawfile_rename+0x52>
mov    %rdx,%rdi
call   1030 <lib_stralloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <lib_stralloc@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <ioutil_rename@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1040 <lib_free@plt>
mov    %rbx,%rdi
call   1040 <lib_free@plt>
xor    %eax,%eax
test   %ebp,%ebp
jns    11dd <rawfile_rename+0x8d>
xor    %edi,%edi
call   1070 <ioutil_errno@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rcx,%rcx,1),%eax
add    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i32 @rawfile_rename(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %7
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = call i8* @lib_stralloc(i8* %14)
store i8* %15, i8** %8
%16 = load i8*, i8** %6
%17 = call i8* @lib_stralloc(i8* %16)
store i8* %17, i8** %9
br label %25
18: ; preds = %3
%19 = load i8*, i8** %7
%20 = load i8*, i8** %5
%21 = call i8* @util_concat(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %20, i32* null)
store i8* %21, i8** %8
%22 = load i8*, i8** %7
%23 = load i8*, i8** %6
%24 = call i8* @util_concat(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %23, i32* null)
store i8* %24, i8** %9
br label %25
25: ; preds = %18, %13
%26 = load i8*, i8** %8
%27 = load i8*, i8** %9
%28 = call i32 @ioutil_rename(i8* %26, i8* %27)
store i32 %28, i32* %10
%29 = load i8*, i8** %8
%30 = call i32 @lib_free(i8* %29)
%31 = load i8*, i8** %9
%32 = call i32 @lib_free(i8* %31)
%33 = load i32, i32* %10
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %25
%36 = call i64 @ioutil_errno(i32 0)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 3, i32* %4
br label %41
39: ; preds = %35
store i32 1, i32* %4
br label %41
40: ; preds = %25
store i32 0, i32* %4
br label %41
41: ; preds = %40, %39, %38
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i32 @rawfile_rename(i8* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %2, null
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = tail call i8* @lib_stralloc(i8* %0)
%7 = tail call i8* @lib_stralloc(i8* %1)
br label %11
8: ; preds = %3
%9 = tail call i8* @util_concat(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %0, i32* null)
%10 = tail call i8* @util_concat(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %1, i32* null)
br label %11
11: ; preds = %8, %5
%12 = phi i8* [ %6, %5 ], [ %9, %8 ]
%13 = phi i8* [ %7, %5 ], [ %10, %8 ]
%14 = tail call i32 @ioutil_rename(i8* %12, i8* %13)
%15 = tail call i32 @lib_free(i8* %12)
%16 = tail call i32 @lib_free(i8* %13)
%17 = icmp slt i32 %14, 0
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = tail call i64 @ioutil_errno(i32 0)
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i32 1, i32 3
br label %22
22: ; preds = %11, %18
%23 = phi i32 [ %21, %18 ], [ 0, %11 ]
ret i32 %23
}