#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
struct evbuffer {
  int dummy;
};
struct conn {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ evbuffer_drain(struct evbuffer *, int /*<<< orphan*/);
scalar_t__ get_distribution_list(int /*<<< orphan*/ const **, size_t *);
int /*<<< orphan*/ send_data(struct conn *, int /*<<< orphan*/ const *, int,
                             size_t, int /*<<< orphan*/ const *);
int /*<<< orphan*/ send_err(struct conn *, int, int /*<<< orphan*/ const *,
                            char *, int /*<<< orphan*/);
int handle_list_dists_command(struct conn *conn, const uint8_t *req_id,
                              uint32_t flags, struct evbuffer *input,
                              uint32_t cmd_len) {
  evbuffer_drain(input, cmd_len);
  const uint8_t *dl;
  size_t sz;
  if (get_distribution_list(&dl, &sz) < 0) {
    send_err(conn, 10, req_id, "No distribution list present", 0);
    return 0;
  }
  send_data(conn, req_id, 0x2004, sz, dl);
  return 0;
}


x86 assembly (clang, -O0):
<handle_list_dists_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1060 <evbuffer_drain@plt>
lea    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <get_distribution_list@plt>
cmp    $0x0,%rax
jge    11a6 <handle_list_dists_command+0x66>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xa,%esi
lea    0xe6e(%rip),%rcx
xor    %r8d,%r8d
call   1030 <send_err@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c7 <handle_list_dists_command+0x87>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    $0x2004,%edx
call   1040 <send_data@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_list_dists_command>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rcx,%rdi
mov    %r8d,%esi
call   1060 <evbuffer_drain@plt>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1050 <get_distribution_list@plt>
test   %rax,%rax
js     1188 <handle_list_dists_command+0x48>
mov    0x8(%rsp),%rcx
mov    0x10(%rsp),%r8
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2004,%edx
call   1040 <send_data@plt>
jmp    11a2 <handle_list_dists_command+0x62>
lea    0xe71(%rip),%rcx
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %r14,%rdx
xor    %r8d,%r8d
call   1030 <send_err@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.conn = type { i32 }
%struct.evbuffer = type { i32 }
@.str = [29 x i8] c"No distribution list present\00"
define i32 @handle_list_dists_command(%struct.conn* %0, i32* %1, i32 %2, %struct.evbuffer* %3, i32 %4) {
%6 = alloca i32
%7 = alloca %struct.conn*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca %struct.evbuffer*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i64
store %struct.conn* %0, %struct.conn** %7
store i32* %1, i32** %8
store i32 %2, i32* %9
store %struct.evbuffer* %3, %struct.evbuffer** %10
store i32 %4, i32* %11
%14 = load %struct.evbuffer*, %struct.evbuffer** %10
%15 = load i32, i32* %11
%16 = call i32 @evbuffer_drain(%struct.evbuffer* %14, i32 %15)
%17 = call i64 @get_distribution_list(i32** %12, i64* %13)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %5
%20 = load %struct.conn*, %struct.conn** %7
%21 = load i32*, i32** %8
%22 = call i32 @send_err(%struct.conn* %20, i32 10, i32* %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 0, i32* %6
br label %29
23: ; preds = %5
%24 = load %struct.conn*, %struct.conn** %7
%25 = load i32*, i32** %8
%26 = load i64, i64* %13
%27 = load i32*, i32** %12
%28 = call i32 @send_data(%struct.conn* %24, i32* %25, i32 8196, i64 %26, i32* %27)
store i32 0, i32* %6
br label %29
29: ; preds = %23, %19
%30 = load i32, i32* %6
ret i32 %30
}

LLVM IR (-O2):
%struct.conn = type { i32 }
%struct.evbuffer = type { i32 }
@.str = [29 x i8] c"No distribution list present\00"
define i32 @handle_list_dists_command(%struct.conn* %0, i32* %1, i32 %2, %struct.evbuffer* %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i64
%8 = tail call i32 @evbuffer_drain(%struct.evbuffer* %3, i32 %4)
%9 = bitcast i32** %6 to i8*
%10 = bitcast i64* %7 to i8*
%11 = call i64 @get_distribution_list(i32** %6, i64* %7)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = call i32 @send_err(%struct.conn* %0, i32 10, i32* %1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 0)
br label %19
15: ; preds = %5
%16 = load i64, i64* %7
%17 = load i32*, i32** %6
%18 = call i32 @send_data(%struct.conn* %0, i32* %1, i32 8196, i64 %16, i32* %17)
br label %19
19: ; preds = %15, %13
ret i32 0
}