#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*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ rename(char const *, char *);
int /*<<< orphan*/ stderr;
char *strdup(char const *);
void final_rename(const char *tag, const char *ofile) {
  if (ofile) {
    char *nfile = strdup(ofile);
    char *e = nfile;
    while (*e)
      e++;
    while (e != nfile && e[-1] == '_')
      e--;
    if (e != nfile && e[-1] != '/' && *e) {
      *e = 0;
      fprintf(stderr, "[%s] finished, renaming %s to %s.\n", tag, ofile, nfile);
      rename(ofile, nfile);
      free(nfile);
    }
  }
}


x86 assembly (clang, -O0):
<final_rename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     124a <final_rename+0x10a>
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     118e <final_rename+0x4e>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1170 <final_rename+0x30>
jmp    1193 <final_rename+0x53>
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x21(%rbp)
je     11b7 <final_rename+0x77>
mov    -0x20(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x5f,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11c7 <final_rename+0x87>
jmp    11d8 <final_rename+0x98>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1193 <final_rename+0x53>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1245 <final_rename+0x105>
mov    -0x20(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
je     1245 <final_rename+0x105>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1245 <final_rename+0x105>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xdd6(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <rename@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    124a <final_rename+0x10a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<final_rename>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     11c9 <final_rename+0x89>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1060 <strdup@plt>
mov    %rax,%rbx
xor    %eax,%eax
nopl   (%rax)
cmpb   $0x0,(%rbx,%rax,1)
lea    0x1(%rax),%rax
jne    1160 <final_rename+0x20>
nopw   0x0(%rax,%rax,1)
cmp    $0x1,%rax
je     11c9 <final_rename+0x89>
movzbl -0x2(%rbx,%rax,1),%ecx
add    $0xffffffffffffffff,%rax
cmp    $0x5f,%cl
je     1170 <final_rename+0x30>
cmp    $0x2f,%cl
je     11c9 <final_rename+0x89>
cmpb   $0x0,(%rbx,%rax,1)
je     11c9 <final_rename+0x89>
movb   $0x0,(%rbx,%rax,1)
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
call   1040 <fprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <rename@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"[%s] finished, renaming %s to %s.\0A\00"
define void @final_rename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %64
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
store i8* %12, i8** %6
br label %13
13: ; preds = %17, %9
%14 = load i8*, i8** %6
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %6
br label %13
20: ; preds = %13
br label %21
21: ; preds = %33, %20
%22 = load i8*, i8** %6
%23 = load i8*, i8** %5
%24 = icmp ne i8* %22, %23
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 -1
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 95
br label %31
31: ; preds = %25, %21
%32 = phi i1 [ false, %21 ], [ %30, %25 ]
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = load i8*, i8** %6
%35 = getelementptr inbounds i8, i8* %34, i32 -1
store i8* %35, i8** %6
br label %21
36: ; preds = %31
%37 = load i8*, i8** %6
%38 = load i8*, i8** %5
%39 = icmp ne i8* %37, %38
br i1 %39, label %40, label %63
40: ; preds = %36
%41 = load i8*, i8** %6
%42 = getelementptr inbounds i8, i8* %41, i64 -1
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 47
br i1 %45, label %46, label %63
46: ; preds = %40
%47 = load i8*, i8** %6
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %63
51: ; preds = %46
%52 = load i8*, i8** %6
store i8 0, i8* %52
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %3
%55 = load i8*, i8** %4
%56 = load i8*, i8** %5
%57 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %54, i8* %55, i8* %56)
%58 = load i8*, i8** %4
%59 = load i8*, i8** %5
%60 = call i32 @rename(i8* %58, i8* %59)
%61 = load i8*, i8** %5
%62 = call i32 @free(i8* %61)
br label %63
63: ; preds = %51, %46, %40, %36
br label %64
64: ; preds = %63, %2
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"[%s] finished, renaming %s to %s.\0A\00"
define void @final_rename(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %25, label %4
4: ; preds = %2
%5 = tail call i8* @strdup(i8* %1)
br label %6
6: ; preds = %6, %4
%7 = phi i8* [ %5, %4 ], [ %10, %6 ]
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
%10 = getelementptr inbounds i8, i8* %7, i64 1
br i1 %9, label %11, label %6
11: ; preds = %6, %14
%12 = phi i8* [ %15, %14 ], [ %7, %6 ]
%13 = icmp eq i8* %12, %5
br i1 %13, label %25, label %14
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %12, i64 -1
%16 = load i8, i8* %15
switch i8 %16, label %17 [
i8 95, label %11
i8 47, label %25
]
17: ; preds = %14
%18 = load i8, i8* %12
%19 = icmp eq i8 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %17
store i8 0, i8* %12
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %5)
%23 = tail call i32 @rename(i8* %1, i8* %5)
%24 = tail call i32 @free(i8* %5)
br label %25
25: ; preds = %14, %11, %17, %20, %2
ret void
}