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

/* Variables and functions */
scalar_t__ check_command(struct nli *);
char *create_response_buf(char *);
struct nli *deserialize(char *);
int /*<<< orphan*/ destroy_nodelist(struct nli *);
int /*<<< orphan*/ join_incoming(struct nli *);
int /*<<< orphan*/ print_declined_incoming();
char *server_dispatch(struct nli *);
char *strdup(char *);
char *incoming_callback(char *buf) {
  char *r = NULL;
  if (buf) {
    struct nli *nli;
    nli = deserialize(buf);
    if (!nli)
      return NULL;
    join_incoming(nli);
    if (check_command(nli)) {
      r = server_dispatch(nli);
    } else {
      print_declined_incoming();
    }
    destroy_nodelist(nli);
    if (!r) {
      r = strdup(
          "failed to forward command, possibly no other nodes available\n");
    }
    r = create_response_buf(r);
  }
  return r;
}


x86 assembly (clang, -O0):
<incoming_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     122a <incoming_callback+0xaa>
mov    -0x10(%rbp),%rdi
call   1060 <deserialize@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c4 <incoming_callback+0x44>
movq   $0x0,-0x8(%rbp)
jmp    1232 <incoming_callback+0xb2>
mov    -0x20(%rbp),%rdi
call   1050 <join_incoming@plt>
mov    -0x20(%rbp),%rdi
call   1090 <check_command@plt>
cmp    $0x0,%rax
je     11f2 <incoming_callback+0x72>
mov    -0x20(%rbp),%rdi
call   1040 <server_dispatch@plt>
mov    %rax,-0x18(%rbp)
jmp    11f9 <incoming_callback+0x79>
mov    $0x0,%al
call   1070 <print_declined_incoming@plt>
mov    -0x20(%rbp),%rdi
call   1030 <destroy_nodelist@plt>
cmpq   $0x0,-0x18(%rbp)
jne    121d <incoming_callback+0x9d>
lea    0xdec(%rip),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <create_response_buf@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<incoming_callback>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11c5 <incoming_callback+0x45>
call   1060 <deserialize@plt>
test   %rax,%rax
je     11c5 <incoming_callback+0x45>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <join_incoming@plt>
mov    %rbx,%rdi
call   1090 <check_command@plt>
test   %rax,%rax
je     11cf <incoming_callback+0x4f>
mov    %rbx,%rdi
call   1040 <server_dispatch@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <destroy_nodelist@plt>
test   %r14,%r14
jne    11ed <incoming_callback+0x6d>
jmp    11de <incoming_callback+0x5e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1070 <print_declined_incoming@plt>
mov    %rbx,%rdi
call   1030 <destroy_nodelist@plt>
lea    0xe1b(%rip),%rdi
call   10a0 <strdup@plt>
mov    %rax,%r14
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <create_response_buf@plt>

LLVM IR (-O0):
%struct.nli = type { i32 }
@.str = [62 x i8] c"failed to forward command, possibly no other nodes available\0A\00"
define i8* @incoming_callback(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.nli*
store i8* %0, i8** %3
store i8* null, i8** %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %35
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call %struct.nli* @deserialize(i8* %9)
store %struct.nli* %10, %struct.nli** %5
%11 = load %struct.nli*, %struct.nli** %5
%12 = icmp ne %struct.nli* %11, null
br i1 %12, label %14, label %13
13: ; preds = %8
store i8* null, i8** %2
br label %37
14: ; preds = %8
%15 = load %struct.nli*, %struct.nli** %5
%16 = call i32 @join_incoming(%struct.nli* %15)
%17 = load %struct.nli*, %struct.nli** %5
%18 = call i64 @check_command(%struct.nli* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load %struct.nli*, %struct.nli** %5
%22 = call i8* @server_dispatch(%struct.nli* %21)
store i8* %22, i8** %4
br label %25
23: ; preds = %14
%24 = call i32 (...) @print_declined_incoming()
br label %25
25: ; preds = %23, %20
%26 = load %struct.nli*, %struct.nli** %5
%27 = call i32 @destroy_nodelist(%struct.nli* %26)
%28 = load i8*, i8** %4
%29 = icmp ne i8* %28, null
br i1 %29, label %32, label %30
30: ; preds = %25
%31 = call i8* @strdup(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
store i8* %31, i8** %4
br label %32
32: ; preds = %30, %25
%33 = load i8*, i8** %4
%34 = call i8* @create_response_buf(i8* %33)
store i8* %34, i8** %4
br label %35
35: ; preds = %32, %1
%36 = load i8*, i8** %4
store i8* %36, i8** %2
br label %37
37: ; preds = %35, %13
%38 = load i8*, i8** %2
ret i8* %38
}

LLVM IR (-O2):
%struct.nli = type { i32 }
@.str = [62 x i8] c"failed to forward command, possibly no other nodes available\0A\00"
define i8* @incoming_callback(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %22, label %3
3: ; preds = %1
%4 = tail call %struct.nli* @deserialize(i8* %0)
%5 = icmp eq %struct.nli* %4, null
br i1 %5, label %22, label %6
6: ; preds = %3
%7 = tail call i32 @join_incoming(%struct.nli* %4)
%8 = tail call i64 @check_command(%struct.nli* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = tail call i32 (...) @print_declined_incoming()
%12 = tail call i32 @destroy_nodelist(%struct.nli* %4)
br label %17
13: ; preds = %6
%14 = tail call i8* @server_dispatch(%struct.nli* %4)
%15 = tail call i32 @destroy_nodelist(%struct.nli* %4)
%16 = icmp eq i8* %14, null
br i1 %16, label %17, label %19
17: ; preds = %10, %13
%18 = tail call dereferenceable_or_null(62) i8* @strdup(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %13, %17
%20 = phi i8* [ %14, %13 ], [ %18, %17 ]
%21 = tail call i8* @create_response_buf(i8* %20)
br label %22
22: ; preds = %3, %1, %19
%23 = phi i8* [ %21, %19 ], [ null, %1 ], [ null, %3 ]
ret i8* %23
}