#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 */
#define EINVAL 130
#define ENOENT 129
#define ENOTEMPTY 128
int errno;
int /*<<< orphan*/ getpid();
scalar_t__ rename(char const *, char const *);
int /*<<< orphan*/ say(char *, int /*<<< orphan*/, char const *, char const *,
                       int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int);
void dorename(const char *name1, const char *name2) {
  if (rename(name1, name2) < 0) {
    switch (errno) {
    case ENOENT:
    case ENOTEMPTY:
    case EINVAL:
      break;
    default:
      say("pid %d: rename %s -> %s: %s\n", getpid(), name1, name2,
          strerror(errno));
      break;
    }
  }
}


x86 assembly (clang, -O0):
<dorename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <rename@plt>
cmp    $0x0,%rax
jge    11cd <dorename+0x8d>
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
sub    $0x2,%eax
ja     1186 <dorename+0x46>
jmp    1181 <dorename+0x41>
jmp    11c8 <dorename+0x88>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    %eax,%r8d
lea    0xe3d(%rip),%rdi
call   1060 <say@plt>
jmp    11cd <dorename+0x8d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dorename>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <rename@plt>
test   %rax,%rax
jns    1169 <dorename+0x29>
mov    0x2e82(%rip),%rbp
mov    0x0(%rbp),%eax
add    $0xffffff80,%eax
cmp    $0x3,%eax
jae    1174 <dorename+0x34>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r15d
mov    0x0(%rbp),%edi
call   1050 <strerror@plt>
lea    0xe73(%rip),%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %eax,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <say@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [29 x i8] c"pid %d: rename %s -> %s: %s\0A\00"
define void @dorename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %3
%6 = load i8*, i8** %4
%7 = call i64 @rename(i8* %5, i8* %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %2
%10 = load i32, i32* @errno
switch i32 %10, label %12 [
i32 129, label %11
i32 128, label %11
i32 130, label %11
]
11: ; preds = %9, %9, %9
br label %19
12: ; preds = %9
%13 = call i32 (...) @getpid()
%14 = load i8*, i8** %3
%15 = load i8*, i8** %4
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = call i32 @say(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %13, i8* %14, i8* %15, i32 %17)
br label %19
19: ; preds = %12, %11
br label %20
20: ; preds = %19, %2
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [29 x i8] c"pid %d: rename %s -> %s: %s\0A\00"
define void @dorename(i8* %0, i8* %1) {
%3 = tail call i64 @rename(i8* %0, i8* %1)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = load i32, i32* @errno
%7 = add i32 %6, -128
%8 = icmp ult i32 %7, 3
br i1 %8, label %14, label %9
9: ; preds = %5
%10 = tail call i32 (...) @getpid()
%11 = load i32, i32* @errno
%12 = tail call i32 @strerror(i32 %11)
%13 = tail call i32 @say(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %0, i8* %1, i32 %12)
br label %14
14: ; preds = %5, %9, %2
ret void
}