#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*/ debug_printf(char *, ...);
int real_rename(char const *, char const *);
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ system(char *);
int rename(const char *old, const char *new) {
  debug_printf("ctlmgr: rename() %s --> %s ", old, new);
  if (strcmp(old, "/var/tmp/passwd.tmp") != 0) {
    debug_printf(" (allowed)\n");
    return real_rename(old, new);
  } else {
    debug_printf(" (rejected)\n");
    system("/usr/bin/modusers update");
    return 0;
  }
}


x86 assembly (clang, -O0):
<rename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <debug_printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xeab(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11a3 <rename+0x63>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <debug_printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <real_rename@plt>
mov    %eax,-0x4(%rbp)
jmp    11c4 <rename+0x84>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <debug_printf@plt>
lea    0xe91(%rip),%rdi
call   1040 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rename>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeaf(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <debug_printf@plt>
lea    0xeb7(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1192 <rename+0x52>
lea    0xeb7(%rip),%rdi
xor    %eax,%eax
call   1030 <debug_printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <real_rename@plt>
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   1030 <debug_printf@plt>
lea    0xea2(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [28 x i8] c"ctlmgr: rename() %s --> %s \00"
@.str.1 = [20 x i8] c"/var/tmp/passwd.tmp\00"
@.str.2 = [12 x i8] c" (allowed)\0A\00"
@.str.3 = [13 x i8] c" (rejected)\0A\00"
@.str.4 = [25 x i8] c"/usr/bin/modusers update\00"
define i32 @rename(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = load i8*, i8** %5
%8 = call i32 (i8*, ...) @debug_printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %7)
%9 = load i8*, i8** %4
%10 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = call i32 (i8*, ...) @debug_printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = call i32 @real_rename(i8* %14, i8* %15)
store i32 %16, i32* %3
br label %20
17: ; preds = %2
%18 = call i32 (i8*, ...) @debug_printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @system(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %20
20: ; preds = %17, %12
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [28 x i8] c"ctlmgr: rename() %s --> %s \00"
@.str.1 = [20 x i8] c"/var/tmp/passwd.tmp\00"
@.str.2 = [12 x i8] c" (allowed)\0A\00"
@.str.3 = [13 x i8] c" (rejected)\0A\00"
@.str.4 = [25 x i8] c"/usr/bin/modusers update\00"
define i32 @rename(i8* %0, i8* %1) {
%3 = tail call i32 (i8*, ...) @debug_printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%4 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @debug_printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @real_rename(i8* %0, i8* %1)
br label %12
9: ; preds = %2
%10 = tail call i32 (i8*, ...) @debug_printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @system(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %12
12: ; preds = %9, %6
%13 = phi i32 [ %8, %6 ], [ 0, %9 ]
ret i32 %13
}