#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 errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int handle_zng(int);
int /*<<< orphan*/ printf(char *, ...);
int rename(char *, char *);
int rename_test(char *old, char *newf) {
  int ret, save_errno;
  int passed;
  printf("rename(): old=%s, newf=%s\n", (((old) == NULL) ? "(null)" : (old)),
         (((newf) == NULL) ? "(null)" : (newf)));
  fflush(NULL);
  passed = handle_zng(ret = rename(old, newf));
  save_errno = errno;
  switch (passed) {
  case -1:
  case 0:
    printf("\t\tret = %d\n", ret);
    printf("\tSucceeded Phase 1\n");
    fflush(NULL);
    break;
  case -2:
    printf("\tFailed Phase 1: returned undefined value! "
           "ret = %d\n",
           ret);
    fflush(NULL);
    break;
  default:
    printf("Internal syscalltester error: passed = %d\n", passed);
    fflush(NULL);
    break;
  }
  errno = save_errno;
  return ret;
}


x86 assembly (clang, -O0):
<rename_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116b <rename_test+0x2b>
lea    0xeb9(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1173 <rename_test+0x33>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1196 <rename_test+0x56>
lea    0xe8e(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    119e <rename_test+0x5e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xe53(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x40(%rbp)
call   1040 <printf@plt>
mov    -0x40(%rbp),%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <rename@plt>
mov    %eax,%edi
mov    %edi,-0x14(%rbp)
call   1030 <handle_zng@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0xfffffffe,%eax
je     123c <rename_test+0xfc>
jmp    11fb <rename_test+0xbb>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
sub    $0x1,%eax
ja     125b <rename_test+0x11b>
jmp    120f <rename_test+0xcf>
mov    -0x14(%rbp),%esi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    1275 <rename_test+0x135>
mov    -0x14(%rbp),%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    1275 <rename_test+0x135>
mov    -0x1c(%rbp),%esi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    -0x18(%rbp),%ecx
mov    0x2d61(%rip),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rename_test>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
test   %rdi,%rdi
lea    0xeba(%rip),%rdx
mov    %rdi,%rax
cmove  %rdx,%rax
mov    %rsi,%rbx
test   %rsi,%rsi
cmovne %rsi,%rdx
lea    0xe87(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <rename@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <handle_zng@plt>
mov    0x2e3b(%rip),%r14
mov    (%r14),%ebp
lea    0x1(%rax),%ecx
cmp    $0x2,%ecx
jae    11ce <rename_test+0x7e>
lea    0xe6b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
jmp    11ee <rename_test+0x9e>
cmp    $0xfffffffe,%eax
jne    11de <rename_test+0x8e>
lea    0xe54(%rip),%rdi
mov    %ebx,%esi
jmp    11e7 <rename_test+0x97>
lea    0xe7e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    %ebp,(%r14)
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"rename(): old=%s, newf=%s\0A\00"
@.str.1 = [7 x i8] c"(null)\00"
@errno = global i32 0
@.str.2 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.3 = [20 x i8] c"\09Succeeded Phase 1\0A\00"
@.str.4 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.5 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
define i32 @rename_test(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
br label %13
11: ; preds = %2
%12 = load i8*, i8** %3
br label %13
13: ; preds = %11, %10
%14 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %10 ], [ %12, %11 ]
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %13
br label %20
18: ; preds = %13
%19 = load i8*, i8** %4
br label %20
20: ; preds = %18, %17
%21 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %17 ], [ %19, %18 ]
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %21)
%23 = call i32 @fflush(i32* null)
%24 = load i8*, i8** %3
%25 = load i8*, i8** %4
%26 = call i32 @rename(i8* %24, i8* %25)
store i32 %26, i32* %5
%27 = call i32 @handle_zng(i32 %26)
store i32 %27, i32* %7
%28 = load i32, i32* @errno
store i32 %28, i32* %6
%29 = load i32, i32* %7
switch i32 %29, label %39 [
i32 -1, label %30
i32 0, label %30
i32 -2, label %35
]
30: ; preds = %20, %20
%31 = load i32, i32* %5
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @fflush(i32* null)
br label %43
35: ; preds = %20
%36 = load i32, i32* %5
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%38 = call i32 @fflush(i32* null)
br label %43
39: ; preds = %20
%40 = load i32, i32* %7
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %40)
%42 = call i32 @fflush(i32* null)
br label %43
43: ; preds = %39, %35, %30
%44 = load i32, i32* %6
store i32 %44, i32* @errno
%45 = load i32, i32* %5
ret i32 %45
}

LLVM IR (-O2):
@.str = [27 x i8] c"rename(): old=%s, newf=%s\0A\00"
@.str.1 = [7 x i8] c"(null)\00"
@errno = global i32 0
@.str.2 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.4 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.5 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
@str = [19 x i8] c"\09Succeeded Phase 1\00"
define i32 @rename_test(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = select i1 %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %0
%5 = icmp eq i8* %1, null
%6 = select i1 %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %6)
%8 = tail call i32 @fflush(i32* null)
%9 = tail call i32 @rename(i8* %0, i8* %1)
%10 = tail call i32 @handle_zng(i32 %9)
%11 = load i32, i32* @errno
switch i32 %10, label %17 [
i32 -1, label %12
i32 0, label %12
i32 -2, label %15
]
12: ; preds = %2, %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %19
15: ; preds = %2
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %9)
br label %19
17: ; preds = %2
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %10)
br label %19
19: ; preds = %17, %15, %12
%20 = tail call i32 @fflush(i32* null)
store i32 %11, i32* @errno
ret i32 %9
}