#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;
};
struct katcl_parse {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ append_string_katcp(struct katcp_dispatch *, int, char *);
struct katcl_parse *get_parse_notice_katcp(struct katcp_dispatch *,
                                           struct katcp_notice *);
char *get_string_parse_katcl(struct katcl_parse *, int);
int /*<<< orphan*/ log_message_katcp(struct katcp_dispatch *, int,
                                     int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ prepend_reply_katcp(struct katcp_dispatch *);
char *query_mode_name_katcp(struct katcp_dispatch *);
int /*<<< orphan*/ resume_katcp(struct katcp_dispatch *);
int mode_resume_katcp(struct katcp_dispatch *d, struct katcp_notice *n,
                      void *data) {
  struct katcl_parse *p;
  char *actual, *code;
  log_message_katcp(d, 1, NULL, "resuming after mode change");
  p = get_parse_notice_katcp(d, n);
  if (p) {
    code = get_string_parse_katcl(p, 1);
  } else {
    code = NULL;
  }
  actual = query_mode_name_katcp(d);
  if (actual == NULL) {
    return (-1);
  }
  prepend_reply_katcp(d);
  append_string_katcp(d, 0x10, code ? code : 0);
  append_string_katcp(d, 0x10 | 0x02, actual);
  resume_katcp(d);
  return 0;
}


x86 assembly (clang, -O0):
<mode_resume_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    0xe68(%rip),%rcx
call   1080 <log_message_katcp@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <get_parse_notice_katcp@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11d0 <mode_resume_katcp+0x60>
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   1050 <get_string_parse_katcl@plt>
mov    %rax,-0x38(%rbp)
jmp    11d8 <mode_resume_katcp+0x68>
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <query_mode_name_katcp@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11fc <mode_resume_katcp+0x8c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1264 <mode_resume_katcp+0xf4>
mov    -0x10(%rbp),%rdi
call   1060 <prepend_reply_katcp@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1225 <mode_resume_katcp+0xb5>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1230 <mode_resume_katcp+0xc0>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    1230 <mode_resume_katcp+0xc0>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    $0x10,%esi
call   1040 <append_string_katcp@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x12,%esi
call   1040 <append_string_katcp@plt>
mov    -0x10(%rbp),%rdi
call   1090 <resume_katcp@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mode_resume_katcp>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe7e(%rip),%rcx
xor    %r14d,%r14d
mov    $0x1,%esi
xor    %edx,%edx
call   1080 <log_message_katcp@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <get_parse_notice_katcp@plt>
test   %rax,%rax
je     11b1 <mode_resume_katcp+0x41>
mov    %rax,%rdi
mov    $0x1,%esi
call   1050 <get_string_parse_katcl@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <query_mode_name_katcp@plt>
test   %rax,%rax
je     11f5 <mode_resume_katcp+0x85>
mov    %rax,%r15
mov    %rbx,%rdi
call   1060 <prepend_reply_katcp@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
mov    %r14,%rdx
call   1040 <append_string_katcp@plt>
mov    %rbx,%rdi
mov    $0x12,%esi
mov    %r15,%rdx
call   1040 <append_string_katcp@plt>
mov    %rbx,%rdi
call   1090 <resume_katcp@plt>
xor    %eax,%eax
jmp    11fa <mode_resume_katcp+0x8a>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.katcp_dispatch = type { i32 }
%struct.katcp_notice = type { i32 }
%struct.katcl_parse = type { i32 }
@.str = [27 x i8] c"resuming after mode change\00"
define i32 @mode_resume_katcp(%struct.katcp_dispatch* %0, %struct.katcp_notice* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.katcp_dispatch*
%6 = alloca %struct.katcp_notice*
%7 = alloca i8*
%8 = alloca %struct.katcl_parse*
%9 = alloca i8*
%10 = alloca i8*
store %struct.katcp_dispatch* %0, %struct.katcp_dispatch** %5
store %struct.katcp_notice* %1, %struct.katcp_notice** %6
store i8* %2, i8** %7
%11 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%12 = call i32 @log_message_katcp(%struct.katcp_dispatch* %11, i32 1, i32* null, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%13 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%14 = load %struct.katcp_notice*, %struct.katcp_notice** %6
%15 = call %struct.katcl_parse* @get_parse_notice_katcp(%struct.katcp_dispatch* %13, %struct.katcp_notice* %14)
store %struct.katcl_parse* %15, %struct.katcl_parse** %8
%16 = load %struct.katcl_parse*, %struct.katcl_parse** %8
%17 = icmp ne %struct.katcl_parse* %16, null
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load %struct.katcl_parse*, %struct.katcl_parse** %8
%20 = call i8* @get_string_parse_katcl(%struct.katcl_parse* %19, i32 1)
store i8* %20, i8** %10
br label %22
21: ; preds = %3
store i8* null, i8** %10
br label %22
22: ; preds = %21, %18
%23 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%24 = call i8* @query_mode_name_katcp(%struct.katcp_dispatch* %23)
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 -1, i32* %4
br label %45
28: ; preds = %22
%29 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%30 = call i32 @prepend_reply_katcp(%struct.katcp_dispatch* %29)
%31 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%32 = load i8*, i8** %10
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = load i8*, i8** %10
br label %37
36: ; preds = %28
br label %37
37: ; preds = %36, %34
%38 = phi i8* [ %35, %34 ], [ null, %36 ]
%39 = call i32 @append_string_katcp(%struct.katcp_dispatch* %31, i32 16, i8* %38)
%40 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%41 = load i8*, i8** %9
%42 = call i32 @append_string_katcp(%struct.katcp_dispatch* %40, i32 18, i8* %41)
%43 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%44 = call i32 @resume_katcp(%struct.katcp_dispatch* %43)
store i32 0, i32* %4
br label %45
45: ; preds = %37, %27
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
%struct.katcp_dispatch = type { i32 }
%struct.katcp_notice = type { i32 }
%struct.katcl_parse = type { i32 }
@.str = [27 x i8] c"resuming after mode change\00"
define i32 @mode_resume_katcp(%struct.katcp_dispatch* %0, %struct.katcp_notice* %1, i8* nocapture readnone %2) {
%4 = tail call i32 @log_message_katcp(%struct.katcp_dispatch* %0, i32 1, i32* null, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%5 = tail call %struct.katcl_parse* @get_parse_notice_katcp(%struct.katcp_dispatch* %0, %struct.katcp_notice* %1)
%6 = icmp eq %struct.katcl_parse* %5, null
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i8* @get_string_parse_katcl(%struct.katcl_parse* %5, i32 1)
br label %9
9: ; preds = %3, %7
%10 = phi i8* [ %8, %7 ], [ null, %3 ]
%11 = tail call i8* @query_mode_name_katcp(%struct.katcp_dispatch* %0)
%12 = icmp eq i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = tail call i32 @prepend_reply_katcp(%struct.katcp_dispatch* %0)
%15 = tail call i32 @append_string_katcp(%struct.katcp_dispatch* %0, i32 16, i8* %10)
%16 = tail call i32 @append_string_katcp(%struct.katcp_dispatch* %0, i32 18, i8* %11)
%17 = tail call i32 @resume_katcp(%struct.katcp_dispatch* %0)
br label %18
18: ; preds = %9, %13
%19 = phi i32 [ 0, %13 ], [ -1, %9 ]
ret i32 %19
}