#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 *RepMkPath(char *, char *);
char *RepMkPathTmp(char *, char *, char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ free(char *);
int rename(char *, char *);
int /*<<< orphan*/ stderr;
int RepRenameTmp(char *Type, char *Filename, char *Ext) {
  char *FnameOld, *Fname;
  int rc;
  FnameOld = RepMkPathTmp(Type, Filename, Ext, 1);
  Fname = RepMkPath(Type, Filename);
  if (!FnameOld || !Fname) {
    fprintf(stderr, "ERROR: Bad repository name: type='%s' name='%s'\n", Type,
            Filename);
    return (-1);
  }
  rc = rename(FnameOld, Fname);
  free(FnameOld);
  free(Fname);
  return (rc);
}


x86 assembly (clang, -O0):
<RepRenameTmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x1,%ecx
call   1050 <RepMkPathTmp@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <RepMkPath@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11a5 <RepRenameTmp+0x55>
cmpq   $0x0,-0x30(%rbp)
jne    11ce <RepRenameTmp+0x7e>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe43(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <RepRenameTmp+0xa6>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <rename@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RepRenameTmp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x1,%ecx
call   1050 <RepMkPathTmp@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <RepMkPath@plt>
test   %r15,%r15
je     11a4 <RepRenameTmp+0x54>
mov    %rax,%r12
test   %rax,%rax
je     11a4 <RepRenameTmp+0x54>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <rename@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
jmp    11c4 <RepRenameTmp+0x74>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"ERROR: Bad repository name: type='%s' name='%s'\0A\00"
define i32 @RepRenameTmp(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** %5
%12 = load i8*, i8** %6
%13 = load i8*, i8** %7
%14 = call i8* @RepMkPathTmp(i8* %11, i8* %12, i8* %13, i32 1)
store i8* %14, i8** %8
%15 = load i8*, i8** %5
%16 = load i8*, i8** %6
%17 = call i8* @RepMkPath(i8* %15, i8* %16)
store i8* %17, i8** %9
%18 = load i8*, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %3
%21 = load i8*, i8** %9
%22 = icmp ne i8* %21, null
br i1 %22, label %28, label %23
23: ; preds = %20, %3
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %5
%26 = load i8*, i8** %6
%27 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %25, i8* %26)
store i32 -1, i32* %4
br label %37
28: ; preds = %20
%29 = load i8*, i8** %8
%30 = load i8*, i8** %9
%31 = call i32 @rename(i8* %29, i8* %30)
store i32 %31, i32* %10
%32 = load i8*, i8** %8
%33 = call i32 @free(i8* %32)
%34 = load i8*, i8** %9
%35 = call i32 @free(i8* %34)
%36 = load i32, i32* %10
store i32 %36, i32* %4
br label %37
37: ; preds = %28, %23
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"ERROR: Bad repository name: type='%s' name='%s'\0A\00"
define i32 @RepRenameTmp(i8* %0, i8* %1, i8* %2) {
%4 = tail call i8* @RepMkPathTmp(i8* %0, i8* %1, i8* %2, i32 1)
%5 = tail call i8* @RepMkPath(i8* %0, i8* %1)
%6 = icmp ne i8* %4, null
%7 = icmp ne i8* %5, null
%8 = select i1 %6, i1 %7, i1 false
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %16
12: ; preds = %3
%13 = tail call i32 @rename(i8* %4, i8* %5)
%14 = tail call i32 @free(i8* %4)
%15 = tail call i32 @free(i8* %5)
br label %16
16: ; preds = %12, %9
%17 = phi i32 [ %13, %12 ], [ -1, %9 ]
ret i32 %17
}