#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*/ __hosted_from_gdb_errno(int);
int do_syscall(int, unsigned int, int, unsigned int, int, int *);
int /*<<< orphan*/ errno;
int strlen(char const *);
int rename(const char *old, const char *new) {
  int status;
  int error;
  int oldlen = strlen(old) + 1;
  int newlen = strlen(new) + 1;
  status = do_syscall(8, (unsigned)old, oldlen, (unsigned)new, newlen, &error);
  if (status < 0)
    errno = __hosted_from_gdb_errno(error);
  return status;
}


x86 assembly (clang, -O0):
<rename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%esi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%r8d
mov    $0x8,%edi
lea    -0x18(%rbp),%r9
call   1040 <do_syscall@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    119f <rename+0x6f>
mov    -0x18(%rbp),%edi
call   1050 <__hosted_from_gdb_errno@plt>
mov    %eax,%ecx
mov    0x2e43(%rip),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rename>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%r8d
lea    0xc(%rsp),%r9
mov    $0x8,%edi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1040 <do_syscall@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1180 <rename+0x50>
mov    0xc(%rsp),%edi
call   1050 <__hosted_from_gdb_errno@plt>
mov    0x2e62(%rip),%rcx
mov    %eax,(%rcx)
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define i32 @rename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 1
store i32 %11, i32* %7
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %13, 1
store i32 %14, i32* %8
%15 = load i8*, i8** %3
%16 = ptrtoint i8* %15 to i32
%17 = load i32, i32* %7
%18 = load i8*, i8** %4
%19 = ptrtoint i8* %18 to i32
%20 = load i32, i32* %8
%21 = call i32 @do_syscall(i32 8, i32 %16, i32 %17, i32 %19, i32 %20, i32* %6)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %2
%25 = load i32, i32* %6
%26 = call i32 @__hosted_from_gdb_errno(i32 %25)
store i32 %26, i32* @errno
br label %27
27: ; preds = %24, %2
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @rename(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, 1
%7 = tail call i32 @strlen(i8* %1)
%8 = add nsw i32 %7, 1
%9 = ptrtoint i8* %0 to i64
%10 = trunc i64 %9 to i32
%11 = ptrtoint i8* %1 to i64
%12 = trunc i64 %11 to i32
%13 = call i32 @do_syscall(i32 8, i32 %10, i32 %6, i32 %12, i32 %8, i32* %3)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* %3
%17 = call i32 @__hosted_from_gdb_errno(i32 %16)
store i32 %17, i32* @errno
br label %18
18: ; preds = %15, %2
ret i32 %13
}