#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 */
struct katcp_notice {
  int dummy;
};
struct katcp_dispatch {
  int dummy;
};

/* Variables and functions */
struct katcp_notice *find_notice_katcp(struct katcp_dispatch *, char *);
int /*<<< orphan*/ log_message_katcp(struct katcp_dispatch *, int,
                                     int /*<<< orphan*/ *, char *,
                                     struct katcp_notice *);
scalar_t__ rename_notice_katcp(struct katcp_dispatch *, struct katcp_notice *,
                               char *);
int change_name_notice_katcp(struct katcp_dispatch *d, char *name,
                             char *newname) {
  struct katcp_notice *n;
  n = find_notice_katcp(d, name);
  if (n == NULL) {
    return -1;
  }
  if (rename_notice_katcp(d, n, newname) < 0) {
    log_message_katcp(d, 4, NULL, "could not rename notice %p", n);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<change_name_notice_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <find_notice_katcp@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116c <change_name_notice_katcp+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <change_name_notice_katcp+0x87>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <rename_notice_katcp@plt>
cmp    $0x0,%rax
jge    11b0 <change_name_notice_katcp+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%r8
mov    $0x4,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    0xe61(%rip),%rcx
call   1050 <log_message_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <change_name_notice_katcp+0x87>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_name_notice_katcp>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rdi,%r14
call   1040 <find_notice_katcp@plt>
mov    %rax,%rbx
mov    $0xffffffff,%eax
test   %rbx,%rbx
je     1183 <change_name_notice_katcp+0x53>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <rename_notice_katcp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    1183 <change_name_notice_katcp+0x53>
lea    0xe94(%rip),%rcx
mov    %r14,%rdi
mov    $0x4,%esi
xor    %edx,%edx
mov    %rbx,%r8
call   1050 <log_message_katcp@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.katcp_dispatch = type { i32 }
%struct.katcp_notice = type { i32 }
@.str = [27 x i8] c"could not rename notice %p\00"
define i32 @change_name_notice_katcp(%struct.katcp_dispatch* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.katcp_dispatch*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.katcp_notice*
store %struct.katcp_dispatch* %0, %struct.katcp_dispatch** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%10 = load i8*, i8** %6
%11 = call %struct.katcp_notice* @find_notice_katcp(%struct.katcp_dispatch* %9, i8* %10)
store %struct.katcp_notice* %11, %struct.katcp_notice** %8
%12 = load %struct.katcp_notice*, %struct.katcp_notice** %8
%13 = icmp eq %struct.katcp_notice* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %26
15: ; preds = %3
%16 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%17 = load %struct.katcp_notice*, %struct.katcp_notice** %8
%18 = load i8*, i8** %7
%19 = call i64 @rename_notice_katcp(%struct.katcp_dispatch* %16, %struct.katcp_notice* %17, i8* %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%23 = load %struct.katcp_notice*, %struct.katcp_notice** %8
%24 = call i32 @log_message_katcp(%struct.katcp_dispatch* %22, i32 4, i32* null, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %struct.katcp_notice* %23)
store i32 -1, i32* %4
br label %26
25: ; preds = %15
store i32 0, i32* %4
br label %26
26: ; preds = %25, %21, %14
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
%struct.katcp_dispatch = type { i32 }
%struct.katcp_notice = type { i32 }
@.str = [27 x i8] c"could not rename notice %p\00"
define i32 @change_name_notice_katcp(%struct.katcp_dispatch* %0, i8* %1, i8* %2) {
%4 = tail call %struct.katcp_notice* @find_notice_katcp(%struct.katcp_dispatch* %0, i8* %1)
%5 = icmp eq %struct.katcp_notice* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = tail call i64 @rename_notice_katcp(%struct.katcp_dispatch* %0, %struct.katcp_notice* %4, i8* %2)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @log_message_katcp(%struct.katcp_dispatch* %0, i32 4, i32* null, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %struct.katcp_notice* %4)
br label %11
11: ; preds = %6, %3, %9
%12 = phi i32 [ -1, %9 ], [ -1, %3 ], [ 0, %6 ]
ret i32 %12
}